-
Notifications
You must be signed in to change notification settings - Fork 15
/
help.go
57 lines (47 loc) · 1.18 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
package command
import (
"context"
"fmt"
"github.com/avenga/couper/config"
"github.com/sirupsen/logrus"
)
var _ Cmd = &Help{}
// Synopsis shows available commands and options.
func Synopsis() { // TODO: generate from command and options list
println(`
Couper usage:
couper <cmd> <options>
Available commands:
help Usage for given command.
run Start the server with given configuration file.
verify Verify the syntax of the given configuration file.
version Print the current version and build information.
Examples:
couper run
couper run -f couper.hcl
couper run -watch -log-format json -log-pretty -p 3000
couper verify -f couper.hcl
`)
}
type Help struct {
ctx context.Context
}
func NewHelp(ctx context.Context) *Help {
return &Help{ctx: ctx}
}
func (h Help) Execute(args Args, _ *config.Couper, _ *logrus.Entry) error {
defer Synopsis()
if len(args) == 0 {
h.Usage()
return fmt.Errorf("missing command argument")
}
cmd := NewCommand(h.ctx, args[0])
if cmd == nil {
return fmt.Errorf("unknown command: %s", args[0])
}
cmd.Usage()
return nil
}
func (h Help) Usage() {
println("Usage of help:\n help <command> Print usage information of given command.")
}