Run executes the command.
(ctx context.Context, args []string)
| 16 | |
| 17 | // Run executes the command. |
| 18 | func (c *DialCreateCommand) Run(ctx context.Context, args []string) error { |
| 19 | // Create a flag set with parameters for the dial fields. |
| 20 | fs := flag.NewFlagSet("wtf-dial-create", flag.ContinueOnError) |
| 21 | name := fs.String("name", "", "dial name") |
| 22 | attachConfigFlags(fs, &c.ConfigPath) |
| 23 | if err := fs.Parse(args); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | // Load the configuration. |
| 28 | config, err := ReadConfigFile(c.ConfigPath) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | // Authenticate the user with the API key from the config. |
| 34 | ctx = wtf.NewContextWithUser(ctx, &wtf.User{APIKey: config.APIKey}) |
| 35 | |
| 36 | // Build dial from arguments and issue creation request over HTTP. |
| 37 | dial := &wtf.Dial{Name: *name} |
| 38 | svc := http.NewDialService(http.NewClient(config.URL)) |
| 39 | if err := svc.CreateDial(ctx, dial); err != nil { |
| 40 | return err |
| 41 | } |
| 42 | |
| 43 | // Notify user of their new dial. |
| 44 | fmt.Printf("Your %q dial has been created!\n\n", dial.Name) |
| 45 | fmt.Printf("Please share this URL to invite others to contribute:\n\n") |
| 46 | fmt.Printf("%s\n\n", config.URL+"/invite/"+dial.InviteCode) |
| 47 | |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | // usage print usage information for the command to STDOUT. |
| 52 | func (c *DialCreateCommand) usage() { |
nothing calls this directly
no test coverage detected