Browse Source

Initial Commit

master
Tim Schuster 1 year ago
commit
321a49e568
Signed by: Tim Schuster <mail@timschuster.info> GPG Key ID: F9E27097EFB77F61

+ 127
- 0
instr.go View File

@@ -0,0 +1,127 @@
1
+package fidgetlang
2
+
3
+type instruction byte
4
+
5
+const (
6
+	iIncrPtr instruction = 1 << iota
7
+	iDecrPtr
8
+	iIncrVal
9
+	iDecrVal
10
+	iPutVal
11
+	iGetVal
12
+	iJumpAhead
13
+	iJumpBehind
14
+	iNop instruction = 0
15
+
16
+	sIncrPtr    = "߷"
17
+	sDecrPtr    = "߷߷"
18
+	sIncrVal    = "߷߷߷"
19
+	sDecrVal    = "߷߷߷߷"
20
+	sPutVal     = "߷߷߷߷߷"
21
+	sGetVal     = "߷߷߷߷߷߷"
22
+	sJumpAhead  = "߷߷߷߷߷߷߷"
23
+	sJumpBehind = "߷߷߷߷߷߷߷߷"
24
+	sNop        = " "
25
+
26
+	dIncrPtr    = "IncrPtr"
27
+	dDecrPtr    = "DecrPtr"
28
+	dIncrVal    = "IncrVal"
29
+	dDecrVal    = "DecrVal"
30
+	dPutVal     = "PutVal"
31
+	dGetVal     = "GetVal"
32
+	dJumpAhead  = "JumpAhead"
33
+	dJumpBehind = "JumpBehind"
34
+	dNop        = "Nop"
35
+)
36
+
37
+func stringToInstruction(d string) instruction {
38
+	switch d {
39
+	case sIncrPtr:
40
+		return iIncrPtr
41
+	case sDecrPtr:
42
+		return iDecrPtr
43
+	case sIncrVal:
44
+		return iIncrVal
45
+	case sDecrVal:
46
+		return iDecrVal
47
+	case sPutVal:
48
+		return iPutVal
49
+	case sGetVal:
50
+		return iGetVal
51
+	case sJumpAhead:
52
+		return iJumpAhead
53
+	case sJumpBehind:
54
+		return iJumpBehind
55
+	default:
56
+		return iNop
57
+	}
58
+}
59
+
60
+func instructionToString(i instruction) string {
61
+	switch i {
62
+	case iIncrPtr:
63
+		return sIncrPtr
64
+	case iDecrPtr:
65
+		return sDecrPtr
66
+	case iIncrVal:
67
+		return sIncrVal
68
+	case iDecrVal:
69
+		return sDecrVal
70
+	case iPutVal:
71
+		return sPutVal
72
+	case iGetVal:
73
+		return sGetVal
74
+	case iJumpAhead:
75
+		return sJumpAhead
76
+	case iJumpBehind:
77
+		return sJumpBehind
78
+	default:
79
+		return sNop
80
+	}
81
+}
82
+
83
+func debugToInstruction(d string) instruction {
84
+	switch d {
85
+	case dIncrPtr:
86
+		return iIncrPtr
87
+	case dDecrPtr:
88
+		return iDecrPtr
89
+	case dIncrVal:
90
+		return iIncrVal
91
+	case dDecrVal:
92
+		return iDecrVal
93
+	case dPutVal:
94
+		return iPutVal
95
+	case dGetVal:
96
+		return iGetVal
97
+	case dJumpAhead:
98
+		return iJumpAhead
99
+	case dJumpBehind:
100
+		return iJumpBehind
101
+	default:
102
+		return iNop
103
+	}
104
+}
105
+
106
+func instructionToDebug(i instruction) string {
107
+	switch i {
108
+	case iIncrPtr:
109
+		return dIncrPtr
110
+	case iDecrPtr:
111
+		return dDecrPtr
112
+	case iIncrVal:
113
+		return dIncrVal
114
+	case iDecrVal:
115
+		return dDecrVal
116
+	case iPutVal:
117
+		return dPutVal
118
+	case iGetVal:
119
+		return dGetVal
120
+	case iJumpAhead:
121
+		return dJumpAhead
122
+	case iJumpBehind:
123
+		return dJumpBehind
124
+	default:
125
+		return dNop
126
+	}
127
+}

+ 44
- 0
jit.go View File

@@ -0,0 +1,44 @@
1
+package fidgetlang
2
+
3
+import "strings"
4
+
5
+func compileDebug(debug string) []instruction {
6
+	var program = []instruction{}
7
+
8
+	instr := strings.Split(debug, " ")
9
+
10
+	for k := range instr {
11
+		instr[k] = strings.TrimSpace(instr[k])
12
+		program = append(program, debugToInstruction(instr[k]))
13
+	}
14
+
15
+	return program
16
+}
17
+
18
+func compileProgram(prg string) []instruction {
19
+	var program = []instruction{}
20
+
21
+	instr := strings.Split(prg, " ")
22
+
23
+	for k := range instr {
24
+		instr[k] = strings.TrimSpace(instr[k])
25
+		program = append(program, stringToInstruction(instr[k]))
26
+	}
27
+
28
+	return program
29
+}
30
+
31
+func makeDebug(k []instruction) string {
32
+	if len(k) == 0 {
33
+		return ""
34
+	}
35
+	var out = instructionToDebug(k[0])
36
+
37
+	if len(k) > 1 {
38
+		for i := range k[1:] {
39
+			out += " " + instructionToDebug(k[i])
40
+		}
41
+	}
42
+
43
+	return out
44
+}

+ 2
- 0
repl/.gitignore View File

@@ -0,0 +1,2 @@
1
+repl
2
+*.exe

+ 1
- 0
repl/fidget.fl View File

@@ -0,0 +1 @@
1
+ ߷߷߷߷߷߷ ߷߷߷߷߷߷߷ ߷߷߷߷߷ ߷߷߷߷߷߷ ߷߷߷߷߷߷߷߷ 

+ 67
- 0
repl/main.go View File

@@ -0,0 +1,67 @@
1
+package main
2
+
3
+import (
4
+	"fmt"
5
+	"go.rls.moe/fidgetlang"
6
+	"gopkg.in/urfave/cli.v1"
7
+	"io/ioutil"
8
+	"os"
9
+	"time"
10
+)
11
+
12
+func main() {
13
+	app := cli.NewApp()
14
+	app.Name = "FidgetLang REPL"
15
+	app.Usage = "I'm being honest, this is not one of my greatest moments"
16
+	app.HideHelp = true
17
+	app.HideVersion = true
18
+	app.Flags = []cli.Flag{
19
+		cli.StringFlag{
20
+			Name:  "file, f",
21
+			Usage: "File to execute",
22
+			Value: "fidget.fl",
23
+		},
24
+		cli.BoolFlag{
25
+			Name:  "debug, d",
26
+			Usage: "Enable Debug Language",
27
+		},
28
+		cli.BoolFlag{
29
+			Name:  "dump, q",
30
+			Usage: "Dump Compiled Program",
31
+		},
32
+		cli.BoolFlag{
33
+			Name:  "hex, h",
34
+			Usage: "Print output in hex",
35
+		},
36
+	}
37
+
38
+	app.Action = func(c *cli.Context) error {
39
+		s := fidgetlang.NewState()
40
+		f, err := ioutil.ReadFile(c.String("file"))
41
+		if err != nil {
42
+			fmt.Printf("Err: %s\n", err)
43
+			return nil
44
+		}
45
+		s.DebugOut = c.Bool("hex")
46
+
47
+		if c.Bool("debug") {
48
+			s.CompileDebug(string(f))
49
+		} else {
50
+			s.Compile(string(f))
51
+		}
52
+
53
+		if c.Bool("dump") {
54
+			fmt.Println(s.GetDebugProgram())
55
+			return nil
56
+		}
57
+
58
+		for s.Step() {
59
+			time.Sleep(1 * time.Millisecond)
60
+		}
61
+
62
+		fmt.Println("\nFinished")
63
+		return nil
64
+	}
65
+
66
+	app.Run(os.Args)
67
+}

+ 136
- 0
state.go View File

@@ -0,0 +1,136 @@
1
+package fidgetlang
2
+
3
+import (
4
+	"bufio"
5
+	"fmt"
6
+	"io"
7
+	"os"
8
+	"strings"
9
+)
10
+
11
+func NewState() *State {
12
+	return &State{
13
+		registers:         [256]int32{},
14
+		position:          0,
15
+		instruction:       0,
16
+		instructionMemory: []instruction{},
17
+		buffReader:        bufio.NewReader(os.Stdin),
18
+	}
19
+}
20
+
21
+type State struct {
22
+	registers         [256]int32
23
+	position          byte
24
+	instruction       uint32
25
+	instructionMemory []instruction
26
+	buffReader        *bufio.Reader
27
+	DebugOut          bool
28
+	SuperDebug        bool
29
+}
30
+
31
+func (s *State) CompileDebug(program string) {
32
+	s.instructionMemory = compileDebug(program)
33
+}
34
+
35
+func (s *State) Compile(program string) {
36
+	s.instructionMemory = compileProgram(program)
37
+}
38
+
39
+func (s *State) GetDebugProgram() string {
40
+	return makeDebug(s.instructionMemory)
41
+}
42
+
43
+func (s *State) bug(text string, args ...interface{}) {
44
+	if !s.SuperDebug {
45
+		return
46
+	}
47
+	var sArgs = make([]string, len(args))
48
+	for k := range args {
49
+		sArgs[k] = fmt.Sprint(args[k])
50
+	}
51
+	println(strings.Join(append([]string{text}, sArgs...), " "))
52
+}
53
+
54
+// Step returns false if the end of memory is reached
55
+func (s *State) Step() bool {
56
+	if s.overEnd() {
57
+		return false
58
+	}
59
+	s.bug("X at I", s.instruction)
60
+	switch s.curInstr() {
61
+	case iIncrPtr:
62
+		s.bug("I of P")
63
+		s.position++
64
+	case iDecrPtr:
65
+		s.bug("D of P")
66
+		s.position--
67
+	case iIncrVal:
68
+		s.bug("I of V")
69
+		s.setData(s.curData() + 1)
70
+	case iDecrVal:
71
+		s.bug("D of V")
72
+		s.setData(s.curData() - 1)
73
+	case iPutVal:
74
+		s.bug("P of V")
75
+		if s.DebugOut {
76
+			fmt.Printf("0x%04X\n", s.curData())
77
+		} else {
78
+			fmt.Printf("%s", string(rune(s.curData())))
79
+		}
80
+	case iGetVal:
81
+		s.bug("R of V")
82
+		rrune, _, err := s.buffReader.ReadRune()
83
+		if err == io.EOF {
84
+			return false
85
+		}
86
+		if err != nil {
87
+			panic(err)
88
+		}
89
+		s.setData(rrune)
90
+	case iJumpBehind:
91
+		if s.curData() != 0 {
92
+			for s.curInstr() != iJumpAhead {
93
+				s.instruction--
94
+			}
95
+			s.bug("JB to I", s.instruction)
96
+			return true
97
+		}
98
+	case iJumpAhead:
99
+		if s.atEnd() {
100
+			s.bug("JA abort at", s.instruction)
101
+			return false
102
+		}
103
+		if s.curData() == 0 {
104
+			for s.curInstr() != iJumpBehind {
105
+				s.instruction++
106
+			}
107
+			s.bug("JA to I", s.instruction)
108
+			return true
109
+		}
110
+	}
111
+	if s.atEnd() {
112
+		return false
113
+	}
114
+	s.instruction++
115
+	return true
116
+}
117
+
118
+func (s *State) atEnd() bool {
119
+	return int(s.instruction) == len(s.instructionMemory)-1
120
+}
121
+
122
+func (s *State) overEnd() bool {
123
+	return int(s.instruction) >= len(s.instructionMemory)
124
+}
125
+
126
+func (s *State) curInstr() instruction {
127
+	return instruction(s.instructionMemory[s.instruction])
128
+}
129
+
130
+func (s *State) curData() int32 {
131
+	return s.registers[s.position]
132
+}
133
+
134
+func (s *State) setData(d int32) {
135
+	s.registers[s.position] = d
136
+}

