commander-openflighthpc 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -62
- data/lib/commander/command.rb +0 -9
- data/lib/commander/error_handler.rb +1 -1
- data/lib/commander/help_formatters/terminal/command_help.erb +9 -7
- data/lib/commander/help_formatters/terminal/help.erb +9 -7
- data/lib/commander/runner.rb +10 -14
- data/lib/commander/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b5727f3d10b876b81b223b19fcac47a56cf293a66b34305b96517976b04613
|
4
|
+
data.tar.gz: e047187d76098db98d240770dca013806512628ad1dcd54c613dc2627a7538d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e8f5850885c9bf9540b82b7a7866fdb9a317c32c94501e51cef85d65711fe5037ffc7924f68c206ff4654e2f998ae237e5fbb36b9495f9619aaba3d95418a4
|
7
|
+
data.tar.gz: a6840ebf11d96c875e45a468ce492e2c748f20c3298121bc338b2f565d9b8f8c3dff6d278340d609f69ca98f8c0e8b52af3e40a4b93385d99dbc5fc4ae2c3c1c
|
data/README.md
CHANGED
@@ -43,39 +43,37 @@ features, and an elegant API.
|
|
43
43
|
|
44
44
|
## Example
|
45
45
|
|
46
|
-
For more option examples view the `Commander::Command#option` method. Also
|
47
|
-
an important feature to note is that action may be a class to instantiate,
|
48
|
-
as well as an object, specifying a method to call, so view the RDoc for more information.
|
49
|
-
|
50
|
-
### Classic style
|
51
|
-
|
52
46
|
```ruby
|
53
47
|
require 'rubygems'
|
54
|
-
require 'commander
|
48
|
+
require 'commander'
|
55
49
|
|
50
|
+
class MyApplication
|
56
51
|
# :name is optional, otherwise uses the basename of this executable
|
57
|
-
program :name, 'Foo Bar'
|
58
|
-
program :version, '1.0.0'
|
59
|
-
program :description, 'Stupid command that prints foo or bar.'
|
60
|
-
|
61
|
-
command :foo do |c|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
program :name, 'Foo Bar'
|
53
|
+
program :version, '1.0.0'
|
54
|
+
program :description, 'Stupid command that prints foo or bar.'
|
55
|
+
|
56
|
+
command :foo do |c|
|
57
|
+
c.syntax = 'foobar foo'
|
58
|
+
c.description = 'Displays foo'
|
59
|
+
c.action do |args, options|
|
60
|
+
say 'foo'
|
61
|
+
end
|
66
62
|
end
|
67
|
-
end
|
68
63
|
|
69
|
-
command :bar do |c|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
command :bar do |c|
|
65
|
+
c.syntax = 'foobar bar [options]'
|
66
|
+
c.description = 'Display bar with optional prefix and suffix'
|
67
|
+
c.slop.string '--prefix', 'Adds a prefix to bar'
|
68
|
+
c.slop.string '--suffix', 'Adds a suffix to bar', meta: 'CUSTOM_META'
|
69
|
+
c.action do |args, options, config|
|
70
|
+
options.default :prefix => '(', :suffix => ')'
|
71
|
+
say "#{options.prefix}bar#{options.suffix}"
|
72
|
+
end
|
77
73
|
end
|
78
74
|
end
|
75
|
+
|
76
|
+
MyApplication.run!(ARGV) if $0 == __FILE__
|
79
77
|
```
|
80
78
|
|
81
79
|
Example output:
|
@@ -88,49 +86,27 @@ $ foobar bar --suffix '}' --prefix '{'
|
|
88
86
|
# => {bar}
|
89
87
|
```
|
90
88
|
|
91
|
-
|
89
|
+
## Commander Goodies
|
92
90
|
|
93
|
-
|
91
|
+
### Option Parsing
|
94
92
|
|
95
|
-
|
96
|
-
require 'rubygems'
|
97
|
-
require 'commander'
|
98
|
-
|
99
|
-
class MyApplication
|
100
|
-
extend Commander::CLI
|
93
|
+
Option parsing is done using [Simple Lightweight Option Parsing](https://github.com/leejarvis/slop) which provides a rich interface for different option types. The main three being:
|
101
94
|
|
102
|
-
program :name, 'Foo Bar'
|
103
|
-
program :version, '1.0.0'
|
104
|
-
program :description, 'Stupid command that prints foo or bar.'
|
105
|
-
|
106
|
-
command :foo do |c|
|
107
|
-
c.syntax = 'foobar foo'
|
108
|
-
c.description = 'Displays foo'
|
109
|
-
c.action do |args, options|
|
110
|
-
say 'foo'
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
MyApplication.run!(ARGV) if $0 == __FILE__
|
116
95
|
```
|
96
|
+
command do |c|
|
97
|
+
# Boolean Flag
|
98
|
+
c.slop.bool '--boolean-flag', 'Sets the :boolean_flag option to true'
|
117
99
|
|
118
|
-
|
100
|
+
# String Value
|
101
|
+
c.slop.string '--string-value', 'Takes a string from the command line'
|
102
|
+
c.slop.string '--flag', 'Sets the meta variable to META', meta: 'META'
|
119
103
|
|
120
|
-
|
104
|
+
# Interger Value
|
105
|
+
c.slop.integer '--integer-value', 'Takes the input and type casts it to an integer'
|
121
106
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
```ruby
|
126
|
-
command :foo do |c|
|
127
|
-
c.option '--interval SECONDS', 'Interval in seconds'
|
128
|
-
c.option '--timeout SECONDS', 'Timeout in seconds'
|
129
|
-
c.action do |args, options|
|
130
|
-
options.default \
|
131
|
-
:interval => 2,
|
132
|
-
:timeout => 60
|
133
|
-
end
|
107
|
+
# Legacy syntax (boolean and string values only)
|
108
|
+
c.option '--legacy-bool', 'A boolean flag using the legacy syntax'
|
109
|
+
c.option '--legacy-string LEGACY_STRING', 'A string flag using the legacy syntax'
|
134
110
|
end
|
135
111
|
```
|
136
112
|
|
@@ -221,7 +197,18 @@ Which will output the rest of the help doc, along with:
|
|
221
197
|
|
222
198
|
### Global Options
|
223
199
|
|
224
|
-
|
200
|
+
Global options work in a similar way to command level options. They both are configured using `Slop`. Global options are available on all commands. They are configure on the `global_slop` directive.
|
201
|
+
|
202
|
+
```
|
203
|
+
class MyApplication
|
204
|
+
program :name, 'Foo Bar'
|
205
|
+
|
206
|
+
...
|
207
|
+
|
208
|
+
global_slop.string '--custom-global', 'Available on all commands'
|
209
|
+
end
|
210
|
+
|
211
|
+
```
|
225
212
|
|
226
213
|
### Tracing
|
227
214
|
|
data/lib/commander/command.rb
CHANGED
@@ -103,15 +103,6 @@ module Commander
|
|
103
103
|
end
|
104
104
|
alias action when_called
|
105
105
|
|
106
|
-
##
|
107
|
-
# Causes the option parsing to be skipped. The flags will be passed
|
108
|
-
# down within the args instead
|
109
|
-
#
|
110
|
-
|
111
|
-
def skip_option_parsing(set = true)
|
112
|
-
@skip_option_parsing ||= set
|
113
|
-
end
|
114
|
-
|
115
106
|
##
|
116
107
|
# Flags the command not to appear in general help text
|
117
108
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Commander
|
2
2
|
##
|
3
3
|
# Internal error class to delay rendering help text
|
4
|
-
# This is required as the help command
|
4
|
+
# This is required as the help command points directly to stdout
|
5
5
|
# In general this has a bit of a code smell to it, and should
|
6
6
|
# not be used publicly
|
7
7
|
class InternalCallableError < StandardError
|
@@ -27,13 +27,15 @@
|
|
27
27
|
<%= $terminal.color "OPTIONS", :bold %>:
|
28
28
|
<% slop.options.each do |option| -%>
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
<% tag = if [Slop::BoolOption, Slop::NullOption].include?(option.class)
|
31
|
+
nil
|
32
|
+
elsif meta = option.config[:meta]
|
33
|
+
meta
|
34
|
+
else
|
35
|
+
option.key.upcase
|
36
|
+
end
|
37
|
+
-%>
|
38
|
+
<%= option.flags.join ', ' %> <%= tag %>
|
37
39
|
<%= Commander::HelpFormatter.indent 8, option.desc %><% if option.default_value %>
|
38
40
|
<%= $terminal.color "Default", :bold %>: <%= option.default_value %><% end %>
|
39
41
|
<% end -%>
|
@@ -32,14 +32,16 @@
|
|
32
32
|
<%= $terminal.color "GLOBAL OPTIONS", :bold %>:
|
33
33
|
<% global_slop.options.each do |global| -%>
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
<% tag = if [Slop::BoolOption, Slop::NullOption]
|
36
|
+
nil
|
37
|
+
elsif meta = option.config[:meta]
|
38
|
+
meta
|
39
|
+
else
|
40
|
+
option.key.upcase
|
41
|
+
end
|
42
|
+
-%>
|
41
43
|
<%= global.flags.join ', ' %> <%= tag %>
|
42
|
-
<%= global.desc %>
|
44
|
+
<%= Commander::HelpFormatter.indent 8, global.desc %>
|
43
45
|
<% end -%>
|
44
46
|
<% end -%>
|
45
47
|
<% if program :help -%>
|
data/lib/commander/runner.rb
CHANGED
@@ -65,21 +65,17 @@ module Commander
|
|
65
65
|
args_without_command_name
|
66
66
|
end
|
67
67
|
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
# Format the config and opts
|
68
|
+
# Combines the global and command options into a single parser
|
69
|
+
global_opts = global_slop.options
|
70
|
+
command_opts = active_command? ? active_command.slop.options : []
|
71
|
+
opts = [*global_opts, *command_opts]
|
72
|
+
parser = Slop::Parser.new(opts)
|
73
|
+
|
74
|
+
# Parsers the arguments/opts and fetches the config
|
75
|
+
parser.parse(remaining_args)
|
76
|
+
opts = OpenStruct.new parser.parse(remaining_args).to_h
|
77
|
+
remaining_args = parser.arguments
|
81
78
|
config = program(:config).dup
|
82
|
-
opts = OpenStruct.new global_opts.to_h.merge(local_opts.to_h)
|
83
79
|
|
84
80
|
if opts.version
|
85
81
|
# Return the version
|
data/lib/commander/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commander-openflighthpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alces Flight Ltd
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-05-
|
13
|
+
date: 2020-05-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|