-
Notifications
You must be signed in to change notification settings - Fork 51
/
help.go
103 lines (93 loc) · 2.43 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package command
import (
"context"
"github.com/spolu/warp"
"github.com/spolu/warp/client"
"github.com/spolu/warp/lib/out"
)
const (
// CmdNmHelp is the command name.
CmdNmHelp cli.CmdName = "help"
)
func init() {
cli.Registrar[CmdNmHelp] = NewHelp
}
// Help a user
type Help struct {
Command cli.Command
}
// NewHelp constructs and initializes the command.
func NewHelp() cli.Command {
return &Help{}
}
// Name returns the command name.
func (c *Help) Name() cli.CmdName {
return CmdNmHelp
}
// Help prints out the help message for the command.
func (c *Help) Help(
ctx context.Context,
) {
out.Normf("\n")
out.Normf(" _ ______ __________ \n")
out.Normf(" | | /| / / __ `/ ___/ __ \\ \n")
out.Normf(" | |/ |/ / /_/ / / / /_/ / \n")
out.Normf(" |__/|__/\\__,_/_/ / .___/ \n")
out.Normf(" /_/ ")
out.Boldf("v%s\n", warp.Version)
out.Normf("\n")
out.Normf(" Secure terminal sharing with one simple command.\n")
out.Normf("\n")
out.Normf("Usage:\n")
out.Boldf(" warp <command> [<args> ...]\n")
out.Normf("\n")
out.Normf("Commands:\n")
out.Boldf(" help <command>\n")
out.Normf(" Show help for a specific command.\n")
out.Valuf(" warp help open\n")
out.Normf("\n")
out.Boldf(" open [<id>]\n")
out.Normf(" Creates a new warp.\n")
out.Valuf(" warp open\n")
out.Normf("\n")
out.Boldf(" connect <id>\n")
out.Normf(" Connects to an existing warp.\n")
out.Valuf(" warp connect goofy-dev\n")
out.Normf("\n")
out.Boldf(" state\n")
out.Normf(" Displays the state of the current warp (in-warp only).\n")
out.Valuf(" warp state\n")
out.Normf("\n")
out.Boldf(" authorize <username_or_token>\n")
out.Normf(" Grants write access to a client (in-warp only).\n")
out.Valuf(" warp authorize goofy\n")
out.Normf("\n")
out.Boldf(" revoke [<username_or_token>]\n")
out.Normf(" Revokes write access to one or all clients (in-warp only).\n")
out.Valuf(" warp revoke\n")
out.Normf("\n")
}
// Parse parses the arguments passed to the command.
func (c *Help) Parse(
ctx context.Context,
args []string,
flags map[string]string,
) error {
if len(args) == 0 {
c.Command = NewHelp()
} else {
if r, ok := cli.Registrar[cli.CmdName(args[0])]; !ok {
c.Command = NewHelp()
} else {
c.Command = r()
}
}
return nil
}
// Execute the command or return a human-friendly error.
func (c *Help) Execute(
ctx context.Context,
) error {
c.Command.Help(ctx)
return nil
}