+ 392
- 0
vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md View File

@@ -0,0 +1,392 @@
1
+# Change Log
2
+
3
+**ATTN**: This project uses [semantic versioning](http://semver.org/).
4
+
5
+## [Unreleased]
6
+
7
+## [1.19.1] - 2016-11-21
8
+
9
+### Fixed
10
+
11
+- Fixes regression introduced in 1.19.0 where using an `ActionFunc` as
12
+  the `Action` for a command would cause it to error rather than calling the
13
+  function. Should not have a affected declarative cases using `func(c
14
+  *cli.Context) err)`.
15
+- Shell completion now handles the case where the user specifies
16
+  `--generate-bash-completion` immediately after a flag that takes an argument.
17
+  Previously it call the application with `--generate-bash-completion` as the
18
+  flag value.
19
+
20
+## [1.19.0] - 2016-11-19
21
+### Added
22
+- `FlagsByName` was added to make it easy to sort flags (e.g. `sort.Sort(cli.FlagsByName(app.Flags))`)
23
+- A `Description` field was added to `App` for a more detailed description of
24
+  the application (similar to the existing `Description` field on `Command`)
25
+- Flag type code generation via `go generate`
26
+- Write to stderr and exit 1 if action returns non-nil error
27
+- Added support for TOML to the `altsrc` loader
28
+- `SkipArgReorder` was added to allow users to skip the argument reordering.
29
+  This is useful if you want to consider all "flags" after an argument as
30
+  arguments rather than flags (the default behavior of the stdlib `flag`
31
+  library). This is backported functionality from the [removal of the flag
32
+  reordering](https://github.com/urfave/cli/pull/398) in the unreleased version
33
+  2
34
+- For formatted errors (those implementing `ErrorFormatter`), the errors will
35
+  be formatted during output. Compatible with `pkg/errors`.
36
+
37
+### Changed
38
+- Raise minimum tested/supported Go version to 1.2+
39
+
40
+### Fixed
41
+- Consider empty environment variables as set (previously environment variables
42
+  with the equivalent of `""` would be skipped rather than their value used).
43
+- Return an error if the value in a given environment variable cannot be parsed
44
+  as the flag type. Previously these errors were silently swallowed.
45
+- Print full error when an invalid flag is specified (which includes the invalid flag)
46
+- `App.Writer` defaults to `stdout` when `nil`
47
+- If no action is specified on a command or app, the help is now printed instead of `panic`ing
48
+- `App.Metadata` is initialized automatically now (previously was `nil` unless initialized)
49
+- Correctly show help message if `-h` is provided to a subcommand
50
+- `context.(Global)IsSet` now respects environment variables. Previously it
51
+  would return `false` if a flag was specified in the environment rather than
52
+  as an argument
53
+- Removed deprecation warnings to STDERR to avoid them leaking to the end-user
54
+- `altsrc`s import paths were updated to use `gopkg.in/urfave/cli.v1`. This
55
+  fixes issues that occurred when `gopkg.in/urfave/cli.v1` was imported as well
56
+  as `altsrc` where Go would complain that the types didn't match
57
+
58
+## [1.18.1] - 2016-08-28
59
+### Fixed
60
+- Removed deprecation warnings to STDERR to avoid them leaking to the end-user (backported)
61
+
62
+## [1.18.0] - 2016-06-27
63
+### Added
64
+- `./runtests` test runner with coverage tracking by default
65
+- testing on OS X
66
+- testing on Windows
67
+- `UintFlag`, `Uint64Flag`, and `Int64Flag` types and supporting code
68
+
69
+### Changed
70
+- Use spaces for alignment in help/usage output instead of tabs, making the
71
+  output alignment consistent regardless of tab width
72
+
73
+### Fixed
74
+- Printing of command aliases in help text
75
+- Printing of visible flags for both struct and struct pointer flags
76
+- Display the `help` subcommand when using `CommandCategories`
77
+- No longer swallows `panic`s that occur within the `Action`s themselves when
78
+  detecting the signature of the `Action` field
79
+
80
+## [1.17.1] - 2016-08-28
81
+### Fixed
82
+- Removed deprecation warnings to STDERR to avoid them leaking to the end-user
83
+
84
+## [1.17.0] - 2016-05-09
85
+### Added
86
+- Pluggable flag-level help text rendering via `cli.DefaultFlagStringFunc`
87
+- `context.GlobalBoolT` was added as an analogue to `context.GlobalBool`
88
+- Support for hiding commands by setting `Hidden: true` -- this will hide the
89
+  commands in help output
90
+
91
+### Changed
92
+- `Float64Flag`, `IntFlag`, and `DurationFlag` default values are no longer
93
+  quoted in help text output.
94
+- All flag types now include `(default: {value})` strings following usage when a
95
+  default value can be (reasonably) detected.
96
+- `IntSliceFlag` and `StringSliceFlag` usage strings are now more consistent
97
+  with non-slice flag types
98
+- Apps now exit with a code of 3 if an unknown subcommand is specified
99
+  (previously they printed "No help topic for...", but still exited 0. This
100
+  makes it easier to script around apps built using `cli` since they can trust
101
+  that a 0 exit code indicated a successful execution.
102
+- cleanups based on [Go Report Card
103
+  feedback](https://goreportcard.com/report/github.com/urfave/cli)
104
+
105
+## [1.16.1] - 2016-08-28
106
+### Fixed
107
+- Removed deprecation warnings to STDERR to avoid them leaking to the end-user
108
+
109
+## [1.16.0] - 2016-05-02
110
+### Added
111
+- `Hidden` field on all flag struct types to omit from generated help text
112
+
113
+### Changed
114
+- `BashCompletionFlag` (`--enable-bash-completion`) is now omitted from
115
+generated help text via the `Hidden` field
116
+
117
+### Fixed
118
+- handling of error values in `HandleAction` and `HandleExitCoder`
119
+
120
+## [1.15.0] - 2016-04-30
121
+### Added
122
+- This file!
123
+- Support for placeholders in flag usage strings
124
+- `App.Metadata` map for arbitrary data/state management
125
+- `Set` and `GlobalSet` methods on `*cli.Context` for altering values after
126
+parsing.
127
+- Support for nested lookup of dot-delimited keys in structures loaded from
128
+YAML.
129
+
130
+### Changed
131
+- The `App.Action` and `Command.Action` now prefer a return signature of
132
+`func(*cli.Context) error`, as defined by `cli.ActionFunc`.  If a non-nil
133
+`error` is returned, there may be two outcomes:
134
+    - If the error fulfills `cli.ExitCoder`, then `os.Exit` will be called
135
+    automatically
136
+    - Else the error is bubbled up and returned from `App.Run`
137
+- Specifying an `Action` with the legacy return signature of
138
+`func(*cli.Context)` will produce a deprecation message to stderr
139
+- Specifying an `Action` that is not a `func` type will produce a non-zero exit
140
+from `App.Run`
141
+- Specifying an `Action` func that has an invalid (input) signature will
142
+produce a non-zero exit from `App.Run`
143
+
144
+### Deprecated
145
+- <a name="deprecated-cli-app-runandexitonerror"></a>
146
+`cli.App.RunAndExitOnError`, which should now be done by returning an error
147
+that fulfills `cli.ExitCoder` to `cli.App.Run`.
148
+- <a name="deprecated-cli-app-action-signature"></a> the legacy signature for
149
+`cli.App.Action` of `func(*cli.Context)`, which should now have a return
150
+signature of `func(*cli.Context) error`, as defined by `cli.ActionFunc`.
151
+
152
+### Fixed
153
+- Added missing `*cli.Context.GlobalFloat64` method
154
+
155
+## [1.14.0] - 2016-04-03 (backfilled 2016-04-25)
156
+### Added
157
+- Codebeat badge
158
+- Support for categorization via `CategorizedHelp` and `Categories` on app.
159
+
160
+### Changed
161
+- Use `filepath.Base` instead of `path.Base` in `Name` and `HelpName`.
162
+
163
+### Fixed
164
+- Ensure version is not shown in help text when `HideVersion` set.
165
+
166
+## [1.13.0] - 2016-03-06 (backfilled 2016-04-25)
167
+### Added
168
+- YAML file input support.
169
+- `NArg` method on context.
170
+
171
+## [1.12.0] - 2016-02-17 (backfilled 2016-04-25)
172
+### Added
173
+- Custom usage error handling.
174
+- Custom text support in `USAGE` section of help output.
175
+- Improved help messages for empty strings.
176
+- AppVeyor CI configuration.
177
+
178
+### Changed
179
+- Removed `panic` from default help printer func.
180
+- De-duping and optimizations.
181
+
182
+### Fixed
183
+- Correctly handle `Before`/`After` at command level when no subcommands.
184
+- Case of literal `-` argument causing flag reordering.
185
+- Environment variable hints on Windows.
186
+- Docs updates.
187
+
188
+## [1.11.1] - 2015-12-21 (backfilled 2016-04-25)
189
+### Changed
190
+- Use `path.Base` in `Name` and `HelpName`
191
+- Export `GetName` on flag types.
192
+
193
+### Fixed
194
+- Flag parsing when skipping is enabled.
195
+- Test output cleanup.
196
+- Move completion check to account for empty input case.
197
+
198
+## [1.11.0] - 2015-11-15 (backfilled 2016-04-25)
199
+### Added
200
+- Destination scan support for flags.
201
+- Testing against `tip` in Travis CI config.
202
+
203
+### Changed
204
+- Go version in Travis CI config.
205
+
206
+### Fixed
207
+- Removed redundant tests.
208
+- Use correct example naming in tests.
209
+
210
+## [1.10.2] - 2015-10-29 (backfilled 2016-04-25)
211
+### Fixed
212
+- Remove unused var in bash completion.
213
+
214
+## [1.10.1] - 2015-10-21 (backfilled 2016-04-25)
215
+### Added
216
+- Coverage and reference logos in README.
217
+
218
+### Fixed
219
+- Use specified values in help and version parsing.
220
+- Only display app version and help message once.
221
+
222
+## [1.10.0] - 2015-10-06 (backfilled 2016-04-25)
223
+### Added
224
+- More tests for existing functionality.
225
+- `ArgsUsage` at app and command level for help text flexibility.
226
+
227
+### Fixed
228
+- Honor `HideHelp` and `HideVersion` in `App.Run`.
229
+- Remove juvenile word from README.
230
+
231
+## [1.9.0] - 2015-09-08 (backfilled 2016-04-25)
232
+### Added
233
+- `FullName` on command with accompanying help output update.
234
+- Set default `$PROG` in bash completion.
235
+
236
+### Changed
237
+- Docs formatting.
238
+
239
+### Fixed
240
+- Removed self-referential imports in tests.
241
+
242
+## [1.8.0] - 2015-06-30 (backfilled 2016-04-25)
243
+### Added
244
+- Support for `Copyright` at app level.
245
+- `Parent` func at context level to walk up context lineage.
246
+
247
+### Fixed
248
+- Global flag processing at top level.
249
+
250
+## [1.7.1] - 2015-06-11 (backfilled 2016-04-25)
251
+### Added
252
+- Aggregate errors from `Before`/`After` funcs.
253
+- Doc comments on flag structs.
254
+- Include non-global flags when checking version and help.
255
+- Travis CI config updates.
256
+
257
+### Fixed
258
+- Ensure slice type flags have non-nil values.
259
+- Collect global flags from the full command hierarchy.
260
+- Docs prose.
261
+
262
+## [1.7.0] - 2015-05-03 (backfilled 2016-04-25)
263
+### Changed
264
+- `HelpPrinter` signature includes output writer.
265
+
266
+### Fixed
267
+- Specify go 1.1+ in docs.
268
+- Set `Writer` when running command as app.
269
+
270
+## [1.6.0] - 2015-03-23 (backfilled 2016-04-25)
271
+### Added
272
+- Multiple author support.
273
+- `NumFlags` at context level.
274
+- `Aliases` at command level.
275
+
276
+### Deprecated
277
+- `ShortName` at command level.
278
+
279
+### Fixed
280
+- Subcommand help output.
281
+- Backward compatible support for deprecated `Author` and `Email` fields.
282
+- Docs regarding `Names`/`Aliases`.
283
+
284
+## [1.5.0] - 2015-02-20 (backfilled 2016-04-25)
285
+### Added
286
+- `After` hook func support at app and command level.
287
+
288
+### Fixed
289
+- Use parsed context when running command as subcommand.
290
+- Docs prose.
291
+
292
+## [1.4.1] - 2015-01-09 (backfilled 2016-04-25)
293
+### Added
294
+- Support for hiding `-h / --help` flags, but not `help` subcommand.
295
+- Stop flag parsing after `--`.
296
+
297
+### Fixed
298
+- Help text for generic flags to specify single value.
299
+- Use double quotes in output for defaults.
300
+- Use `ParseInt` instead of `ParseUint` for int environment var values.
301
+- Use `0` as base when parsing int environment var values.
302
+
303
+## [1.4.0] - 2014-12-12 (backfilled 2016-04-25)
304
+### Added
305
+- Support for environment variable lookup "cascade".
306
+- Support for `Stdout` on app for output redirection.
307
+
308
+### Fixed
309
+- Print command help instead of app help in `ShowCommandHelp`.
310
+
311
+## [1.3.1] - 2014-11-13 (backfilled 2016-04-25)
312
+### Added
313
+- Docs and example code updates.
314
+
315
+### Changed
316
+- Default `-v / --version` flag made optional.
317
+
318
+## [1.3.0] - 2014-08-10 (backfilled 2016-04-25)
319
+### Added
320
+- `FlagNames` at context level.
321
+- Exposed `VersionPrinter` var for more control over version output.
322
+- Zsh completion hook.
323
+- `AUTHOR` section in default app help template.
324
+- Contribution guidelines.
325
+- `DurationFlag` type.
326
+
327
+## [1.2.0] - 2014-08-02
328
+### Added
329
+- Support for environment variable defaults on flags plus tests.
330
+
331
+## [1.1.0] - 2014-07-15
332
+### Added
333
+- Bash completion.
334
+- Optional hiding of built-in help command.
335
+- Optional skipping of flag parsing at command level.
336
+- `Author`, `Email`, and `Compiled` metadata on app.
337
+- `Before` hook func support at app and command level.
338
+- `CommandNotFound` func support at app level.
339
+- Command reference available on context.
340
+- `GenericFlag` type.
341
+- `Float64Flag` type.
342
+- `BoolTFlag` type.
343
+- `IsSet` flag helper on context.
344
+- More flag lookup funcs at context level.
345
+- More tests &amp; docs.
346
+
347
+### Changed
348
+- Help template updates to account for presence/absence of flags.
349
+- Separated subcommand help template.
350
+- Exposed `HelpPrinter` var for more control over help output.
351
+
352
+## [1.0.0] - 2013-11-01
353
+### Added
354
+- `help` flag in default app flag set and each command flag set.
355
+- Custom handling of argument parsing errors.
356
+- Command lookup by name at app level.
357
+- `StringSliceFlag` type and supporting `StringSlice` type.
358
+- `IntSliceFlag` type and supporting `IntSlice` type.
359
+- Slice type flag lookups by name at context level.
360
+- Export of app and command help functions.
361
+- More tests &amp; docs.
362
+
363
+## 0.1.0 - 2013-07-22
364
+### Added
365
+- Initial implementation.
366
+
367
+[Unreleased]: https://github.com/urfave/cli/compare/v1.18.0...HEAD
368
+[1.18.0]: https://github.com/urfave/cli/compare/v1.17.0...v1.18.0
369
+[1.17.0]: https://github.com/urfave/cli/compare/v1.16.0...v1.17.0
370
+[1.16.0]: https://github.com/urfave/cli/compare/v1.15.0...v1.16.0
371
+[1.15.0]: https://github.com/urfave/cli/compare/v1.14.0...v1.15.0
372
+[1.14.0]: https://github.com/urfave/cli/compare/v1.13.0...v1.14.0
373
+[1.13.0]: https://github.com/urfave/cli/compare/v1.12.0...v1.13.0
374
+[1.12.0]: https://github.com/urfave/cli/compare/v1.11.1...v1.12.0
375
+[1.11.1]: https://github.com/urfave/cli/compare/v1.11.0...v1.11.1
376
+[1.11.0]: https://github.com/urfave/cli/compare/v1.10.2...v1.11.0
377
+[1.10.2]: https://github.com/urfave/cli/compare/v1.10.1...v1.10.2
378
+[1.10.1]: https://github.com/urfave/cli/compare/v1.10.0...v1.10.1
379
+[1.10.0]: https://github.com/urfave/cli/compare/v1.9.0...v1.10.0
380
+[1.9.0]: https://github.com/urfave/cli/compare/v1.8.0...v1.9.0
381
+[1.8.0]: https://github.com/urfave/cli/compare/v1.7.1...v1.8.0
382
+[1.7.1]: https://github.com/urfave/cli/compare/v1.7.0...v1.7.1
383
+[1.7.0]: https://github.com/urfave/cli/compare/v1.6.0...v1.7.0
384
+[1.6.0]: https://github.com/urfave/cli/compare/v1.5.0...v1.6.0
385
+[1.5.0]: https://github.com/urfave/cli/compare/v1.4.1...v1.5.0
386
+[1.4.1]: https://github.com/urfave/cli/compare/v1.4.0...v1.4.1
387
+[1.4.0]: https://github.com/urfave/cli/compare/v1.3.1...v1.4.0
388
+[1.3.1]: https://github.com/urfave/cli/compare/v1.3.0...v1.3.1
389
+[1.3.0]: https://github.com/urfave/cli/compare/v1.2.0...v1.3.0
390
+[1.2.0]: https://github.com/urfave/cli/compare/v1.1.0...v1.2.0
391
+[1.1.0]: https://github.com/urfave/cli/compare/v1.0.0...v1.1.0
392
+[1.0.0]: https://github.com/urfave/cli/compare/v0.1.0...v1.0.0

+ 21
- 0
vendor/gopkg.in/urfave/cli.v1/LICENSE View File

@@ -0,0 +1,21 @@
1
+MIT License
2
+
3
+Copyright (c) 2016 Jeremy Saenz & Contributors
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 1364
- 0
vendor/gopkg.in/urfave/cli.v1/README.md
File diff suppressed because it is too large
View File


+ 492
- 0
vendor/gopkg.in/urfave/cli.v1/app.go View File

@@ -0,0 +1,492 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+	"io"
6
+	"io/ioutil"
7
+	"os"
8
+	"path/filepath"
9
+	"sort"
10
+	"time"
11
+)
12
+
13
+var (
14
+	changeLogURL                    = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
15
+	appActionDeprecationURL         = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
16
+	runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
17
+
18
+	contactSysadmin = "This is an error in the application.  Please contact the distributor of this application if this is not you."
19
+
20
+	errInvalidActionType = NewExitError("ERROR invalid Action type. "+
21
+		fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error).  %s", contactSysadmin)+
22
+		fmt.Sprintf("See %s", appActionDeprecationURL), 2)
23
+)
24
+
25
+// App is the main structure of a cli application. It is recommended that
26
+// an app be created with the cli.NewApp() function
27
+type App struct {
28
+	// The name of the program. Defaults to path.Base(os.Args[0])
29
+	Name string
30
+	// Full name of command for help, defaults to Name
31
+	HelpName string
32
+	// Description of the program.
33
+	Usage string
34
+	// Text to override the USAGE section of help
35
+	UsageText string
36
+	// Description of the program argument format.
37
+	ArgsUsage string
38
+	// Version of the program
39
+	Version string
40
+	// Description of the program
41
+	Description string
42
+	// List of commands to execute
43
+	Commands []Command
44
+	// List of flags to parse
45
+	Flags []Flag
46
+	// Boolean to enable bash completion commands
47
+	EnableBashCompletion bool
48
+	// Boolean to hide built-in help command
49
+	HideHelp bool
50
+	// Boolean to hide built-in version flag and the VERSION section of help
51
+	HideVersion bool
52
+	// Populate on app startup, only gettable through method Categories()
53
+	categories CommandCategories
54
+	// An action to execute when the bash-completion flag is set
55
+	BashComplete BashCompleteFunc
56
+	// An action to execute before any subcommands are run, but after the context is ready
57
+	// If a non-nil error is returned, no subcommands are run
58
+	Before BeforeFunc
59
+	// An action to execute after any subcommands are run, but after the subcommand has finished
60
+	// It is run even if Action() panics
61
+	After AfterFunc
62
+
63
+	// The action to execute when no subcommands are specified
64
+	// Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}`
65
+	// *Note*: support for the deprecated `Action` signature will be removed in a future version
66
+	Action interface{}
67
+
68
+	// Execute this function if the proper command cannot be found
69
+	CommandNotFound CommandNotFoundFunc
70
+	// Execute this function if an usage error occurs
71
+	OnUsageError OnUsageErrorFunc
72
+	// Compilation date
73
+	Compiled time.Time
74
+	// List of all authors who contributed
75
+	Authors []Author
76
+	// Copyright of the binary if any
77
+	Copyright string
78
+	// Name of Author (Note: Use App.Authors, this is deprecated)
79
+	Author string
80
+	// Email of Author (Note: Use App.Authors, this is deprecated)
81
+	Email string
82
+	// Writer writer to write output to
83
+	Writer io.Writer
84
+	// ErrWriter writes error output
85
+	ErrWriter io.Writer
86
+	// Other custom info
87
+	Metadata map[string]interface{}
88
+
89
+	didSetup bool
90
+}
91
+
92
+// Tries to find out when this binary was compiled.
93
+// Returns the current time if it fails to find it.
94
+func compileTime() time.Time {
95
+	info, err := os.Stat(os.Args[0])
96
+	if err != nil {
97
+		return time.Now()
98
+	}
99
+	return info.ModTime()
100
+}
101
+
102
+// NewApp creates a new cli Application with some reasonable defaults for Name,
103
+// Usage, Version and Action.
104
+func NewApp() *App {
105
+	return &App{
106
+		Name:         filepath.Base(os.Args[0]),
107
+		HelpName:     filepath.Base(os.Args[0]),
108
+		Usage:        "A new cli application",
109
+		UsageText:    "",
110
+		Version:      "0.0.0",
111
+		BashComplete: DefaultAppComplete,
112
+		Action:       helpCommand.Action,
113
+		Compiled:     compileTime(),
114
+		Writer:       os.Stdout,
115
+	}
116
+}
117
+
118
+// Setup runs initialization code to ensure all data structures are ready for
119
+// `Run` or inspection prior to `Run`.  It is internally called by `Run`, but
120
+// will return early if setup has already happened.
121
+func (a *App) Setup() {
122
+	if a.didSetup {
123
+		return
124
+	}
125
+
126
+	a.didSetup = true
127
+
128
+	if a.Author != "" || a.Email != "" {
129
+		a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
130
+	}
131
+
132
+	newCmds := []Command{}
133
+	for _, c := range a.Commands {
134
+		if c.HelpName == "" {
135
+			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
136
+		}
137
+		newCmds = append(newCmds, c)
138
+	}
139
+	a.Commands = newCmds
140
+
141
+	if a.Command(helpCommand.Name) == nil && !a.HideHelp {
142
+		a.Commands = append(a.Commands, helpCommand)
143
+		if (HelpFlag != BoolFlag{}) {
144
+			a.appendFlag(HelpFlag)
145
+		}
146
+	}
147
+
148
+	if !a.HideVersion {
149
+		a.appendFlag(VersionFlag)
150
+	}
151
+
152
+	a.categories = CommandCategories{}
153
+	for _, command := range a.Commands {
154
+		a.categories = a.categories.AddCommand(command.Category, command)
155
+	}
156
+	sort.Sort(a.categories)
157
+
158
+	if a.Metadata == nil {
159
+		a.Metadata = make(map[string]interface{})
160
+	}
161
+
162
+	if a.Writer == nil {
163
+		a.Writer = os.Stdout
164
+	}
165
+}
166
+
167
+// Run is the entry point to the cli app. Parses the arguments slice and routes
168
+// to the proper flag/args combination
169
+func (a *App) Run(arguments []string) (err error) {
170
+	a.Setup()
171
+
172
+	// handle the completion flag separately from the flagset since
173
+	// completion could be attempted after a flag, but before its value was put
174
+	// on the command line. this causes the flagset to interpret the completion
175
+	// flag name as the value of the flag before it which is undesirable
176
+	// note that we can only do this because the shell autocomplete function
177
+	// always appends the completion flag at the end of the command
178
+	shellComplete, arguments := checkShellCompleteFlag(a, arguments)
179
+
180
+	// parse flags
181
+	set, err := flagSet(a.Name, a.Flags)
182
+	if err != nil {
183
+		return err
184
+	}
185
+
186
+	set.SetOutput(ioutil.Discard)
187
+	err = set.Parse(arguments[1:])
188
+	nerr := normalizeFlags(a.Flags, set)
189
+	context := NewContext(a, set, nil)
190
+	if nerr != nil {
191
+		fmt.Fprintln(a.Writer, nerr)
192
+		ShowAppHelp(context)
193
+		return nerr
194
+	}
195
+	context.shellComplete = shellComplete
196
+
197
+	if checkCompletions(context) {
198
+		return nil
199
+	}
200
+
201
+	if err != nil {
202
+		if a.OnUsageError != nil {
203
+			err := a.OnUsageError(context, err, false)
204
+			HandleExitCoder(err)
205
+			return err
206
+		}
207
+		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
208
+		ShowAppHelp(context)
209
+		return err
210
+	}
211
+
212
+	if !a.HideHelp && checkHelp(context) {
213
+		ShowAppHelp(context)
214
+		return nil
215
+	}
216
+
217
+	if !a.HideVersion && checkVersion(context) {
218
+		ShowVersion(context)
219
+		return nil
220
+	}
221
+
222
+	if a.After != nil {
223
+		defer func() {
224
+			if afterErr := a.After(context); afterErr != nil {
225
+				if err != nil {
226
+					err = NewMultiError(err, afterErr)
227
+				} else {
228
+					err = afterErr
229
+				}
230
+			}
231
+		}()
232
+	}
233
+
234
+	if a.Before != nil {
235
+		beforeErr := a.Before(context)
236
+		if beforeErr != nil {
237
+			fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
238
+			ShowAppHelp(context)
239
+			HandleExitCoder(beforeErr)
240
+			err = beforeErr
241
+			return err
242
+		}
243
+	}
244
+
245
+	args := context.Args()
246
+	if args.Present() {
247
+		name := args.First()
248
+		c := a.Command(name)
249
+		if c != nil {
250
+			return c.Run(context)
251
+		}
252
+	}
253
+
254
+	if a.Action == nil {
255
+		a.Action = helpCommand.Action
256
+	}
257
+
258
+	// Run default Action
259
+	err = HandleAction(a.Action, context)
260
+
261
+	HandleExitCoder(err)
262
+	return err
263
+}
264
+
265
+// RunAndExitOnError calls .Run() and exits non-zero if an error was returned
266
+//
267
+// Deprecated: instead you should return an error that fulfills cli.ExitCoder
268
+// to cli.App.Run. This will cause the application to exit with the given eror
269
+// code in the cli.ExitCoder
270
+func (a *App) RunAndExitOnError() {
271
+	if err := a.Run(os.Args); err != nil {
272
+		fmt.Fprintln(a.errWriter(), err)
273
+		OsExiter(1)
274
+	}
275
+}
276
+
277
+// RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to
278
+// generate command-specific flags
279
+func (a *App) RunAsSubcommand(ctx *Context) (err error) {
280
+	// append help to commands
281
+	if len(a.Commands) > 0 {
282
+		if a.Command(helpCommand.Name) == nil && !a.HideHelp {
283
+			a.Commands = append(a.Commands, helpCommand)
284
+			if (HelpFlag != BoolFlag{}) {
285
+				a.appendFlag(HelpFlag)
286
+			}
287
+		}
288
+	}
289
+
290
+	newCmds := []Command{}
291
+	for _, c := range a.Commands {
292
+		if c.HelpName == "" {
293
+			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
294
+		}
295
+		newCmds = append(newCmds, c)
296
+	}
297
+	a.Commands = newCmds
298
+
299
+	// parse flags
300
+	set, err := flagSet(a.Name, a.Flags)
301
+	if err != nil {
302
+		return err
303
+	}
304
+
305
+	set.SetOutput(ioutil.Discard)
306
+	err = set.Parse(ctx.Args().Tail())
307
+	nerr := normalizeFlags(a.Flags, set)
308
+	context := NewContext(a, set, ctx)
309
+
310
+	if nerr != nil {
311
+		fmt.Fprintln(a.Writer, nerr)
312
+		fmt.Fprintln(a.Writer)
313
+		if len(a.Commands) > 0 {
314
+			ShowSubcommandHelp(context)
315
+		} else {
316
+			ShowCommandHelp(ctx, context.Args().First())
317
+		}
318
+		return nerr
319
+	}
320
+
321
+	if checkCompletions(context) {
322
+		return nil
323
+	}
324
+
325
+	if err != nil {
326
+		if a.OnUsageError != nil {
327
+			err = a.OnUsageError(context, err, true)
328
+			HandleExitCoder(err)
329
+			return err
330
+		}
331
+		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
332
+		ShowSubcommandHelp(context)
333
+		return err
334
+	}
335
+
336
+	if len(a.Commands) > 0 {
337
+		if checkSubcommandHelp(context) {
338
+			return nil
339
+		}
340
+	} else {
341
+		if checkCommandHelp(ctx, context.Args().First()) {
342
+			return nil
343
+		}
344
+	}
345
+
346
+	if a.After != nil {
347
+		defer func() {
348
+			afterErr := a.After(context)
349
+			if afterErr != nil {
350
+				HandleExitCoder(err)
351
+				if err != nil {
352
+					err = NewMultiError(err, afterErr)
353
+				} else {
354
+					err = afterErr
355
+				}
356
+			}
357
+		}()
358
+	}
359
+
360
+	if a.Before != nil {
361
+		beforeErr := a.Before(context)
362
+		if beforeErr != nil {
363
+			HandleExitCoder(beforeErr)
364
+			err = beforeErr
365
+			return err
366
+		}
367
+	}
368
+
369
+	args := context.Args()
370
+	if args.Present() {
371
+		name := args.First()
372
+		c := a.Command(name)
373
+		if c != nil {
374
+			return c.Run(context)
375
+		}
376
+	}
377
+
378
+	// Run default Action
379
+	err = HandleAction(a.Action, context)
380
+
381
+	HandleExitCoder(err)
382
+	return err
383
+}
384
+
385
+// Command returns the named command on App. Returns nil if the command does not exist
386
+func (a *App) Command(name string) *Command {
387
+	for _, c := range a.Commands {
388
+		if c.HasName(name) {
389
+			return &c
390
+		}
391
+	}
392
+
393
+	return nil
394
+}
395
+
396
+// Categories returns a slice containing all the categories with the commands they contain
397
+func (a *App) Categories() CommandCategories {
398
+	return a.categories
399
+}
400
+
401
+// VisibleCategories returns a slice of categories and commands that are
402
+// Hidden=false
403
+func (a *App) VisibleCategories() []*CommandCategory {
404
+	ret := []*CommandCategory{}
405
+	for _, category := range a.categories {
406
+		if visible := func() *CommandCategory {
407
+			for _, command := range category.Commands {
408
+				if !command.Hidden {
409
+					return category
410
+				}
411
+			}
412
+			return nil
413
+		}(); visible != nil {
414
+			ret = append(ret, visible)
415
+		}
416
+	}
417
+	return ret
418
+}
419
+
420
+// VisibleCommands returns a slice of the Commands with Hidden=false
421
+func (a *App) VisibleCommands() []Command {
422
+	ret := []Command{}
423
+	for _, command := range a.Commands {
424
+		if !command.Hidden {
425
+			ret = append(ret, command)
426
+		}
427
+	}
428
+	return ret
429
+}
430
+
431
+// VisibleFlags returns a slice of the Flags with Hidden=false
432
+func (a *App) VisibleFlags() []Flag {
433
+	return visibleFlags(a.Flags)
434
+}
435
+
436
+func (a *App) hasFlag(flag Flag) bool {
437
+	for _, f := range a.Flags {
438
+		if flag == f {
439
+			return true
440
+		}
441
+	}
442
+
443
+	return false
444
+}
445
+
446
+func (a *App) errWriter() io.Writer {
447
+
448
+	// When the app ErrWriter is nil use the package level one.
449
+	if a.ErrWriter == nil {
450
+		return ErrWriter
451
+	}
452
+
453
+	return a.ErrWriter
454
+}
455
+
456
+func (a *App) appendFlag(flag Flag) {
457
+	if !a.hasFlag(flag) {
458
+		a.Flags = append(a.Flags, flag)
459
+	}
460
+}
461
+
462
+// Author represents someone who has contributed to a cli project.
463
+type Author struct {
464
+	Name  string // The Authors name
465
+	Email string // The Authors email
466
+}
467
+
468
+// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
469
+func (a Author) String() string {
470
+	e := ""
471
+	if a.Email != "" {
472
+		e = " <" + a.Email + ">"
473
+	}
474
+
475
+	return fmt.Sprintf("%v%v", a.Name, e)
476
+}
477
+
478
+// HandleAction attempts to figure out which Action signature was used.  If
479
+// it's an ActionFunc or a func with the legacy signature for Action, the func
480
+// is run!
481
+func HandleAction(action interface{}, context *Context) (err error) {
482
+	if a, ok := action.(ActionFunc); ok {
483
+		return a(context)
484
+	} else if a, ok := action.(func(*Context) error); ok {
485
+		return a(context)
486
+	} else if a, ok := action.(func(*Context)); ok { // deprecated function signature
487
+		a(context)
488
+		return nil
489
+	} else {
490
+		return errInvalidActionType
491
+	}
492
+}

+ 24
- 0
vendor/gopkg.in/urfave/cli.v1/appveyor.yml View File

@@ -0,0 +1,24 @@
1
+version: "{build}"
2
+
3
+os: Windows Server 2012 R2
4
+
5
+clone_folder: c:\gopath\src\github.com\urfave\cli
6
+
7
+environment:
8
+  GOPATH: C:\gopath
9
+  GOVERSION: 1.6
10
+  PYTHON: C:\Python27-x64
11
+  PYTHON_VERSION: 2.7.x
12
+  PYTHON_ARCH: 64
13
+
14
+install:
15
+- set PATH=%GOPATH%\bin;C:\go\bin;%PATH%
16
+- go version
17
+- go env
18
+- go get github.com/urfave/gfmrun/...
19
+- go get -v -t ./...
20
+
21
+build_script:
22
+- python runtests vet
23
+- python runtests test
24
+- python runtests gfmrun

+ 44
- 0
vendor/gopkg.in/urfave/cli.v1/category.go View File

@@ -0,0 +1,44 @@
1
+package cli
2
+
3
+// CommandCategories is a slice of *CommandCategory.
4
+type CommandCategories []*CommandCategory
5
+
6
+// CommandCategory is a category containing commands.
7
+type CommandCategory struct {
8
+	Name     string
9
+	Commands Commands
10
+}
11
+
12
+func (c CommandCategories) Less(i, j int) bool {
13
+	return c[i].Name < c[j].Name
14
+}
15
+
16
+func (c CommandCategories) Len() int {
17
+	return len(c)
18
+}
19
+
20
+func (c CommandCategories) Swap(i, j int) {
21
+	c[i], c[j] = c[j], c[i]
22
+}
23
+
24
+// AddCommand adds a command to a category.
25
+func (c CommandCategories) AddCommand(category string, command Command) CommandCategories {
26
+	for _, commandCategory := range c {
27
+		if commandCategory.Name == category {
28
+			commandCategory.Commands = append(commandCategory.Commands, command)
29
+			return c
30
+		}
31
+	}
32
+	return append(c, &CommandCategory{Name: category, Commands: []Command{command}})
33
+}
34
+
35
+// VisibleCommands returns a slice of the Commands with Hidden=false
36
+func (c *CommandCategory) VisibleCommands() []Command {
37
+	ret := []Command{}
38
+	for _, command := range c.Commands {
39
+		if !command.Hidden {
40
+			ret = append(ret, command)
41
+		}
42
+	}
43
+	return ret
44
+}

+ 21
- 0
vendor/gopkg.in/urfave/cli.v1/cli.go View File

@@ -0,0 +1,21 @@
1
+// Package cli provides a minimal framework for creating and organizing command line
2
+// Go applications. cli is designed to be easy to understand and write, the most simple
3
+// cli application can be written as follows:
4
+//   func main() {
5
+//     cli.NewApp().Run(os.Args)
6
+//   }
7
+//
8
+// Of course this application does not do much, so let's make this an actual application:
9
+//   func main() {
10
+//     app := cli.NewApp()
11
+//     app.Name = "greet"
12
+//     app.Usage = "say a greeting"
13
+//     app.Action = func(c *cli.Context) error {
14
+//       println("Greetings")
15
+//     }
16
+//
17
+//     app.Run(os.Args)
18
+//   }
19
+package cli
20
+
21
+//go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go

+ 286
- 0
vendor/gopkg.in/urfave/cli.v1/command.go View File

@@ -0,0 +1,286 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+	"io/ioutil"
6
+	"sort"
7
+	"strings"
8
+)
9
+
10
+// Command is a subcommand for a cli.App.
11
+type Command struct {
12
+	// The name of the command
13
+	Name string
14
+	// short name of the command. Typically one character (deprecated, use `Aliases`)
15
+	ShortName string
16
+	// A list of aliases for the command
17
+	Aliases []string
18
+	// A short description of the usage of this command
19
+	Usage string
20
+	// Custom text to show on USAGE section of help
21
+	UsageText string
22
+	// A longer explanation of how the command works
23
+	Description string
24
+	// A short description of the arguments of this command
25
+	ArgsUsage string
26
+	// The category the command is part of
27
+	Category string
28
+	// The function to call when checking for bash command completions
29
+	BashComplete BashCompleteFunc
30
+	// An action to execute before any sub-subcommands are run, but after the context is ready
31
+	// If a non-nil error is returned, no sub-subcommands are run
32
+	Before BeforeFunc
33
+	// An action to execute after any subcommands are run, but after the subcommand has finished
34
+	// It is run even if Action() panics
35
+	After AfterFunc
36
+	// The function to call when this command is invoked
37
+	Action interface{}
38
+	// TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind
39
+	// of deprecation period has passed, maybe?
40
+
41
+	// Execute this function if a usage error occurs.
42
+	OnUsageError OnUsageErrorFunc
43
+	// List of child commands
44
+	Subcommands Commands
45
+	// List of flags to parse
46
+	Flags []Flag
47
+	// Treat all flags as normal arguments if true
48
+	SkipFlagParsing bool
49
+	// Skip argument reordering which attempts to move flags before arguments,
50
+	// but only works if all flags appear after all arguments. This behavior was
51
+	// removed n version 2 since it only works under specific conditions so we
52
+	// backport here by exposing it as an option for compatibility.
53
+	SkipArgReorder bool
54
+	// Boolean to hide built-in help command
55
+	HideHelp bool
56
+	// Boolean to hide this command from help or completion
57
+	Hidden bool
58
+
59
+	// Full name of command for help, defaults to full command name, including parent commands.
60
+	HelpName        string
61
+	commandNamePath []string
62
+}
63
+
64
+// FullName returns the full name of the command.
65
+// For subcommands this ensures that parent commands are part of the command path
66
+func (c Command) FullName() string {
67
+	if c.commandNamePath == nil {
68
+		return c.Name
69
+	}
70
+	return strings.Join(c.commandNamePath, " ")
71
+}
72
+
73
+// Commands is a slice of Command
74
+type Commands []Command
75
+
76
+// Run invokes the command given the context, parses ctx.Args() to generate command-specific flags
77
+func (c Command) Run(ctx *Context) (err error) {
78
+	if len(c.Subcommands) > 0 {
79
+		return c.startApp(ctx)
80
+	}
81
+
82
+	if !c.HideHelp && (HelpFlag != BoolFlag{}) {
83
+		// append help to flags
84
+		c.Flags = append(
85
+			c.Flags,
86
+			HelpFlag,
87
+		)
88
+	}
89
+
90
+	set, err := flagSet(c.Name, c.Flags)
91
+	if err != nil {
92
+		return err
93
+	}
94
+	set.SetOutput(ioutil.Discard)
95
+
96
+	if c.SkipFlagParsing {
97
+		err = set.Parse(append([]string{"--"}, ctx.Args().Tail()...))
98
+	} else if !c.SkipArgReorder {
99
+		firstFlagIndex := -1
100
+		terminatorIndex := -1
101
+		for index, arg := range ctx.Args() {
102
+			if arg == "--" {
103
+				terminatorIndex = index
104
+				break
105
+			} else if arg == "-" {
106
+				// Do nothing. A dash alone is not really a flag.
107
+				continue
108
+			} else if strings.HasPrefix(arg, "-") && firstFlagIndex == -1 {
109
+				firstFlagIndex = index
110
+			}
111
+		}
112
+
113
+		if firstFlagIndex > -1 {
114
+			args := ctx.Args()
115
+			regularArgs := make([]string, len(args[1:firstFlagIndex]))
116
+			copy(regularArgs, args[1:firstFlagIndex])
117
+
118
+			var flagArgs []string
119
+			if terminatorIndex > -1 {
120
+				flagArgs = args[firstFlagIndex:terminatorIndex]
121
+				regularArgs = append(regularArgs, args[terminatorIndex:]...)
122
+			} else {
123
+				flagArgs = args[firstFlagIndex:]
124
+			}
125
+
126
+			err = set.Parse(append(flagArgs, regularArgs...))
127
+		} else {
128
+			err = set.Parse(ctx.Args().Tail())
129
+		}
130
+	} else {
131
+		err = set.Parse(ctx.Args().Tail())
132
+	}
133
+
134
+	nerr := normalizeFlags(c.Flags, set)
135
+	if nerr != nil {
136
+		fmt.Fprintln(ctx.App.Writer, nerr)
137
+		fmt.Fprintln(ctx.App.Writer)
138
+		ShowCommandHelp(ctx, c.Name)
139
+		return nerr
140
+	}
141
+
142
+	context := NewContext(ctx.App, set, ctx)
143
+	if checkCommandCompletions(context, c.Name) {
144
+		return nil
145
+	}
146
+
147
+	if err != nil {
148
+		if c.OnUsageError != nil {
149
+			err := c.OnUsageError(ctx, err, false)
150
+			HandleExitCoder(err)
151
+			return err
152
+		}
153
+		fmt.Fprintln(ctx.App.Writer, "Incorrect Usage:", err.Error())
154
+		fmt.Fprintln(ctx.App.Writer)
155
+		ShowCommandHelp(ctx, c.Name)
156
+		return err
157
+	}
158
+
159
+	if checkCommandHelp(context, c.Name) {
160
+		return nil
161
+	}
162
+
163
+	if c.After != nil {
164
+		defer func() {
165
+			afterErr := c.After(context)
166
+			if afterErr != nil {
167
+				HandleExitCoder(err)
168
+				if err != nil {
169
+					err = NewMultiError(err, afterErr)
170
+				} else {
171
+					err = afterErr
172
+				}
173
+			}
174
+		}()
175
+	}
176
+
177
+	if c.Before != nil {
178
+		err = c.Before(context)
179
+		if err != nil {
180
+			fmt.Fprintln(ctx.App.Writer, err)
181
+			fmt.Fprintln(ctx.App.Writer)
182
+			ShowCommandHelp(ctx, c.Name)
183
+			HandleExitCoder(err)
184
+			return err
185
+		}
186
+	}
187
+
188
+	if c.Action == nil {
189
+		c.Action = helpSubcommand.Action
190
+	}
191
+
192
+	context.Command = c
193
+	err = HandleAction(c.Action, context)
194
+
195
+	if err != nil {
196
+		HandleExitCoder(err)
197
+	}
198
+	return err
199
+}
200
+
201
+// Names returns the names including short names and aliases.
202
+func (c Command) Names() []string {
203
+	names := []string{c.Name}
204
+
205
+	if c.ShortName != "" {
206
+		names = append(names, c.ShortName)
207
+	}
208
+
209
+	return append(names, c.Aliases...)
210
+}
211
+
212
+// HasName returns true if Command.Name or Command.ShortName matches given name
213
+func (c Command) HasName(name string) bool {
214
+	for _, n := range c.Names() {
215
+		if n == name {
216
+			return true
217
+		}
218
+	}
219
+	return false
220
+}
221
+
222
+func (c Command) startApp(ctx *Context) error {
223
+	app := NewApp()
224
+	app.Metadata = ctx.App.Metadata
225
+	// set the name and usage
226
+	app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name)
227
+	if c.HelpName == "" {
228
+		app.HelpName = c.HelpName
229
+	} else {
230
+		app.HelpName = app.Name
231
+	}
232
+
233
+	if c.Description != "" {
234
+		app.Usage = c.Description
235
+	} else {
236
+		app.Usage = c.Usage
237
+	}
238
+
239
+	// set CommandNotFound
240
+	app.CommandNotFound = ctx.App.CommandNotFound
241
+
242
+	// set the flags and commands
243
+	app.Commands = c.Subcommands
244
+	app.Flags = c.Flags
245
+	app.HideHelp = c.HideHelp
246
+
247
+	app.Version = ctx.App.Version
248
+	app.HideVersion = ctx.App.HideVersion
249
+	app.Compiled = ctx.App.Compiled
250
+	app.Author = ctx.App.Author
251
+	app.Email = ctx.App.Email
252
+	app.Writer = ctx.App.Writer
253
+
254
+	app.categories = CommandCategories{}
255
+	for _, command := range c.Subcommands {
256
+		app.categories = app.categories.AddCommand(command.Category, command)
257
+	}
258
+
259
+	sort.Sort(app.categories)
260
+
261
+	// bash completion
262
+	app.EnableBashCompletion = ctx.App.EnableBashCompletion
263
+	if c.BashComplete != nil {
264
+		app.BashComplete = c.BashComplete
265
+	}
266
+
267
+	// set the actions
268
+	app.Before = c.Before
269
+	app.After = c.After
270
+	if c.Action != nil {
271
+		app.Action = c.Action
272
+	} else {
273
+		app.Action = helpSubcommand.Action
274
+	}
275
+
276
+	for index, cc := range app.Commands {
277
+		app.Commands[index].commandNamePath = []string{c.Name, cc.Name}
278
+	}
279
+
280
+	return app.RunAsSubcommand(ctx)
281
+}
282
+
283
+// VisibleFlags returns a slice of the Flags with Hidden=false
284
+func (c Command) VisibleFlags() []Flag {
285
+	return visibleFlags(c.Flags)
286
+}

