commander-openflighthpc 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -87
- data/commander-openflighthpc.gemspec +1 -0
- data/lib/commander.rb +3 -4
- data/lib/commander/cli.rb +15 -76
- data/lib/commander/command.rb +89 -175
- data/lib/commander/error_handler.rb +72 -0
- data/lib/commander/help_formatters.rb +0 -4
- data/lib/commander/help_formatters/terminal.rb +0 -5
- data/lib/commander/help_formatters/terminal/command_help.erb +12 -6
- data/lib/commander/help_formatters/terminal/help.erb +10 -4
- data/lib/commander/runner.rb +98 -129
- data/lib/commander/version.rb +1 -1
- metadata +19 -44
- data/bin/commander +0 -104
- data/lib/commander/blank.rb +0 -7
- data/lib/commander/core_ext.rb +0 -2
- data/lib/commander/core_ext/array.rb +0 -24
- data/lib/commander/core_ext/object.rb +0 -8
- data/lib/commander/help_formatters/terminal/subcommand_help.erb +0 -23
- data/lib/commander/help_formatters/terminal_compact.rb +0 -11
- data/lib/commander/help_formatters/terminal_compact/command_help.erb +0 -26
- data/lib/commander/help_formatters/terminal_compact/help.erb +0 -29
- data/lib/commander/help_formatters/terminal_compact/subcommand_help.erb +0 -15
- data/lib/commander/import.rb +0 -5
- data/lib/commander/patches/decimal-integer.rb +0 -17
- data/lib/commander/patches/help_formatter_binding.rb +0 -15
- data/lib/commander/patches/implicit-short-tags.rb +0 -75
- data/lib/commander/patches/priority_sort.rb +0 -21
- data/lib/commander/patches/validate_inputs.rb +0 -79
- data/lib/commander/platform.rb +0 -7
- data/spec/command_spec.rb +0 -157
- data/spec/configure_spec.rb +0 -37
- data/spec/core_ext/array_spec.rb +0 -18
- data/spec/core_ext/object_spec.rb +0 -19
- data/spec/help_formatters/terminal_compact_spec.rb +0 -69
- data/spec/help_formatters/terminal_spec.rb +0 -67
- data/spec/methods_spec.rb +0 -61
- data/spec/patches/validate_inputs_spec.rb +0 -84
- data/spec/runner_spec.rb +0 -672
- data/spec/spec_helper.rb +0 -79
- data/spec/ui_spec.rb +0 -30
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.0
|
4
|
+
version: 2.1.0
|
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-
|
13
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - ">"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 1.7.2
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: slop
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '4.8'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '4.8'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: paint
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,8 +115,7 @@ description: The complete solution for Ruby command-line executables. Commander
|
|
101
115
|
HighLine), while providing many new features, and an elegant API.
|
102
116
|
email:
|
103
117
|
- flight@openflighthpc.org
|
104
|
-
executables:
|
105
|
-
- commander
|
118
|
+
executables: []
|
106
119
|
extensions: []
|
107
120
|
extra_rdoc_files: []
|
108
121
|
files:
|
@@ -117,45 +130,18 @@ files:
|
|
117
130
|
- Manifest
|
118
131
|
- README.md
|
119
132
|
- Rakefile
|
120
|
-
- bin/commander
|
121
133
|
- commander-openflighthpc.gemspec
|
122
134
|
- lib/commander.rb
|
123
|
-
- lib/commander/blank.rb
|
124
135
|
- lib/commander/cli.rb
|
125
136
|
- lib/commander/command.rb
|
126
|
-
- lib/commander/
|
127
|
-
- lib/commander/core_ext/array.rb
|
128
|
-
- lib/commander/core_ext/object.rb
|
137
|
+
- lib/commander/error_handler.rb
|
129
138
|
- lib/commander/help_formatters.rb
|
130
139
|
- lib/commander/help_formatters/base.rb
|
131
140
|
- lib/commander/help_formatters/terminal.rb
|
132
141
|
- lib/commander/help_formatters/terminal/command_help.erb
|
133
142
|
- lib/commander/help_formatters/terminal/help.erb
|
134
|
-
- lib/commander/help_formatters/terminal/subcommand_help.erb
|
135
|
-
- lib/commander/help_formatters/terminal_compact.rb
|
136
|
-
- lib/commander/help_formatters/terminal_compact/command_help.erb
|
137
|
-
- lib/commander/help_formatters/terminal_compact/help.erb
|
138
|
-
- lib/commander/help_formatters/terminal_compact/subcommand_help.erb
|
139
|
-
- lib/commander/import.rb
|
140
|
-
- lib/commander/patches/decimal-integer.rb
|
141
|
-
- lib/commander/patches/help_formatter_binding.rb
|
142
|
-
- lib/commander/patches/implicit-short-tags.rb
|
143
|
-
- lib/commander/patches/priority_sort.rb
|
144
|
-
- lib/commander/patches/validate_inputs.rb
|
145
|
-
- lib/commander/platform.rb
|
146
143
|
- lib/commander/runner.rb
|
147
144
|
- lib/commander/version.rb
|
148
|
-
- spec/command_spec.rb
|
149
|
-
- spec/configure_spec.rb
|
150
|
-
- spec/core_ext/array_spec.rb
|
151
|
-
- spec/core_ext/object_spec.rb
|
152
|
-
- spec/help_formatters/terminal_compact_spec.rb
|
153
|
-
- spec/help_formatters/terminal_spec.rb
|
154
|
-
- spec/methods_spec.rb
|
155
|
-
- spec/patches/validate_inputs_spec.rb
|
156
|
-
- spec/runner_spec.rb
|
157
|
-
- spec/spec_helper.rb
|
158
|
-
- spec/ui_spec.rb
|
159
145
|
homepage: https://github.com/openflighthpc/commander-openflighthpc
|
160
146
|
licenses:
|
161
147
|
- MIT
|
@@ -179,15 +165,4 @@ rubygems_version: 3.0.3
|
|
179
165
|
signing_key:
|
180
166
|
specification_version: 4
|
181
167
|
summary: The complete solution for Ruby command-line executables
|
182
|
-
test_files:
|
183
|
-
- spec/command_spec.rb
|
184
|
-
- spec/configure_spec.rb
|
185
|
-
- spec/core_ext/array_spec.rb
|
186
|
-
- spec/core_ext/object_spec.rb
|
187
|
-
- spec/help_formatters/terminal_compact_spec.rb
|
188
|
-
- spec/help_formatters/terminal_spec.rb
|
189
|
-
- spec/methods_spec.rb
|
190
|
-
- spec/patches/validate_inputs_spec.rb
|
191
|
-
- spec/runner_spec.rb
|
192
|
-
- spec/spec_helper.rb
|
193
|
-
- spec/ui_spec.rb
|
168
|
+
test_files: []
|
data/bin/commander
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'commander/import'
|
5
|
-
|
6
|
-
program :name, 'commander'
|
7
|
-
program :version, Commander::VERSION
|
8
|
-
program :description, 'Commander utility program.'
|
9
|
-
|
10
|
-
command :init do |c|
|
11
|
-
c.syntax = 'commander init [option] <file>'
|
12
|
-
c.summary = 'Initialize a commander template'
|
13
|
-
c.description = 'Initialize an empty <file> with a commander template,
|
14
|
-
allowing very quick creation of commander executables.'
|
15
|
-
c.example 'Create a new classic style template file.', 'commander init bin/my_executable'
|
16
|
-
c.example 'Create a new modular style template file.', 'commander init --modular bin/my_executable'
|
17
|
-
c.option '-m', '--modular', 'Initialize a modular style template'
|
18
|
-
c.action do |args, options|
|
19
|
-
file = args.shift || abort('file argument required.')
|
20
|
-
name = ask 'Machine name of program: '
|
21
|
-
description = ask 'Describe your program: '
|
22
|
-
commands = ask_for_array 'List the commands you wish to create: '
|
23
|
-
begin
|
24
|
-
if options.modular
|
25
|
-
File.open(file, 'w') do |f|
|
26
|
-
f.write <<-"...".gsub!(/^ {10}/, '')
|
27
|
-
#!/usr/bin/env ruby
|
28
|
-
|
29
|
-
require 'rubygems'
|
30
|
-
require 'commander'
|
31
|
-
|
32
|
-
class MyApplication
|
33
|
-
include Commander::Methods
|
34
|
-
# include whatever modules you need
|
35
|
-
|
36
|
-
def run
|
37
|
-
program :name, '#{name}'
|
38
|
-
program :version, '0.0.1'
|
39
|
-
program :description, '#{description}'
|
40
|
-
|
41
|
-
...
|
42
|
-
commands.each do |command|
|
43
|
-
f.write <<-"...".gsub!(/^ {12}/, '')
|
44
|
-
command :#{command} do |c|
|
45
|
-
c.syntax = '#{name} #{command} [options]'
|
46
|
-
c.summary = ''
|
47
|
-
c.description = ''
|
48
|
-
c.example 'description', 'command example'
|
49
|
-
c.option '--some-switch', 'Some switch that does something'
|
50
|
-
c.action do |args, options|
|
51
|
-
# Do something or c.when_called #{name.capitalize}::Commands::#{command.capitalize}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
...
|
56
|
-
end
|
57
|
-
f.write <<-"...".gsub!(/^ {12}/, '')
|
58
|
-
run!
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
MyApplication.new.run if $0 == __FILE__
|
63
|
-
...
|
64
|
-
end
|
65
|
-
|
66
|
-
File.chmod(0755, file)
|
67
|
-
say "Initialized modular template in #{file}"
|
68
|
-
else
|
69
|
-
File.open(file, 'w') do |f|
|
70
|
-
f.write <<-"...".gsub!(/^ {10}/, '')
|
71
|
-
#!/usr/bin/env ruby
|
72
|
-
|
73
|
-
require 'rubygems'
|
74
|
-
require 'commander/import'
|
75
|
-
|
76
|
-
program :name, '#{name}'
|
77
|
-
program :version, '0.0.1'
|
78
|
-
program :description, '#{description}'
|
79
|
-
|
80
|
-
...
|
81
|
-
commands.each do |command|
|
82
|
-
f.write <<-"...".gsub!(/^ {12}/, '')
|
83
|
-
command :#{command} do |c|
|
84
|
-
c.syntax = '#{name} #{command} [options]'
|
85
|
-
c.summary = ''
|
86
|
-
c.description = ''
|
87
|
-
c.example 'description', 'command example'
|
88
|
-
c.option '--some-switch', 'Some switch that does something'
|
89
|
-
c.action do |args, options|
|
90
|
-
# Do something or c.when_called #{name.capitalize}::Commands::#{command.capitalize}
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
...
|
95
|
-
end
|
96
|
-
end
|
97
|
-
File.chmod 0755, file
|
98
|
-
say "Initialized template in #{file}"
|
99
|
-
end
|
100
|
-
rescue => e
|
101
|
-
abort e
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/commander/blank.rb
DELETED
data/lib/commander/core_ext.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
##
|
3
|
-
# Split _string_ into an array. Used in
|
4
|
-
# conjunction with Highline's #ask, or #ask_for_array
|
5
|
-
# methods, which must respond to #parse.
|
6
|
-
#
|
7
|
-
# This method allows escaping of whitespace. For example
|
8
|
-
# the arguments foo bar\ baz will become ['foo', 'bar baz']
|
9
|
-
#
|
10
|
-
# === Example
|
11
|
-
#
|
12
|
-
# # ask invokes Array#parse
|
13
|
-
# list = ask 'Favorite cookies:', Array
|
14
|
-
#
|
15
|
-
# # or use ask_for_CLASS
|
16
|
-
# list = ask_for_array 'Favorite cookies: '
|
17
|
-
#
|
18
|
-
|
19
|
-
def self.parse(string)
|
20
|
-
# Using reverse + lookahead to work around Ruby 1.8's lack of lookbehind
|
21
|
-
# TODO: simplify now that we don't support Ruby 1.8
|
22
|
-
string.reverse.split(/\s(?!\\)/).reverse.map { |s| s.reverse.gsub('\\ ', ' ') }
|
23
|
-
end
|
24
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
<% if !cmd.syntax %>
|
2
|
-
<%= $terminal.color "NAME", :bold %>:
|
3
|
-
|
4
|
-
<%= cmd.name %>
|
5
|
-
<% else -%>
|
6
|
-
<%= $terminal.color "SYNOPSIS", :bold %>:
|
7
|
-
|
8
|
-
<%= cmd.syntax -%>
|
9
|
-
|
10
|
-
<% end -%>
|
11
|
-
|
12
|
-
<%= $terminal.color "DESCRIPTION", :bold %>:
|
13
|
-
|
14
|
-
<%= Commander::HelpFormatter.indent 4, (cmd.description || cmd.summary || 'No description.') -%>
|
15
|
-
|
16
|
-
|
17
|
-
<%= $terminal.color "SUBCOMMANDS", :bold %>:
|
18
|
-
<% @commands.values.sort.map { |c| [c.name, c] }.each do |name, command| -%>
|
19
|
-
<% unless alias? name %>
|
20
|
-
<%= "%-#{max_command_length}s %s" % [command.name, command.summary || command.description] -%>
|
21
|
-
<% end -%>
|
22
|
-
<% end %>
|
23
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<%= @name %>
|
2
|
-
<% if @syntax -%>
|
3
|
-
|
4
|
-
Usage: <%= @syntax %>
|
5
|
-
<% end -%>
|
6
|
-
<% if @description || @summary -%>
|
7
|
-
|
8
|
-
<%= @description || @summary %>
|
9
|
-
<% end -%>
|
10
|
-
<% unless @examples.empty? -%>
|
11
|
-
|
12
|
-
Examples:
|
13
|
-
<% for description, command in @examples -%>
|
14
|
-
|
15
|
-
# <%= description %>
|
16
|
-
<%= command %>
|
17
|
-
<% end -%>
|
18
|
-
<% end -%>
|
19
|
-
<% unless @options.empty? -%>
|
20
|
-
|
21
|
-
Options:
|
22
|
-
<% for option in @options -%>
|
23
|
-
<%= "%-20s %s" % [option[:switches].join(', '), option[:description]] %><% if option[:default] %> <%= option[:default] %><% end %>
|
24
|
-
<% end -%>
|
25
|
-
<% end -%>
|
26
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<%= program :name %>
|
2
|
-
|
3
|
-
<%= program :description %>
|
4
|
-
|
5
|
-
Commands:
|
6
|
-
<% for name, command in @help_commands.sort -%>
|
7
|
-
<% unless alias? name -%>
|
8
|
-
<%= "%-#{max_command_length}s %s" % [command.name, command.summary || command.description] %>
|
9
|
-
<% end -%>
|
10
|
-
<% end -%>
|
11
|
-
<% unless @aliases.empty? %>
|
12
|
-
Aliases:
|
13
|
-
<% for alias_name, args in @aliases.sort -%>
|
14
|
-
<%= "%-#{max_aliases_length}s %s %s" % [alias_name, command(alias_name).name, args.join(' ')] %>
|
15
|
-
<% end -%>
|
16
|
-
<% end %>
|
17
|
-
<% unless @help_options.empty? -%>
|
18
|
-
Global Options:
|
19
|
-
<% for option in @help_options -%>
|
20
|
-
<%= "%-20s %s" % [option[:switches].join(', '), option[:description]] -%>
|
21
|
-
<% end -%>
|
22
|
-
<% end -%>
|
23
|
-
<% if program :help -%>
|
24
|
-
<% for title, body in program(:help) %>
|
25
|
-
<%= title %>:
|
26
|
-
<%= body %>
|
27
|
-
<% end %>
|
28
|
-
<% end -%>
|
29
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<%= cmd.name %>
|
2
|
-
<% if cmd.syntax -%>
|
3
|
-
|
4
|
-
Usage: <%= cmd.syntax %>
|
5
|
-
<% end -%>
|
6
|
-
<% if cmd.description || cmd.summary -%>
|
7
|
-
|
8
|
-
<%= cmd.description || cmd.summary %>
|
9
|
-
<% end -%>
|
10
|
-
|
11
|
-
<% @commands.values.sort.map { |c| [c.name, c] }.each do |name, command| -%>
|
12
|
-
<% unless alias? name -%>
|
13
|
-
<%= "%-#{max_command_length}s %s" % [command.name, command.summary || command.description] %>
|
14
|
-
<% end -%>
|
15
|
-
<% end -%>
|
data/lib/commander/import.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# Patches the underling OptionParser DecimalInteger type so that it doesn't
|
2
|
-
# convert numbers starting with a '0' as if they are an Octal number
|
3
|
-
module Commander
|
4
|
-
module Patches
|
5
|
-
module DecimalInteger
|
6
|
-
decimal = '\d+(?:_\d+)*'
|
7
|
-
DecimalInteger = /\A[-+]?#{decimal}\z/io
|
8
|
-
::OptionParser::accept(DecimalInteger, DecimalInteger) {|s,|
|
9
|
-
begin
|
10
|
-
Integer(s, 10)
|
11
|
-
rescue ArgumentError
|
12
|
-
raise ::OptionParser::InvalidArgument, s
|
13
|
-
end if s
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Commander
|
2
|
-
module Patches
|
3
|
-
module HelpFormatterBinding
|
4
|
-
def get_binding(additional = {})
|
5
|
-
bnd = @target.instance_eval { binding }.tap do |bind|
|
6
|
-
decorate_binding(bind)
|
7
|
-
end
|
8
|
-
additional.each do |k, v|
|
9
|
-
bnd.local_variable_set(k, v)
|
10
|
-
end
|
11
|
-
bnd
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# Patches the underling ruby OptionParser to prevent it from automatically
|
2
|
-
# generating short tags for options
|
3
|
-
module Commander
|
4
|
-
module Patches
|
5
|
-
module ImplicitShortTags
|
6
|
-
def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
|
7
|
-
opt, arg, val, rest = nil
|
8
|
-
nonopt ||= proc {|a| throw :terminate, a}
|
9
|
-
argv.unshift(arg) if arg = catch(:terminate) {
|
10
|
-
while arg = argv.shift
|
11
|
-
case arg
|
12
|
-
# long option
|
13
|
-
when /\A--([^=]*)(?:=(.*))?/m
|
14
|
-
opt, rest = $1, $2
|
15
|
-
opt.tr!('_', '-')
|
16
|
-
begin
|
17
|
-
sw, = complete(:long, opt, true)
|
18
|
-
rescue ::OptionParser::ParseError
|
19
|
-
raise $!.set_option(arg, true)
|
20
|
-
end
|
21
|
-
begin
|
22
|
-
opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
|
23
|
-
val = cb.call(val) if cb
|
24
|
-
setter.call(sw.switch_name, val) if setter
|
25
|
-
rescue ::OptionParser::ParseError
|
26
|
-
raise $!.set_option(arg, rest)
|
27
|
-
end
|
28
|
-
|
29
|
-
# short option
|
30
|
-
when /\A-(.)((=).*|.+)?/m
|
31
|
-
eq, rest, opt = $3, $2, $1
|
32
|
-
has_arg, val = eq, rest
|
33
|
-
begin
|
34
|
-
sw, = search(:short, opt)
|
35
|
-
unless sw
|
36
|
-
sw, = complete(:short, opt)
|
37
|
-
# short option matched.
|
38
|
-
val = arg.sub(/\A-/, '')
|
39
|
-
has_arg = true
|
40
|
-
end
|
41
|
-
rescue ::OptionParser::ParseError
|
42
|
-
raise $!.set_option(arg, true)
|
43
|
-
end
|
44
|
-
begin
|
45
|
-
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
|
46
|
-
raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
|
47
|
-
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
|
48
|
-
val = cb.call(val) if cb
|
49
|
-
setter.call(sw.switch_name, val) if setter
|
50
|
-
rescue ::OptionParser::ParseError
|
51
|
-
raise $!.set_option(arg, arg.length > 2)
|
52
|
-
end
|
53
|
-
|
54
|
-
# non-option argument
|
55
|
-
else
|
56
|
-
catch(:prune) do
|
57
|
-
visit(:each_option) do |sw0|
|
58
|
-
sw = sw0
|
59
|
-
sw.block.call(arg) if ::OptionParser::Switch === sw and sw.match_nonswitch?(arg)
|
60
|
-
end
|
61
|
-
nonopt.call(arg)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
nil
|
67
|
-
}
|
68
|
-
|
69
|
-
visit(:search, :short, nil) {|sw| sw.block.call(*argv) if !sw.pattern}
|
70
|
-
|
71
|
-
argv
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|