-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopcli.go
94 lines (75 loc) · 2.03 KB
/
topcli.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
package otium
import (
"fmt"
"io"
"github.com/alecthomas/kong"
)
type bind struct {
pcd *Procedure
}
// Ensure the topcli compiles.
var _ = kong.Must(&topcli{})
// Top-level REPL commands.
type topcli struct {
Help helpCmd `cmd:"" help:"Show help."`
Question helpCmd `cmd:"" hidden:"" name:"?" help:"Show help."`
Repl replCmd `cmd:"" help:"Show help for the REPL."`
List listCmd `cmd:"" help:"Show the list of steps."`
Next nextCmd `cmd:"" help:"Run the next step."`
Quit quitCmd `cmd:"" help:"Quit the program."`
Variables variablesCmd `cmd:"" help:"List the variables."`
}
type helpCmd struct {
Command []string `arg:"" optional:"" help:"Show help on command."`
}
func (h *helpCmd) Run(realCtx *kong.Context) error {
ctx, err := kong.Trace(realCtx.Kong, h.Command)
if err != nil {
return err
}
if ctx.Error != nil {
return ctx.Error
}
err = ctx.PrintUsage(false)
if err != nil {
return err
}
fmt.Fprintln(realCtx.Stdout)
return nil
}
type replCmd struct{}
func (hr *replCmd) Run(ctx *kong.Context) error {
ctx.Printf(`
The REPL is based on https://github.com/peterh/liner; see there for the full
keystroke list.
Subset of the supported keystrokes:
Keystroke Action
----------- ------
Tab List completions
Tab Tab List all commands (if line is empty)
Up arrow Previous match from history, like Fish shell
Down arrow Next match from history, like Fish shell
Ctrl-R Reverse Search history, like Bash shell (Esc cancel)
Ctrl-D (if line is empty) End of File - usually quits application
`)
return nil
}
type listCmd struct{}
func (l *listCmd) Run(bind *bind) error {
printToc(bind.pcd)
return nil
}
type nextCmd struct{}
func (n *nextCmd) Run(bind *bind) error {
return cmdNext(bind.pcd)
}
type quitCmd struct{}
func (q *quitCmd) Run(bind *bind) error {
// FIXME HACK USE PROPER ErrQuit sentinel instead!!!
return io.EOF
}
type variablesCmd struct{}
func (q *variablesCmd) Run(bind *bind) error {
cmdVariables(bind.pcd)
return nil
}