+ 276
- 0
vendor/gopkg.in/urfave/cli.v1/context.go View File

@@ -0,0 +1,276 @@
1
+package cli
2
+
3
+import (
4
+	"errors"
5
+	"flag"
6
+	"reflect"
7
+	"strings"
8
+	"syscall"
9
+)
10
+
11
+// Context is a type that is passed through to
12
+// each Handler action in a cli application. Context
13
+// can be used to retrieve context-specific Args and
14
+// parsed command-line options.
15
+type Context struct {
16
+	App           *App
17
+	Command       Command
18
+	shellComplete bool
19
+	flagSet       *flag.FlagSet
20
+	setFlags      map[string]bool
21
+	parentContext *Context
22
+}
23
+
24
+// NewContext creates a new context. For use in when invoking an App or Command action.
25
+func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context {
26
+	c := &Context{App: app, flagSet: set, parentContext: parentCtx}
27
+
28
+	if parentCtx != nil {
29
+		c.shellComplete = parentCtx.shellComplete
30
+	}
31
+
32
+	return c
33
+}
34
+
35
+// NumFlags returns the number of flags set
36
+func (c *Context) NumFlags() int {
37
+	return c.flagSet.NFlag()
38
+}
39
+
40
+// Set sets a context flag to a value.
41
+func (c *Context) Set(name, value string) error {
42
+	return c.flagSet.Set(name, value)
43
+}
44
+
45
+// GlobalSet sets a context flag to a value on the global flagset
46
+func (c *Context) GlobalSet(name, value string) error {
47
+	return globalContext(c).flagSet.Set(name, value)
48
+}
49
+
50
+// IsSet determines if the flag was actually set
51
+func (c *Context) IsSet(name string) bool {
52
+	if c.setFlags == nil {
53
+		c.setFlags = make(map[string]bool)
54
+
55
+		c.flagSet.Visit(func(f *flag.Flag) {
56
+			c.setFlags[f.Name] = true
57
+		})
58
+
59
+		c.flagSet.VisitAll(func(f *flag.Flag) {
60
+			if _, ok := c.setFlags[f.Name]; ok {
61
+				return
62
+			}
63
+			c.setFlags[f.Name] = false
64
+		})
65
+
66
+		// XXX hack to support IsSet for flags with EnvVar
67
+		//
68
+		// There isn't an easy way to do this with the current implementation since
69
+		// whether a flag was set via an environment variable is very difficult to
70
+		// determine here. Instead, we intend to introduce a backwards incompatible
71
+		// change in version 2 to add `IsSet` to the Flag interface to push the
72
+		// responsibility closer to where the information required to determine
73
+		// whether a flag is set by non-standard means such as environment
74
+		// variables is avaliable.
75
+		//
76
+		// See https://github.com/urfave/cli/issues/294 for additional discussion
77
+		flags := c.Command.Flags
78
+		if c.Command.Name == "" { // cannot == Command{} since it contains slice types
79
+			if c.App != nil {
80
+				flags = c.App.Flags
81
+			}
82
+		}
83
+		for _, f := range flags {
84
+			eachName(f.GetName(), func(name string) {
85
+				if isSet, ok := c.setFlags[name]; isSet || !ok {
86
+					return
87
+				}
88
+
89
+				val := reflect.ValueOf(f)
90
+				if val.Kind() == reflect.Ptr {
91
+					val = val.Elem()
92
+				}
93
+
94
+				envVarValue := val.FieldByName("EnvVar")
95
+				if !envVarValue.IsValid() {
96
+					return
97
+				}
98
+
99
+				eachName(envVarValue.String(), func(envVar string) {
100
+					envVar = strings.TrimSpace(envVar)
101
+					if _, ok := syscall.Getenv(envVar); ok {
102
+						c.setFlags[name] = true
103
+						return
104
+					}
105
+				})
106
+			})
107
+		}
108
+	}
109
+
110
+	return c.setFlags[name]
111
+}
112
+
113
+// GlobalIsSet determines if the global flag was actually set
114
+func (c *Context) GlobalIsSet(name string) bool {
115
+	ctx := c
116
+	if ctx.parentContext != nil {
117
+		ctx = ctx.parentContext
118
+	}
119
+
120
+	for ; ctx != nil; ctx = ctx.parentContext {
121
+		if ctx.IsSet(name) {
122
+			return true
123
+		}
124
+	}
125
+	return false
126
+}
127
+
128
+// FlagNames returns a slice of flag names used in this context.
129
+func (c *Context) FlagNames() (names []string) {
130
+	for _, flag := range c.Command.Flags {
131
+		name := strings.Split(flag.GetName(), ",")[0]
132
+		if name == "help" {
133
+			continue
134
+		}
135
+		names = append(names, name)
136
+	}
137
+	return
138
+}
139
+
140
+// GlobalFlagNames returns a slice of global flag names used by the app.
141
+func (c *Context) GlobalFlagNames() (names []string) {
142
+	for _, flag := range c.App.Flags {
143
+		name := strings.Split(flag.GetName(), ",")[0]
144
+		if name == "help" || name == "version" {
145
+			continue
146
+		}
147
+		names = append(names, name)
148
+	}
149
+	return
150
+}
151
+
152
+// Parent returns the parent context, if any
153
+func (c *Context) Parent() *Context {
154
+	return c.parentContext
155
+}
156
+
157
+// value returns the value of the flag coressponding to `name`
158
+func (c *Context) value(name string) interface{} {
159
+	return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
160
+}
161
+
162
+// Args contains apps console arguments
163
+type Args []string
164
+
165
+// Args returns the command line arguments associated with the context.
166
+func (c *Context) Args() Args {
167
+	args := Args(c.flagSet.Args())
168
+	return args
169
+}
170
+
171
+// NArg returns the number of the command line arguments.
172
+func (c *Context) NArg() int {
173
+	return len(c.Args())
174
+}
175
+
176
+// Get returns the nth argument, or else a blank string
177
+func (a Args) Get(n int) string {
178
+	if len(a) > n {
179
+		return a[n]
180
+	}
181
+	return ""
182
+}
183
+
184
+// First returns the first argument, or else a blank string
185
+func (a Args) First() string {
186
+	return a.Get(0)
187
+}
188
+
189
+// Tail returns the rest of the arguments (not the first one)
190
+// or else an empty string slice
191
+func (a Args) Tail() []string {
192
+	if len(a) >= 2 {
193
+		return []string(a)[1:]
194
+	}
195
+	return []string{}
196
+}
197
+
198
+// Present checks if there are any arguments present
199
+func (a Args) Present() bool {
200
+	return len(a) != 0
201
+}
202
+
203
+// Swap swaps arguments at the given indexes
204
+func (a Args) Swap(from, to int) error {
205
+	if from >= len(a) || to >= len(a) {
206
+		return errors.New("index out of range")
207
+	}
208
+	a[from], a[to] = a[to], a[from]
209
+	return nil
210
+}
211
+
212
+func globalContext(ctx *Context) *Context {
213
+	if ctx == nil {
214
+		return nil
215
+	}
216
+
217
+	for {
218
+		if ctx.parentContext == nil {
219
+			return ctx
220
+		}
221
+		ctx = ctx.parentContext
222
+	}
223
+}
224
+
225
+func lookupGlobalFlagSet(name string, ctx *Context) *flag.FlagSet {
226
+	if ctx.parentContext != nil {
227
+		ctx = ctx.parentContext
228
+	}
229
+	for ; ctx != nil; ctx = ctx.parentContext {
230
+		if f := ctx.flagSet.Lookup(name); f != nil {
231
+			return ctx.flagSet
232
+		}
233
+	}
234
+	return nil
235
+}
236
+
237
+func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) {
238
+	switch ff.Value.(type) {
239
+	case *StringSlice:
240
+	default:
241
+		set.Set(name, ff.Value.String())
242
+	}
243
+}
244
+
245
+func normalizeFlags(flags []Flag, set *flag.FlagSet) error {
246
+	visited := make(map[string]bool)
247
+	set.Visit(func(f *flag.Flag) {
248
+		visited[f.Name] = true
249
+	})
250
+	for _, f := range flags {
251
+		parts := strings.Split(f.GetName(), ",")
252
+		if len(parts) == 1 {
253
+			continue
254
+		}
255
+		var ff *flag.Flag
256
+		for _, name := range parts {
257
+			name = strings.Trim(name, " ")
258
+			if visited[name] {
259
+				if ff != nil {
260
+					return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name)
261
+				}
262
+				ff = set.Lookup(name)
263
+			}
264
+		}
265
+		if ff == nil {
266
+			continue
267
+		}
268
+		for _, name := range parts {
269
+			name = strings.Trim(name, " ")
270
+			if !visited[name] {
271
+				copyFlag(name, ff, set)
272
+			}
273
+		}
274
+	}
275
+	return nil
276
+}

