-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcommandlineCLI-027.ref
More file actions
139 lines (109 loc) · 3.63 KB
/
commandlineCLI-027.ref
File metadata and controls
139 lines (109 loc) · 3.63 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// -*- go -*-
////////////////////////////////////////////////////////////////////////////
// Program: redo
// Purpose: global option redo
////////////////////////////////////////////////////////////////////////////
package main
import (
"github.com/mkideal/cli"
)
////////////////////////////////////////////////////////////////////////////
// redo
type rootT struct {
cli.Helper
Self *rootT `cli:"c,config" usage:"config file" json:"-" parser:"jsonfile" dft:"redo.json"`
Host string `cli:"H,host" usage:"host address" dft:"$HOST"`
Port int `cli:"p,port" usage:"listening port" dft:"80"`
}
var root = &cli.Command{
Name: "redo",
Desc: "global option redo",
Text: " redo global option via automatic code-gen",
Global: true,
Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
Fn: redo,
NumArg: cli.ExactN(1),
}
// func main() {
// cli.SetUsageStyle(cli.ManualStyle) // up-down, for left-right, use NormalStyle
// //NOTE: You can set any writer implements io.Writer
// // default writer is os.Stdout
// if err := cli.Root(root,
// cli.Tree(buildDef),
// cli.Tree(installDef),
// cli.Tree(publishDef)).Run(os.Args[1:]); err != nil {
// fmt.Fprintln(os.Stderr, err)
// }
// fmt.Println("")
// }
// func redo(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
// return nil
// }
////////////////////////////////////////////////////////////////////////////
// build
// func buildCLI(ctx *cli.Context) error {
// rootArgv := ctx.RootArgv().(*rootT)
// argv := ctx.Argv().(*buildT)
// fmt.Printf("[build]:\n %+v\n %+v\n %v\n", rootArgv, argv, ctx.Args())
// return nil
// }
type buildT struct {
Dir string `cli:"dir" usage:"source code root dir" dft:"./"`
Suffix string `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
Out string `cli:"o,out" usage:"output filename"`
}
var buildDef = &cli.Command{
Name: "build",
Desc: "Build the network application",
Text: "Usage:\n redo build [Options] Arch(i386|amd64)",
Argv: func() interface{} { return new(buildT) },
Fn: buildCLI,
NumArg: cli.ExactN(1),
CanSubRoute: true,
}
////////////////////////////////////////////////////////////////////////////
// install
// func installCLI(ctx *cli.Context) error {
// rootArgv := ctx.RootArgv().(*rootT)
// argv := ctx.Argv().(*installT)
// fmt.Printf("[install]:\n %+v\n %+v\n %v\n", rootArgv, argv, ctx.Args())
// return nil
// }
type installT struct {
Dir string `cli:"dir" usage:"source code root dir" dft:"./"`
Suffix string `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
Out string `cli:"o,out" usage:"output filename"`
}
var installDef = &cli.Command{
Name: "install",
Desc: "Install the network application",
Text: "Usage:\n redo install [Options] package [package...]",
Argv: func() interface{} { return new(installT) },
Fn: installCLI,
NumArg: cli.AtLeast(1),
CanSubRoute: true,
}
////////////////////////////////////////////////////////////////////////////
// publish
// func publishCLI(ctx *cli.Context) error {
// rootArgv := ctx.RootArgv().(*rootT)
// argv := ctx.Argv().(*publishT)
// fmt.Printf("[publish]:\n %+v\n %+v\n %v\n", rootArgv, argv, ctx.Args())
// return nil
// }
type publishT struct {
Dir string `cli:"*d,dir" usage:"publish dir"`
Suffix string `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
Out string `cli:"o,out" usage:"output filename"`
List bool `cli:"l,list" usage:"list all sub commands"`
}
var publishDef = &cli.Command{
Name: "publish",
Desc: "Publish the network application",
Argv: func() interface{} { return new(publishT) },
Fn: publishCLI,
NumOption: cli.AtLeast(1),
}