commander-openflighthpc 1.0.0.pre.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +44 -0
  5. data/.rubocop_todo.yml +77 -0
  6. data/.travis.yml +14 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE +51 -0
  10. data/Manifest +38 -0
  11. data/README.md +492 -0
  12. data/Rakefile +13 -0
  13. data/bin/commander +104 -0
  14. data/commander-openflighthpc.gemspec +32 -0
  15. data/lib/commander.rb +36 -0
  16. data/lib/commander/blank.rb +7 -0
  17. data/lib/commander/command.rb +263 -0
  18. data/lib/commander/configure.rb +14 -0
  19. data/lib/commander/core_ext.rb +2 -0
  20. data/lib/commander/core_ext/array.rb +24 -0
  21. data/lib/commander/core_ext/object.rb +8 -0
  22. data/lib/commander/delegates.rb +27 -0
  23. data/lib/commander/help_formatters.rb +52 -0
  24. data/lib/commander/help_formatters/base.rb +24 -0
  25. data/lib/commander/help_formatters/terminal.rb +24 -0
  26. data/lib/commander/help_formatters/terminal/command_help.erb +35 -0
  27. data/lib/commander/help_formatters/terminal/help.erb +36 -0
  28. data/lib/commander/help_formatters/terminal/subcommand_help.erb +23 -0
  29. data/lib/commander/help_formatters/terminal_compact.rb +11 -0
  30. data/lib/commander/help_formatters/terminal_compact/command_help.erb +26 -0
  31. data/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
  32. data/lib/commander/help_formatters/terminal_compact/subcommand_help.erb +15 -0
  33. data/lib/commander/import.rb +5 -0
  34. data/lib/commander/methods.rb +11 -0
  35. data/lib/commander/patches/decimal-integer.rb +17 -0
  36. data/lib/commander/patches/help_formatter_binding.rb +15 -0
  37. data/lib/commander/patches/implicit-short-tags.rb +75 -0
  38. data/lib/commander/patches/option_defaults.rb +23 -0
  39. data/lib/commander/patches/validate_inputs.rb +76 -0
  40. data/lib/commander/platform.rb +7 -0
  41. data/lib/commander/runner.rb +493 -0
  42. data/lib/commander/user_interaction.rb +551 -0
  43. data/lib/commander/version.rb +3 -0
  44. data/spec/command_spec.rb +157 -0
  45. data/spec/configure_spec.rb +37 -0
  46. data/spec/core_ext/array_spec.rb +18 -0
  47. data/spec/core_ext/object_spec.rb +19 -0
  48. data/spec/help_formatters/terminal_compact_spec.rb +69 -0
  49. data/spec/help_formatters/terminal_spec.rb +67 -0
  50. data/spec/methods_spec.rb +61 -0
  51. data/spec/patches/validate_inputs_spec.rb +84 -0
  52. data/spec/runner_spec.rb +672 -0
  53. data/spec/spec_helper.rb +79 -0
  54. data/spec/ui_spec.rb +30 -0
  55. metadata +183 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc01ccac1ba2a5fd02f67bd37df18b99338c47ee5ec198a8290c04d49314a914