+ 110
- 0
vendor/gopkg.in/urfave/cli.v1/errors.go View File

@@ -0,0 +1,110 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+	"io"
6
+	"os"
7
+	"strings"
8
+)
9
+
10
+// OsExiter is the function used when the app exits. If not set defaults to os.Exit.
11
+var OsExiter = os.Exit
12
+
13
+// ErrWriter is used to write errors to the user. This can be anything
14
+// implementing the io.Writer interface and defaults to os.Stderr.
15
+var ErrWriter io.Writer = os.Stderr
16
+
17
+// MultiError is an error that wraps multiple errors.
18
+type MultiError struct {
19
+	Errors []error
20
+}
21
+
22
+// NewMultiError creates a new MultiError. Pass in one or more errors.
23
+func NewMultiError(err ...error) MultiError {
24
+	return MultiError{Errors: err}
25
+}
26
+
27
+// Error implements the error interface.
28
+func (m MultiError) Error() string {
29
+	errs := make([]string, len(m.Errors))
30
+	for i, err := range m.Errors {
31
+		errs[i] = err.Error()
32
+	}
33
+
34
+	return strings.Join(errs, "\n")
35
+}
36
+
37
+type ErrorFormatter interface {
38
+	Format(s fmt.State, verb rune)
39
+}
40
+
41
+// ExitCoder is the interface checked by `App` and `Command` for a custom exit
42
+// code
43
+type ExitCoder interface {
44
+	error
45
+	ExitCode() int
46
+}
47
+
48
+// ExitError fulfills both the builtin `error` interface and `ExitCoder`
49
+type ExitError struct {
50
+	exitCode int
51
+	message  interface{}
52
+}
53
+
54
+// NewExitError makes a new *ExitError
55
+func NewExitError(message interface{}, exitCode int) *ExitError {
56
+	return &ExitError{
57
+		exitCode: exitCode,
58
+		message:  message,
59
+	}
60
+}
61
+
62
+// Error returns the string message, fulfilling the interface required by
63
+// `error`
64
+func (ee *ExitError) Error() string {
65
+	return fmt.Sprintf("%v", ee.message)
66
+}
67
+
68
+// ExitCode returns the exit code, fulfilling the interface required by
69
+// `ExitCoder`
70
+func (ee *ExitError) ExitCode() int {
71
+	return ee.exitCode
72
+}
73
+
74
+// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if
75
+// so prints the error to stderr (if it is non-empty) and calls OsExiter with the
76
+// given exit code.  If the given error is a MultiError, then this func is
77
+// called on all members of the Errors slice.
78
+func HandleExitCoder(err error) {
79
+	if err == nil {
80
+		return
81
+	}
82
+
83
+	if exitErr, ok := err.(ExitCoder); ok {
84
+		if err.Error() != "" {
85
+			if _, ok := exitErr.(ErrorFormatter); ok {
86
+				fmt.Fprintf(ErrWriter, "%+v\n", err)
87
+			} else {
88
+				fmt.Fprintln(ErrWriter, err)
89
+			}
90
+		}
91
+		OsExiter(exitErr.ExitCode())
92
+		return
93
+	}
94
+
95
+	if multiErr, ok := err.(MultiError); ok {
96
+		for _, merr := range multiErr.Errors {
97
+			HandleExitCoder(merr)
98
+		}
99
+		return
100
+	}
101
+
102
+	if err.Error() != "" {
103
+		if _, ok := err.(ErrorFormatter); ok {
104
+			fmt.Fprintf(ErrWriter, "%+v\n", err)
105
+		} else {
106
+			fmt.Fprintln(ErrWriter, err)
107
+		}
108
+	}
109
+	OsExiter(1)
110
+}

