forked from FactomProject/walletapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.go
64 lines (58 loc) · 1.46 KB
/
help.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
59
60
61
62
63
64
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"strings"
)
type Help struct {
ICommand
}
func (h Help) Execute(state IState, args []string) error {
if len(args) == 1 || len(args) > 2 {
fmt.Println(h.ShortHelp())
return nil
}
if strings.ToLower(args[1]) == "all" {
keys := make([]string, 0, len(state.GetCommands()))
for key, _ := range state.GetCommands() {
keys = append(keys, key)
}
for i := 0; i < len(keys)-1; i++ {
for j := 0; j < len(keys)-1-i; j++ {
if keys[j] > keys[j+1] {
t := keys[j]
keys[j] = keys[j+1]
keys[j+1] = t
}
}
}
for _, key := range keys {
fmt.Println(state.GetCommands()[key].LongHelp())
}
}
c := state.GetCommands()[strings.ToLower(args[1])]
if c != nil {
fmt.Println(c.LongHelp())
} else {
if strings.ToLower(args[1]) != "all" {
return fmt.Errorf("Unknown Command")
}
}
return nil
}
func (Help) Name() string {
return "Help"
}
func (Help) ShortHelp() string {
return "Help <all|cmd> -- Help all prints help on all commands.\n" +
" Help <cmd> prints the detailed help on the given command."
}
func (Help) LongHelp() string {
return `
Help <all|cmd> Help facility for the Factom Wallet App. Returns
help on all commands, or on individual specified
commands.
`
}