4
+ data.tar.gz: 721ce6a9a0664d524b5647fe6ecf0e905bdc30918c4711fa3c42e9abe8c8fc16
5
+ SHA512:
6
+ metadata.gz: 21b6f4bacadc8d47584d780b2656227bca27ca0ad6ce70d3cee8948f6c4f2a899d2cb01798d2572e8470907ae8ee136bb09d88c6fbc63e5d11fd5f1d9cb4ae37
7
+ data.tar.gz: 782fe6b493abe05d551b77ea719d9c01b7e6712e23d40697465f817c0d069af367cb6cbd817295e70f29dd3cc90ca9e91f57a180949c8f72d95cd37cd98f42dc
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ .ruby-version
7
+ coverage/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 1.9
5
+
6
+ # not Ruby 1.9.3 compatible
7
+ Style/PercentLiteralDelimiters:
8
+ Enabled: false
9
+
10
+ # Offense count: 5
11
+ Encoding:
12
+ Enabled: false
13
+
14
+ # Enforce trailing comma after last item of multiline hashes.
15
+ Style/TrailingCommaInLiteral:
16
+ EnforcedStyleForMultiline: comma
17
+
18
+ Metrics/BlockLength:
19
+ Enabled: false
20
+
21
+ Style/SignalException:
22
+ EnforcedStyle: only_fail
23
+
24
+ Style/ParallelAssignment:
25
+ Enabled: false
26
+
27
+ Style/NumericLiteralPrefix:
28
+ EnforcedOctalStyle: zero_only
29
+
30
+ Style/MethodMissing:
31
+ Enabled: false
32
+
33
+ Layout/SpaceInsideStringInterpolation:
34
+ Enabled: false
35
+
36
+ Layout/MultilineOperationIndentation:
37
+ Enabled: false
38
+
39
+ Style/EmptyMethod:
40
+ EnforcedStyle: expanded
41
+
42
+ Metrics/ModuleLength:
43
+ CountComments: false # count full line comments?
44
+ Max: 150
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,77 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-02-16 16:08:54 -0800 using RuboCop version 0.29.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 2
9
+ Security/Eval:
10
+ Enabled: false
11
+
12
+ # Offense count: 2
13
+ Lint/HandleExceptions:
14
+ Enabled: false
15
+
16
+ # Offense count: 5
17
+ Metrics/AbcSize:
18
+ Max: 29
19
+
20
+ # Offense count: 1
21
+ # Configuration parameters: CountComments.
22
+ Metrics/ClassLength:
23
+ Enabled: false
24
+
25
+ # Offense count: 4
26
+ Metrics/CyclomaticComplexity:
27
+ Max: 13
28
+
29
+ # Offense count: 89
30
+ # Configuration parameters: AllowURI, URISchemes.
31
+ Metrics/LineLength:
32
+ Max: 242
33
+
34
+ # Offense count: 7
35
+ # Configuration parameters: CountComments.
36
+ Metrics/MethodLength:
37
+ Max: 36
38
+
39
+ # Offense count: 4
40
+ Metrics/PerceivedComplexity:
41
+ Max: 14
42
+
43
+ # Offense count: 1
44
+ Style/AccessorMethodName:
45
+ Enabled: false
46
+
47
+ # Offense count: 18
48
+ Style/Documentation:
49
+ Enabled: false
50
+
51
+ # Offense count: 12
52
+ # Configuration parameters: AllowedVariables.
53
+ Style/GlobalVars:
54
+ Enabled: false
55
+
56
+ # Offense count: 1
57
+ # Configuration parameters: MaxLineLength.
58
+ Style/IfUnlessModifier:
59
+ Enabled: false
60
+
61
+ # Offense count: 1
62
+ Style/MultilineBlockChain:
63
+ Enabled: false
64
+
65
+ # Offense count: 1
66
+ Style/MultilineTernaryOperator:
67
+ Enabled: false
68
+
69
+ # Offense count: 5
70
+ Style/RescueModifier:
71
+ Enabled: false
72
+
73
+ # Offense count: 2
74
+ # Cop supports --auto-correct.
75
+ # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
76
+ Style/TrivialAccessors:
77
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ before_install:
4
+ - gem update --system
5
+ - gem update bundler
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0.0
9
+ - 2.1.10
10
+ - 2.2.9
11
+ - 2.3.6
12
+ - 2.4.3
13
+ - 2.5.0
14
+ - jruby-19mode
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 1.0.0 / Unreleased
2
+
3
+ * Reset version numbering for this fork.
4
+ * Forked for OpenFlightHPC from upstream version 4.4.4 w/ existing patches from [alces-software/commander](https://github.com/alces-software/commander).
5
+ * Refer to [commander-rb/commander:History.rdoc](https://github.com/commander-rb/commander/blob/master/History.rdoc) for older changes.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ The following license applies to changes made subsequent to the point
2
+ this version was forked from the original upstream version available
3
+ at <https://github.com/commander-rb/commander>.
4
+
5
+ The MIT License (MIT)
6
+
7
+ Copyright (c) 2017-present Alces Flight Ltd <licensing@alces-flight.com>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining
10
+ a copy of this software and associated documentation files (the
11
+ "Software"), to deal in the Software without restriction, including
12
+ without limitation the rights to use, copy, modify, merge, publish,
13
+ distribute, sublicense, and/or sell copies of the Software, and to
14
+ permit persons to whom the Software is furnished to do so, subject to
15
+ the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included
18
+ in all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+
28
+ The original license from the upstream version is included below:
29
+
30
+ The MIT License (MIT)
31
+
32
+ Copyright (c) 2008-2013 TJ Holowaychuk <tj@vision-media.ca>
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ "Software"), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included
43
+ in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,38 @@
1
+ DEVELOPMENT
2
+ History.rdoc
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ bin/commander
7
+ commander.gemspec
8
+ lib/commander.rb
9
+ lib/commander/blank.rb
10
+ lib/commander/command.rb
11
+ lib/commander/core_ext.rb
12
+ lib/commander/core_ext/array.rb
13
+ lib/commander/core_ext/object.rb
14
+ lib/commander/delegates.rb
15
+ lib/commander/help_formatters.rb
16
+ lib/commander/help_formatters/base.rb
17
+ lib/commander/help_formatters/terminal.rb
18
+ lib/commander/help_formatters/terminal/command_help.erb
19
+ lib/commander/help_formatters/terminal/help.erb
20
+ lib/commander/help_formatters/terminal_compact.rb
21
+ lib/commander/help_formatters/terminal_compact/command_help.erb
22
+ lib/commander/help_formatters/terminal_compact/help.erb
23
+ lib/commander/import.rb
24
+ lib/commander/platform.rb
25
+ lib/commander/runner.rb
26
+ lib/commander/user_interaction.rb
27
+ lib/commander/version.rb
28
+ spec/command_spec.rb
29
+ spec/core_ext/array_spec.rb
30
+ spec/core_ext/object_spec.rb
31
+ spec/help_formatters/terminal_spec.rb
32
+ spec/runner_spec.rb
33
+ spec/spec.opts
34
+ spec/spec_helper.rb
35
+ spec/ui_spec.rb
36
+ tasks/dev_setup.rake
37
+ tasks/docs.rake
38
+ tasks/gemspec.rake
data/README.md ADDED
@@ -0,0 +1,492 @@
1
+ # Note: This is a fork
2
+
3
+ The version number was reset to 1.0.0 at the time of forking and
4
+ roughly maps to v4.4.4 of the upstream project.
5
+
6
+ You can find the original repo at
7
+ [commander-rb/commander](https://github.com/commander-rb/commander).
8
+
9
+ This fork adds a number of patches and modifications to the upstream
10
+ project that support the OpenFlightHPC tools.
11
+
12
+ To ship a new release, do the following:
13
+
14
+ * Increment the version number in `version.rb`
15
+ * Run `rake build`
16
+ * Run `rake release`
17
+
18
+ Documentation from the upstream project follows.
19
+
20
+ ---
21
+
22
+ # Commander
23
+
24
+ The complete solution for Ruby command-line executables.
25
+ Commander bridges the gap between other terminal related libraries
26
+ you know and love (OptionParser, HighLine), while providing many new
27
+ features, and an elegant API.
28
+
29
+ ## Features
30
+
31
+ * Easier than baking cookies
32
+ * Parses options using OptionParser
33
+ * Auto-populates struct with options ( no more `{ |v| options[:recursive] = v }` )
34
+ * Auto-generates help documentation via pluggable help formatters
35
+ * Optional default command when none is present
36
+ * Global / Command level options
37
+ * Packaged with two help formatters (Terminal, TerminalCompact)
38
+ * Imports the highline gem for interacting with the terminal
39
+ * Adds additional user interaction functionality
40
+ * Highly customizable progress bar with intuitive, simple usage
41
+ * Multi-word command name support such as `drupal module install MOD`, rather than `drupal module_install MOD`
42
+ * Sexy paging for long bodies of text
43
+ * Support for MacOS text-to-speech
44
+ * Command aliasing (very powerful, as both switches and arguments can be used)
45
+ * Growl notification support for MacOS
46
+ * Use the `commander` executable to initialize a commander driven program
47
+
48
+ ## Installation
49
+
50
+ $ gem install commander
51
+
52
+ ## Quick Start
53
+
54
+ To generate a quick template for a commander app, run:
55
+
56
+ $ commander init yourfile.rb
57
+
58
+ To generate a quick modular style template for a commander app, run:
59
+
60
+ $ commander init --modular yourfile.rb
61
+
62
+ ## Example
63
+
64
+ For more option examples view the `Commander::Command#option` method. Also
65
+ an important feature to note is that action may be a class to instantiate,
66
+ as well as an object, specifying a method to call, so view the RDoc for more information.
67
+
68
+ ### Classic style
69
+
70
+ ```ruby
71
+ require 'rubygems'
72
+ require 'commander/import'
73
+
74
+ # :name is optional, otherwise uses the basename of this executable
75
+ program :name, 'Foo Bar'
76
+ program :version, '1.0.0'
77
+ program :description, 'Stupid command that prints foo or bar.'
78
+
79
+ command :foo do |c|
80
+ c.syntax = 'foobar foo'
81
+ c.description = 'Displays foo'
82
+ c.action do |args, options|
83
+ say 'foo'
84
+ end
85
+ end
86
+
87
+ command :bar do |c|
88
+ c.syntax = 'foobar bar [options]'
89
+ c.description = 'Display bar with optional prefix and suffix'
90
+ c.option '--prefix STRING', String, 'Adds a prefix to bar'
91
+ c.option '--suffix STRING', String, 'Adds a suffix to bar'
92
+ c.action do |args, options|
93
+ options.default :prefix => '(', :suffix => ')'
94
+ say "#{options.prefix}bar#{options.suffix}"
95
+ end
96
+ end
97
+ ```
98
+
99
+ Example output:
100
+
101
+ ```
102
+ $ foobar bar
103
+ # => (bar)
104
+
105
+ $ foobar bar --suffix '}' --prefix '{'
106
+ # => {bar}
107
+ ```
108
+
109
+ ### Modular style
110
+
111
+ **NOTE:** Make sure to use `require 'commander'` rather than `require 'commander/import'`, otherwise Commander methods will still be imported into the global namespace.
112
+
113
+ ```ruby
114
+ require 'rubygems'
115
+ require 'commander'
116
+
117
+ class MyApplication
118
+ include Commander::Methods
119
+
120
+ def run
121
+ program :name, 'Foo Bar'
122
+ program :version, '1.0.0'
123
+ program :description, 'Stupid command that prints foo or bar.'
124
+
125
+ command :foo do |c|
126
+ c.syntax = 'foobar foo'
127
+ c.description = 'Displays foo'
128
+ c.action do |args, options|
129
+ say 'foo'
130
+ end
131
+ end
132
+
133
+ run!
134
+ end
135
+ end
136
+
137
+ MyApplication.new.run if $0 == __FILE__
138
+ ```
139
+
140
+ ### Block style
141
+
142
+ ```ruby
143
+ require 'rubygems'
144
+ require 'commander'
145
+
146
+ Commander.configure do
147
+ program :name, 'Foo Bar'
148
+ program :version, '1.0.0'
149
+ program :description, 'Stupid command that prints foo or bar.'
150
+
151
+ # see classic style example for options
152
+ end
153
+ ```
154
+
155
+ ## HighLine
156
+
157
+ As mentioned above, the highline gem is imported into the global scope. Here
158
+ are some quick examples for how to utilize highline in your commands:
159
+
160
+ ```ruby
161
+ # Ask for password masked with '*' character
162
+ ask("Password: ") { |q| q.echo = "*" }
163
+
164
+ # Ask for password
165
+ ask("Password: ") { |q| q.echo = false }
166
+
167
+ # Ask if the user agrees (yes or no)
168
+ agree("Do something?")
169
+
170
+ # Asks on a single line (note the space after ':')
171
+ ask("Name: ")
172
+
173
+ # Asks with new line after "Description:"
174
+ ask("Description:")
175
+
176
+ # Calls Date#parse to parse the date string passed
177
+ ask("Birthday? ", Date)
178
+
179
+ # Ensures Integer is within the range specified
180
+ ask("Age? ", Integer) { |q| q.in = 0..105 }
181
+
182
+ # Asks for a list of strings, converts to array
183
+ ask("Fav colors?", Array)
184
+ ```
185
+
186
+ ## HighLine & Interaction Additions
187
+
188
+ In addition to highline's fantastic choice of methods, commander adds the
189
+ following methods to simplify common tasks:
190
+
191
+ ```ruby
192
+ # Ask for password
193
+ password
194
+
195
+ # Ask for password with specific message and mask character
196
+ password "Enter your password please:", '-'
197
+
198
+ # Ask for CLASS, which may be any valid class responding to #parse. Date, Time, Array, etc
199
+ names = ask_for_array 'Names: '
200
+ bday = ask_for_date 'Birthday?: '
201
+
202
+ # Simple progress bar (Commander::UI::ProgressBar)
203
+ uris = %w[
204
+ http://vision-media.ca
205
+ http://google.com
206
+ http://yahoo.com
207
+ ]
208
+ progress uris do |uri|
209
+ res = open uri
210
+ # Do something with response
211
+ end
212
+
213
+ # 'Log' action to stdout
214
+ log "create", "path/to/file.rb"
215
+
216
+ # Enable paging of output after this point
217
+ enable_paging
218
+
219
+ # Ask editor for input (EDITOR environment variable or whichever is available: TextMate, vim, vi, emacs, nano, pico)
220
+ ask_editor
221
+
222
+ # Ask editor, supplying initial text
223
+ ask_editor 'previous data to update'
224
+
225
+ # Ask editor, preferring a specific editor
226
+ ask_editor 'previous data', 'vim'
227
+
228
+ # Choose from an array of elements
229
+ choice = choose("Favorite language?", :ruby, :perl, :js)
230
+
231
+ # Alter IO for the duration of the block
232
+ io new_input, new_output do
233
+ new_input_contents = $stdin.read
234
+ puts new_input_contents # outputs to new_output stream
235
+ end
236
+ # $stdin / $stdout reset back to original streams
237
+
238
+ # Speech synthesis
239
+ speak 'What is your favorite food? '
240
+ food = ask 'favorite food?: '
241
+ speak "Wow, I like #{food} too. We have so much in common."
242
+ speak "I like #{food} as well!", "Victoria", 190
243
+
244
+ # Execute arbitrary applescript
245
+ applescript 'foo'
246
+
247
+ # Converse with speech recognition server
248
+ case converse 'What is the best food?', :cookies => 'Cookies', :unknown => 'Nothing'
249
+ when :cookies
250
+ speak 'o.m.g. you are awesome!'
251
+ else
252
+ case converse 'That is lame, shall I convince you cookies are the best?', :yes => 'Ok', :no => 'No', :maybe => 'Maybe another time'
253
+ when :yes
254
+ speak 'Well you see, cookies are just fantastic, they melt in your mouth.'
255
+ else
256
+ speak 'Ok then, bye.'
257
+ end
258
+ end
259
+ ```
260
+
261
+ ## Growl Notifications
262
+
263
+ Commander provides methods for displaying Growl notifications. To use these
264
+ methods you need to install http://github.com/tj/growl which utilizes
265
+ the [growlnotify](http://growl.info/extras.php#growlnotify) executable. Note that
266
+ growl is auto-imported by Commander when available, no need to require.
267
+
268
+ ```ruby
269
+ # Display a generic Growl notification
270
+ notify 'Something happened'
271
+
272
+ # Display an 'info' status notification
273
+ notify_info 'You have #{emails.length} new email(s)'
274
+
275
+ # Display an 'ok' status notification
276
+ notify_ok 'Gems updated'
277
+
278
+ # Display a 'warning' status notification
279
+ notify_warning '1 gem failed installation'
280
+
281
+ # Display an 'error' status notification
282
+ notify_error "Gem #{name} failed"
283
+ ```
284
+
285
+ ## Commander Goodies
286
+
287
+ ### Option Defaults
288
+
289
+ The options struct passed to `#action` provides a `#default` method, allowing you
290
+ to set defaults in a clean manner for options which have not been set.
291
+
292
+ ```ruby
293
+ command :foo do |c|
294
+ c.option '--interval SECONDS', Integer, 'Interval in seconds'
295
+ c.option '--timeout SECONDS', Integer, 'Timeout in seconds'
296
+ c.action do |args, options|
297
+ options.default \
298
+ :interval => 2,
299
+ :timeout => 60
300
+ end
301
+ end
302
+ ```
303
+
304
+ ### Command Aliasing
305
+
306
+ Aliases can be created using the `#alias_command` method like below:
307
+
308
+ ```ruby
309
+ command :'install gem' do |c|
310
+ c.action { puts 'foo' }
311
+ end
312
+ alias_command :'gem install', :'install gem'
313
+ ```
314
+
315
+ Or more complicated aliases can be made, passing any arguments
316
+ as if it was invoked via the command line:
317
+
318
+ ```ruby
319
+ command :'install gem' do |c|
320
+ c.syntax = 'install gem <name> [options]'
321
+ c.option '--dest DIR', String, 'Destination directory'
322
+ c.action { |args, options| puts "installing #{args.first} to #{options.dest}" }
323
+ end
324
+ alias_command :update, :'install gem', 'rubygems', '--dest', 'some_path'
325
+ ```
326
+
327
+ ```
328
+ $ foo update
329
+ # => installing rubygems to some_path
330
+ ```
331
+
332
+ ### Command Defaults
333
+
334
+ Although working with a command executable framework provides many
335
+ benefits over a single command implementation, sometimes you still
336
+ want the ability to create a terse syntax for your command. With that
337
+ in mind we may use `#default_command` to help with this. Considering
338
+ our previous `:'install gem'` example:
339
+
340
+ ```ruby
341
+ default_command :update
342
+ ```
343
+
344
+ ```
345
+ $ foo
346
+ # => installing rubygems to some_path
347
+ ```
348
+
349
+ Keeping in mind that commander searches for the longest possible match
350
+ when considering a command, so if you were to pass arguments to foo
351
+ like below, expecting them to be passed to `:update`, this would be incorrect,
352
+ and would end up calling `:'install gem'`, so be careful that the users do
353
+ not need to use command names within the arguments.
354
+
355
+ ```
356
+ $ foo install gem
357
+ # => installing to
358
+ ```
359
+
360
+ ### Long descriptions
361
+
362
+ If you need to have a long command description, keep your short description under `summary`, and consider multi-line strings for `description`:
363
+
364
+ ```ruby
365
+ program :summary, 'Stupid command that prints foo or bar.'
366
+ program :description, %q(
367
+ #{c.summary}
368
+
369
+ More information about that stupid command that prints foo or bar.
370
+
371
+ And more
372
+ )
373
+ ```
374
+
375
+ ### Additional Global Help
376
+
377
+ Arbitrary help can be added using the following `#program` symbol:
378
+
379
+ ```ruby
380
+ program :help, 'Author', 'TJ Holowaychuk <tj@vision-media.ca>'
381
+ ```
382
+
383
+ Which will output the rest of the help doc, along with:
384
+
385
+ AUTHOR:
386
+
387
+ TJ Holowaychuk <tj@vision-media.ca>
388
+
389
+ ### Global Options
390
+
391
+ Although most switches will be at the command level, several are available by
392
+ default at the global level, such as `--version`, and `--help`. Using
393
+ `#global_option` you can add additional global options:
394
+
395
+ ```ruby
396
+ global_option('-c', '--config FILE', 'Load config data for your commands to use') { |file| ... }
397
+ ```
398
+
399
+ This method accepts the same syntax as `Commander::Command#option` so check it out for documentation.
400
+
401
+ All global options regardless of providing a block are accessable at the command level. This
402
+ means that instead of the following:
403
+
404
+ ```ruby
405
+ global_option('--verbose') { $verbose = true }
406
+ ...
407
+ c.action do |args, options|
408
+ say 'foo' if $verbose
409
+ ...
410
+ ```
411
+
412
+ You may:
413
+
414
+ ```ruby
415
+ global_option '--verbose'
416
+ ...
417
+ c.action do |args, options|
418
+ say 'foo' if options.verbose
419
+ ...
420
+ ```
421
+
422
+ ### Formatters
423
+
424
+ Two core formatters are currently available, the default `Terminal` formatter
425
+ as well as `TerminalCompact`. To utilize a different formatter simply use
426
+ `:help_formatter` like below:
427
+
428
+ ```ruby
429
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
430
+ ```
431
+
432
+ Or utilize the help formatter aliases:
433
+
434
+ ```ruby
435
+ program :help_formatter, :compact
436
+ ```
437
+
438
+ This abstraction could be utilized to generate HTML documentation for your executable.
439
+
440
+ ### Tracing
441
+
442
+ By default the `-t` and `--trace` global options are provided to allow users to get a backtrace to aid debugging.
443
+
444
+ You can disable these options:
445
+
446
+ ```ruby
447
+ never_trace!
448
+ ```
449
+
450
+ Or make it always on:
451
+
452
+ ```ruby
453
+ always_trace!
454
+ ```
455
+
456
+ Include the `--trace` global option but turn off the error message prompt:
457
+
458
+ ```ruby
459
+ silent_trace!
460
+ ```
461
+
462
+ ## Tips
463
+
464
+ When adding a global or command option, `OptionParser` no longer implicitly adds a small
465
+ switch unless explicitly stated.
466
+
467
+ ## ASCII Tables
468
+
469
+ For feature rich ASCII tables for your terminal app check out the terminal-table gem at http://github.com/tj/terminal-table
470
+
471
+ +----------+-------+----+--------+-----------------------+
472
+ | Terminal | Table | Is | Wicked | Awesome |
473
+ +----------+-------+----+--------+-----------------------+
474
+ | | | | | get it while its hot! |
475
+ +----------+-------+----+--------+-----------------------+
476
+
477
+ ## Running Specifications
478
+
479
+ $ rake spec
480
+
481
+ OR
482
+
483
+ $ spec --color spec
484
+
485
+ ## Contrib
486
+
487
+ Feel free to fork and request a pull, or submit a ticket
488
+ http://github.com/commander-rb/commander/issues
489
+
490
+ ## License
491
+
492
+ This project is available under the MIT license. See LICENSE for details.