+ 93
- 0
vendor/gopkg.in/urfave/cli.v1/flag-types.json View File

@@ -0,0 +1,93 @@
1
+[
2
+  {
3
+    "name": "Bool",
4
+    "type": "bool",
5
+    "value": false,
6
+    "context_default": "false",
7
+    "parser": "strconv.ParseBool(f.Value.String())"
8
+  },
9
+  {
10
+    "name": "BoolT",
11
+    "type": "bool",
12
+    "value": false,
13
+    "doctail": " that is true by default",
14
+    "context_default": "false",
15
+    "parser": "strconv.ParseBool(f.Value.String())"
16
+  },
17
+  {
18
+    "name": "Duration",
19
+    "type": "time.Duration",
20
+    "doctail": " (see https://golang.org/pkg/time/#ParseDuration)",
21
+    "context_default": "0",
22
+    "parser": "time.ParseDuration(f.Value.String())"
23
+  },
24
+  {
25
+    "name": "Float64",
26
+    "type": "float64",
27
+    "context_default": "0",
28
+    "parser": "strconv.ParseFloat(f.Value.String(), 64)"
29
+  },
30
+  {
31
+    "name": "Generic",
32
+    "type": "Generic",
33
+    "dest": false,
34
+    "context_default": "nil",
35
+    "context_type": "interface{}"
36
+  },
37
+  {
38
+    "name": "Int64",
39
+    "type": "int64",
40
+    "context_default": "0",
41
+    "parser": "strconv.ParseInt(f.Value.String(), 0, 64)"
42
+  },
43
+  {
44
+    "name": "Int",
45
+    "type": "int",
46
+    "context_default": "0",
47
+    "parser": "strconv.ParseInt(f.Value.String(), 0, 64)",
48
+    "parser_cast": "int(parsed)"
49
+  },
50
+  {
51
+    "name": "IntSlice",
52
+    "type": "*IntSlice",
53
+    "dest": false,
54
+    "context_default": "nil",
55
+    "context_type": "[]int",
56
+    "parser": "(f.Value.(*IntSlice)).Value(), error(nil)"
57
+  },
58
+  {
59
+    "name": "Int64Slice",
60
+    "type": "*Int64Slice",
61
+    "dest": false,
62
+    "context_default": "nil",
63
+    "context_type": "[]int64",
64
+    "parser": "(f.Value.(*Int64Slice)).Value(), error(nil)"
65
+  },
66
+  {
67
+    "name": "String",
68
+    "type": "string",
69
+    "context_default": "\"\"",
70
+    "parser": "f.Value.String(), error(nil)"
71
+  },
72
+  {
73
+    "name": "StringSlice",
74
+    "type": "*StringSlice",
75
+    "dest": false,
76
+    "context_default": "nil",
77
+    "context_type": "[]string",
78
+    "parser": "(f.Value.(*StringSlice)).Value(), error(nil)"
79
+  },
80
+  {
81
+    "name": "Uint64",
82
+    "type": "uint64",
83
+    "context_default": "0",
84
+    "parser": "strconv.ParseUint(f.Value.String(), 0, 64)"
85
+  },
86
+  {
87
+    "name": "Uint",
88
+    "type": "uint",
89
+    "context_default": "0",
90
+    "parser": "strconv.ParseUint(f.Value.String(), 0, 64)",
91
+    "parser_cast": "uint(parsed)"
92
+  }
93
+]

+ 799
- 0
vendor/gopkg.in/urfave/cli.v1/flag.go View File

@@ -0,0 +1,799 @@
1
+package cli
2
+
3
+import (
4
+	"flag"
5
+	"fmt"
6
+	"reflect"
7
+	"runtime"
8
+	"strconv"
9
+	"strings"
10
+	"syscall"
11
+	"time"
12
+)
13
+
14
+const defaultPlaceholder = "value"
15
+
16
+// BashCompletionFlag enables bash-completion for all commands and subcommands
17
+var BashCompletionFlag = BoolFlag{
18
+	Name:   "generate-bash-completion",
19
+	Hidden: true,
20
+}
21
+
22
+// VersionFlag prints the version for the application
23
+var VersionFlag = BoolFlag{
24
+	Name:  "version, v",
25
+	Usage: "print the version",
26
+}
27
+
28
+// HelpFlag prints the help for all commands and subcommands
29
+// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand
30
+// unless HideHelp is set to true)
31
+var HelpFlag = BoolFlag{
32
+	Name:  "help, h",
33
+	Usage: "show help",
34
+}
35
+
36
+// FlagStringer converts a flag definition to a string. This is used by help
37
+// to display a flag.
38
+var FlagStringer FlagStringFunc = stringifyFlag
39
+
40
+// FlagsByName is a slice of Flag.
41
+type FlagsByName []Flag
42
+
43
+func (f FlagsByName) Len() int {
44
+	return len(f)
45
+}
46
+
47
+func (f FlagsByName) Less(i, j int) bool {
48
+	return f[i].GetName() < f[j].GetName()
49
+}
50
+
51
+func (f FlagsByName) Swap(i, j int) {
52
+	f[i], f[j] = f[j], f[i]
53
+}
54
+
55
+// Flag is a common interface related to parsing flags in cli.
56
+// For more advanced flag parsing techniques, it is recommended that
57
+// this interface be implemented.
58
+type Flag interface {
59
+	fmt.Stringer
60
+	// Apply Flag settings to the given flag set
61
+	Apply(*flag.FlagSet)
62
+	GetName() string
63
+}
64
+
65
+// errorableFlag is an interface that allows us to return errors during apply
66
+// it allows flags defined in this library to return errors in a fashion backwards compatible
67
+// TODO remove in v2 and modify the existing Flag interface to return errors
68
+type errorableFlag interface {
69
+	Flag
70
+
71
+	ApplyWithError(*flag.FlagSet) error
72
+}
73
+
74
+func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
75
+	set := flag.NewFlagSet(name, flag.ContinueOnError)
76
+
77
+	for _, f := range flags {
78
+		//TODO remove in v2 when errorableFlag is removed
79
+		if ef, ok := f.(errorableFlag); ok {
80
+			if err := ef.ApplyWithError(set); err != nil {
81
+				return nil, err
82
+			}
83
+		} else {
84
+			f.Apply(set)
85
+		}
86
+	}
87
+	return set, nil
88
+}
89
+
90
+func eachName(longName string, fn func(string)) {
91
+	parts := strings.Split(longName, ",")
92
+	for _, name := range parts {
93
+		name = strings.Trim(name, " ")
94
+		fn(name)
95
+	}
96
+}
97
+
98
+// Generic is a generic parseable type identified by a specific flag
99
+type Generic interface {
100
+	Set(value string) error
101
+	String() string
102
+}
103
+
104
+// Apply takes the flagset and calls Set on the generic flag with the value
105
+// provided by the user for parsing by the flag
106
+// Ignores parsing errors
107
+func (f GenericFlag) Apply(set *flag.FlagSet) {
108
+	f.ApplyWithError(set)
109
+}
110
+
111
+// ApplyWithError takes the flagset and calls Set on the generic flag with the value
112
+// provided by the user for parsing by the flag
113
+func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error {
114
+	val := f.Value
115
+	if f.EnvVar != "" {
116
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
117
+			envVar = strings.TrimSpace(envVar)
118
+			if envVal, ok := syscall.Getenv(envVar); ok {
119
+				if err := val.Set(envVal); err != nil {
120
+					return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err)
121
+				}
122
+				break
123
+			}
124
+		}
125
+	}
126
+
127
+	eachName(f.Name, func(name string) {
128
+		set.Var(f.Value, name, f.Usage)
129
+	})
130
+
131
+	return nil
132
+}
133
+
134
+// StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter
135
+type StringSlice []string
136
+
137
+// Set appends the string value to the list of values
138
+func (f *StringSlice) Set(value string) error {
139
+	*f = append(*f, value)
140
+	return nil
141
+}
142
+
143
+// String returns a readable representation of this value (for usage defaults)
144
+func (f *StringSlice) String() string {
145
+	return fmt.Sprintf("%s", *f)
146
+}
147
+
148
+// Value returns the slice of strings set by this flag
149
+func (f *StringSlice) Value() []string {
150
+	return *f
151
+}
152
+
153
+// Get returns the slice of strings set by this flag
154
+func (f *StringSlice) Get() interface{} {
155
+	return *f
156
+}
157
+
158
+// Apply populates the flag given the flag set and environment
159
+// Ignores errors
160
+func (f StringSliceFlag) Apply(set *flag.FlagSet) {
161
+	f.ApplyWithError(set)
162
+}
163
+
164
+// ApplyWithError populates the flag given the flag set and environment
165
+func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error {
166
+	if f.EnvVar != "" {
167
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
168
+			envVar = strings.TrimSpace(envVar)
169
+			if envVal, ok := syscall.Getenv(envVar); ok {
170
+				newVal := &StringSlice{}
171
+				for _, s := range strings.Split(envVal, ",") {
172
+					s = strings.TrimSpace(s)
173
+					if err := newVal.Set(s); err != nil {
174
+						return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err)
175
+					}
176
+				}
177
+				f.Value = newVal
178
+				break
179
+			}
180
+		}
181
+	}
182
+
183
+	eachName(f.Name, func(name string) {
184
+		if f.Value == nil {
185
+			f.Value = &StringSlice{}
186
+		}
187
+		set.Var(f.Value, name, f.Usage)
188
+	})
189
+
190
+	return nil
191
+}
192
+
193
+// IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter
194
+type IntSlice []int
195
+
196
+// Set parses the value into an integer and appends it to the list of values
197
+func (f *IntSlice) Set(value string) error {
198
+	tmp, err := strconv.Atoi(value)
199
+	if err != nil {
200
+		return err
201
+	}
202
+	*f = append(*f, tmp)
203
+	return nil
204
+}
205
+
206
+// String returns a readable representation of this value (for usage defaults)
207
+func (f *IntSlice) String() string {
208
+	return fmt.Sprintf("%#v", *f)
209
+}
210
+
211
+// Value returns the slice of ints set by this flag
212
+func (f *IntSlice) Value() []int {
213
+	return *f
214
+}
215
+
216
+// Get returns the slice of ints set by this flag
217
+func (f *IntSlice) Get() interface{} {
218
+	return *f
219
+}
220
+
221
+// Apply populates the flag given the flag set and environment
222
+// Ignores errors
223
+func (f IntSliceFlag) Apply(set *flag.FlagSet) {
224
+	f.ApplyWithError(set)
225
+}
226
+
227
+// ApplyWithError populates the flag given the flag set and environment
228
+func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error {
229
+	if f.EnvVar != "" {
230
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
231
+			envVar = strings.TrimSpace(envVar)
232
+			if envVal, ok := syscall.Getenv(envVar); ok {
233
+				newVal := &IntSlice{}
234
+				for _, s := range strings.Split(envVal, ",") {
235
+					s = strings.TrimSpace(s)
236
+					if err := newVal.Set(s); err != nil {
237
+						return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err)
238
+					}
239
+				}
240
+				f.Value = newVal
241
+				break
242
+			}
243
+		}
244
+	}
245
+
246
+	eachName(f.Name, func(name string) {
247
+		if f.Value == nil {
248
+			f.Value = &IntSlice{}
249
+		}
250
+		set.Var(f.Value, name, f.Usage)
251
+	})
252
+
253
+	return nil
254
+}
255
+
256
+// Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter
257
+type Int64Slice []int64
258
+
259
+// Set parses the value into an integer and appends it to the list of values
260
+func (f *Int64Slice) Set(value string) error {
261
+	tmp, err := strconv.ParseInt(value, 10, 64)
262
+	if err != nil {
263
+		return err
264
+	}
265
+	*f = append(*f, tmp)
266
+	return nil
267
+}
268
+
269
+// String returns a readable representation of this value (for usage defaults)
270
+func (f *Int64Slice) String() string {
271
+	return fmt.Sprintf("%#v", *f)
272
+}
273
+
274
+// Value returns the slice of ints set by this flag
275
+func (f *Int64Slice) Value() []int64 {
276
+	return *f
277
+}
278
+
279
+// Get returns the slice of ints set by this flag
280
+func (f *Int64Slice) Get() interface{} {
281
+	return *f
282
+}
283
+
284
+// Apply populates the flag given the flag set and environment
285
+// Ignores errors
286
+func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
287
+	f.ApplyWithError(set)
288
+}
289
+
290
+// ApplyWithError populates the flag given the flag set and environment
291
+func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
292
+	if f.EnvVar != "" {
293
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
294
+			envVar = strings.TrimSpace(envVar)
295
+			if envVal, ok := syscall.Getenv(envVar); ok {
296
+				newVal := &Int64Slice{}
297
+				for _, s := range strings.Split(envVal, ",") {
298
+					s = strings.TrimSpace(s)
299
+					if err := newVal.Set(s); err != nil {
300
+						return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err)
301
+					}
302
+				}
303
+				f.Value = newVal
304
+				break
305
+			}
306
+		}
307
+	}
308
+
309
+	eachName(f.Name, func(name string) {
310
+		if f.Value == nil {
311
+			f.Value = &Int64Slice{}
312
+		}
313
+		set.Var(f.Value, name, f.Usage)
314
+	})
315
+	return nil
316
+}
317
+
318
+// Apply populates the flag given the flag set and environment
319
+// Ignores errors
320
+func (f BoolFlag) Apply(set *flag.FlagSet) {
321
+	f.ApplyWithError(set)
322
+}
323
+
324
+// ApplyWithError populates the flag given the flag set and environment
325
+func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
326
+	val := false
327
+	if f.EnvVar != "" {
328
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
329
+			envVar = strings.TrimSpace(envVar)
330
+			if envVal, ok := syscall.Getenv(envVar); ok {
331
+				if envVal == "" {
332
+					val = false
333
+					break
334
+				}
335
+
336
+				envValBool, err := strconv.ParseBool(envVal)
337
+				if err != nil {
338
+					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
339
+				}
340
+
341
+				val = envValBool
342
+				break
343
+			}
344
+		}
345
+	}
346
+
347
+	eachName(f.Name, func(name string) {
348
+		if f.Destination != nil {
349
+			set.BoolVar(f.Destination, name, val, f.Usage)
350
+			return
351
+		}
352
+		set.Bool(name, val, f.Usage)
353
+	})
354
+
355
+	return nil
356
+}
357
+
358
+// Apply populates the flag given the flag set and environment
359
+// Ignores errors
360
+func (f BoolTFlag) Apply(set *flag.FlagSet) {
361
+	f.ApplyWithError(set)
362
+}
363
+
364
+// ApplyWithError populates the flag given the flag set and environment
365
+func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
366
+	val := true
367
+	if f.EnvVar != "" {
368
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
369
+			envVar = strings.TrimSpace(envVar)
370
+			if envVal, ok := syscall.Getenv(envVar); ok {
371
+				if envVal == "" {
372
+					val = false
373
+					break
374
+				}
375
+
376
+				envValBool, err := strconv.ParseBool(envVal)
377
+				if err != nil {
378
+					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
379
+				}
380
+
381
+				val = envValBool
382
+				break
383
+			}
384
+		}
385
+	}
386
+
387
+	eachName(f.Name, func(name string) {
388
+		if f.Destination != nil {
389
+			set.BoolVar(f.Destination, name, val, f.Usage)
390
+			return
391
+		}
392
+		set.Bool(name, val, f.Usage)
393
+	})
394
+
395
+	return nil
396
+}
397
+
398
+// Apply populates the flag given the flag set and environment
399
+// Ignores errors
400
+func (f StringFlag) Apply(set *flag.FlagSet) {
401
+	f.ApplyWithError(set)
402
+}
403
+
404
+// ApplyWithError populates the flag given the flag set and environment
405
+func (f StringFlag) ApplyWithError(set *flag.FlagSet) error {
406
+	if f.EnvVar != "" {
407
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
408
+			envVar = strings.TrimSpace(envVar)
409
+			if envVal, ok := syscall.Getenv(envVar); ok {
410
+				f.Value = envVal
411
+				break
412
+			}
413
+		}
414
+	}
415
+
416
+	eachName(f.Name, func(name string) {
417
+		if f.Destination != nil {
418
+			set.StringVar(f.Destination, name, f.Value, f.Usage)
419
+			return
420
+		}
421
+		set.String(name, f.Value, f.Usage)
422
+	})
423
+
424
+	return nil
425
+}
426
+
427
+// Apply populates the flag given the flag set and environment
428
+// Ignores errors
429
+func (f IntFlag) Apply(set *flag.FlagSet) {
430
+	f.ApplyWithError(set)
431
+}
432
+
433
+// ApplyWithError populates the flag given the flag set and environment
434
+func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
435
+	if f.EnvVar != "" {
436
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
437
+			envVar = strings.TrimSpace(envVar)
438
+			if envVal, ok := syscall.Getenv(envVar); ok {
439
+				envValInt, err := strconv.ParseInt(envVal, 0, 64)
440
+				if err != nil {
441
+					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
442
+				}
443
+				f.Value = int(envValInt)
444
+				break
445
+			}
446
+		}
447
+	}
448
+
449
+	eachName(f.Name, func(name string) {
450
+		if f.Destination != nil {
451
+			set.IntVar(f.Destination, name, f.Value, f.Usage)
452
+			return
453
+		}
454
+		set.Int(name, f.Value, f.Usage)
455
+	})
456
+
457
+	return nil
458
+}
459
+
460
+// Apply populates the flag given the flag set and environment
461
+// Ignores errors
462
+func (f Int64Flag) Apply(set *flag.FlagSet) {
463
+	f.ApplyWithError(set)
464
+}
465
+
466
+// ApplyWithError populates the flag given the flag set and environment
467
+func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
468
+	if f.EnvVar != "" {
469
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
470
+			envVar = strings.TrimSpace(envVar)
471
+			if envVal, ok := syscall.Getenv(envVar); ok {
472
+				envValInt, err := strconv.ParseInt(envVal, 0, 64)
473
+				if err != nil {
474
+					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
475
+				}
476
+
477
+				f.Value = envValInt
478
+				break
479
+			}
480
+		}
481
+	}
482
+
483
+	eachName(f.Name, func(name string) {
484
+		if f.Destination != nil {
485
+			set.Int64Var(f.Destination, name, f.Value, f.Usage)
486
+			return
487
+		}
488
+		set.Int64(name, f.Value, f.Usage)
489
+	})
490
+
491
+	return nil
492
+}
493
+
494
+// Apply populates the flag given the flag set and environment
495
+// Ignores errors
496
+func (f UintFlag) Apply(set *flag.FlagSet) {
497
+	f.ApplyWithError(set)
498
+}
499
+
500
+// ApplyWithError populates the flag given the flag set and environment
501
+func (f UintFlag) ApplyWithError(set *flag.FlagSet) error {
502
+	if f.EnvVar != "" {
503
+		for _, envVar := range strings.Split(f.EnvVar, ",") {
504
+			envVar = strings.TrimSpace(envVar)
505
+			if envVal, ok := syscall.Getenv(envVar); ok {
506
+				envValInt, err := strconv.ParseUint(envVal, 0, 64)
507
+				if err != nil {