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

Method Run

cmd/wtf/dial_members.go:19–64  ·  view source on GitHub ↗

Run executes the command.

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

17
18// Run executes the command.
19func (c *DialMembersCommand) Run(ctx context.Context, args []string) error {
20 // Create a flag set to read the config path & read the dial ID.
21 fs := flag.NewFlagSet("wtf-dial-members", flag.ContinueOnError)
22 attachConfigFlags(fs, &c.ConfigPath)
23 if err := fs.Parse(args); err != nil {
24 return err
25 } else if fs.NArg() == 0 {
26 return fmt.Errorf("Dial ID required.")
27 } else if fs.NArg() > 1 {
28 return fmt.Errorf("Only one dial ID allowed.")
29 }
30
31 // Parse dial ID from first arg.
32 id, err := strconv.Atoi(fs.Arg(0))
33 if err != nil {
34 return fmt.Errorf("Invalid dial ID.")
35 }
36
37 // Load configuration file.
38 config, err := ReadConfigFile(c.ConfigPath)
39 if err != nil {
40 return err
41 }
42
43 // Authenticate user with API key.
44 ctx = wtf.NewContextWithUser(ctx, &wtf.User{APIKey: config.APIKey})
45
46 // Instantiate HTTP user service and fetch dial.
47 // Members are automatically attached to the dial.
48 dialService := http.NewDialService(http.NewClient(config.URL))
49 dial, err := dialService.FindDialByID(ctx, id)
50 if err != nil {
51 return err
52 }
53
54 // Iterate over membrships and print the name & value.
55 for _, membership := range dial.Memberships {
56 fmt.Printf(
57 "%s\t%d\n",
58 membership.User.Name,
59 membership.Value,
60 )
61 }
62
63 return nil
64}
65
66// usage prints command usage information to STDOUT.
67func (c *DialMembersCommand) usage() {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected