MCPcopy
hub / github.com/benbjohnson/wtf / Run

Method Run

cmd/wtf/dial_create.go:18–49  ·  view source on GitHub ↗

Run executes the command.

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

16
17// Run executes the command.
18func (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.
52func (c *DialCreateCommand) usage() {

Callers

nothing calls this directly

Calls 6

CreateDialMethod · 0.95
NewContextWithUserFunction · 0.92
NewDialServiceFunction · 0.92
NewClientFunction · 0.92
attachConfigFlagsFunction · 0.85
ReadConfigFileFunction · 0.70

Tested by

no test coverage detected