-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.go
More file actions
50 lines (46 loc) · 1.1 KB
/
help.go
File metadata and controls
50 lines (46 loc) · 1.1 KB
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
package cli_utils
import "fmt"
var HelpCommand = Command{
Name: "help",
Description: "Helps you with a command",
Run: RunHelp,
Args: []Arg{
{
Name: "command",
Description: "Command to get help for",
Required: false,
Default: nil,
},
},
}
func RunHelp(args RuntimeArgs, c *CLI) error {
if args["command"] != nil {
command := args["command"].(string)
for _, c := range c.Commands {
if c.Name == command {
fmt.Printf("Help for command %s:\n", command)
fmt.Printf("Description: %s\n", c.Description)
if c.Args != nil {
fmt.Println("Arguments:")
for _, a := range c.Args {
fmt.Printf(" %s - %s\n", a.Name, a.Description)
}
}
return nil
}
}
return fmt.Errorf("Command %s not found", command)
}
fmt.Printf("Supported commands for %s are:\n", c.Name)
for _, c := range c.Commands {
fmt.Printf("%s - %s\n", c.Name, c.Description)
if c.Args != nil {
fmt.Println(" Arguments:")
for _, a := range c.Args {
fmt.Printf(" %s - %s\n", a.Name, a.Description)
}
}
fmt.Println("------------------")
}
return nil
}