-
Notifications
You must be signed in to change notification settings - Fork 3
/
command.go
89 lines (77 loc) · 1.67 KB
/
command.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
package gofire
type Visitor interface {
VisitPlaceholder(Placeholder) error
VisitArgument(Argument) error
VisitFlag(Flag, *Group) error
}
// Parameter defines an abstraction for cmd parameter.
type Parameter interface {
Accept(Visitor) error
}
// Placeholder is a cmd parameter implementation
// that just hold parameter slot.
type Placeholder struct {
Type Typ
}
func (p Placeholder) Accept(v Visitor) error {
return v.VisitPlaceholder(p)
}
// Argument is a cmd parameter implementation
// that represents cmd positional argument.
type Argument struct {
Index uint64
Ellipsis bool
Type Typ
}
func (a Argument) Accept(v Visitor) error {
return v.VisitArgument(a)
}
// Flag is a cmd parameter implementation
// that represents cmd flag.
type Flag struct {
Full string
Short string
Doc string
Deprecated bool
Hidden bool
Default interface{}
Type Typ
}
func (f Flag) Accept(v Visitor) error {
return v.VisitFlag(f, nil)
}
// Group is a cmd parameter implementation
// that groups multiple cmd flags together.
type Group struct {
Name string
Doc string
Flags []Flag
Type Typ
}
func (g Group) Accept(v Visitor) error {
for _, f := range g.Flags {
if err := v.VisitFlag(f, &g); err != nil {
return err
}
}
return nil
}
// Group is a cmd composite parameter implementation
// that represent function as a command.
type Command struct {
Package string
Function string
Definition string
Doc string
Context bool
Results []string
Parameters []Parameter
}
func (c Command) Accept(v Visitor) error {
for _, p := range c.Parameters {
if err := p.Accept(v); err != nil {
return err
}
}
return nil
}