/
dial.go
58 lines (49 loc) · 1.31 KB
/
dial.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"flag"
"fmt"
"strings"
)
// DialCommand represents a collection of dial-related subcommands.
type DialCommand struct{}
// Run executes the command which delegates to other subcommands.
func (c *DialCommand) Run(ctx context.Context, args []string) error {
// Shift off the subcommand name, if available.
var cmd string
if len(args) > 0 && !strings.HasPrefix(args[0], "-") {
cmd, args = args[0], args[1:]
}
// Delegete to the appropriate subcommand.
switch cmd {
case "", "list":
return (&DialListCommand{}).Run(ctx, args)
case "create":
return (&DialCreateCommand{}).Run(ctx, args)
case "delete":
return (&DialDeleteCommand{}).Run(ctx, args)
case "members":
return (&DialMembersCommand{}).Run(ctx, args)
case "set":
return (&DialSetCommand{}).Run(ctx, args)
case "help":
c.usage()
return flag.ErrHelp
default:
return fmt.Errorf("wtf dial %s: unknown command", cmd)
}
}
// usage prints the subcommand usage to STDOUT.
func (c *DialCommand) usage() {
fmt.Println(`
Manage WTF dials you own or are a member of.
Usage:
wtf dial <command> [arguments]
The commands are:
list list all available dials
create create a new dial
delete remove an existing dial
members view list of members of a dial
set set your WTF level for a dial
`[1:])
}