commander 4.1.5 → 4.1.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89c316cbb98922c1aa25063c184fe3214dc33f03
4
+ data.tar.gz: 5222385e2c3e6f4d59b4b748315b429173d95435
5
+ SHA512:
6
+ metadata.gz: 1d88c3df61b540cfa7e5bf58f83891393f331f0844a031619692a5429417471f3aacd1910fb7fdfb52bcaa8aa0ca469b050cd301b2323e3cd9220851d36bce2e
7
+ data.tar.gz: 5534ce249d8211b77c8c8112d9793e122137ec0513146bef96cf6ad1fcca4610f0bdf8a83856a1288bcca8e4f0818e537263df017263ba2709943ff0b290fd46
@@ -2,10 +2,9 @@ language: ruby
2
2
  before_install: gem update --system
3
3
  rvm:
4
4
  - 1.8.7
5
- - 1.9.2
6
5
  - 1.9.3
7
6
  - 2.0.0
7
+ - 2.1.0
8
8
  - jruby-18mode
9
9
  - jruby-19mode
10
- - rbx-18mode
11
- - rbx-19mode
10
+ - rbx
@@ -1,3 +1,8 @@
1
+ === 4.1.6 / 2014-02-11
2
+
3
+ * Respect environment setting for $LESS (@ellemenno)
4
+ * Add ability to hide trace flags and globally enable tracing (#16, #17) (@jamesrwhite)
5
+
1
6
  === 4.1.5 / 2013-08-11
2
7
 
3
8
  * Prevent deprecation warning when loaded in a Rails 4 environment (#58)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2008-2013 TJ Holowaychuk <tj@vision-media.ca>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,406 @@
1
+ [<img src="https://secure.travis-ci.org/ggilder/commander.png?branch=master" alt="Build Status" />](http://travis-ci.org/ggilder/commander)
2
+
3
+ # Commander
4
+
5
+ The complete solution for Ruby command-line executables.
6
+ Commander bridges the gap between other terminal related libraries
7
+ you know and love (OptionParser, HighLine), while providing many new
8
+ features, and an elegant API.
9
+
10
+ ## Features
11
+
12
+ * Easier than baking cookies
13
+ * Parses options using OptionParser
14
+ * Auto-populates struct with options ( no more `{ |v| options[:recursive] = v }` )
15
+ * Auto-generates help documentation via pluggable help formatters
16
+ * Optional default command when none is present
17
+ * Global / Command level options
18
+ * Packaged with two help formatters (Terminal, TerminalCompact)
19
+ * Imports the highline gem for interacting with the terminal
20
+ * Adds additional user interaction functionality
21
+ * Highly customizable progress bar with intuitive, simple usage
22
+ * Multi-word command name support such as `drupal module install MOD`, rather than `drupal module_install MOD`
23
+ * Sexy paging for long bodies of text
24
+ * Support for MacOS text-to-speech
25
+ * Command aliasing (very powerful, as both switches and arguments can be used)
26
+ * Growl notification support for MacOS
27
+ * Use the `commander` executable to initialize a commander driven program
28
+
29
+ ## Installation
30
+
31
+ $ gem install commander
32
+
33
+ ## Quick Start
34
+
35
+ To generate a quick template for a commander app, run:
36
+
37
+ $ commander init yourfile.rb
38
+
39
+ ## Example
40
+
41
+ For more option examples view the `Commander::Command#option` method. Also
42
+ an important feature to note is that action may be a class to instantiate,
43
+ as well as an object, specifying a method to call, so view the RDoc for more information.
44
+
45
+ ```ruby
46
+ require 'rubygems'
47
+ require 'commander/import'
48
+
49
+ # :name is optional, otherwise uses the basename of this executable
50
+ program :name, 'Foo Bar'
51
+ program :version, '1.0.0'
52
+ program :description, 'Stupid command that prints foo or bar.'
53
+
54
+ command :foo do |c|
55
+ c.syntax = 'foobar foo'
56
+ c.description = 'Displays foo'
57
+ c.action do |args, options|
58
+ say 'foo'
59
+ end
60
+ end
61
+
62
+ command :bar do |c|
63
+ c.syntax = 'foobar bar [options]'
64
+ c.description = 'Display bar with optional prefix and suffix'
65
+ c.option '--prefix STRING', String, 'Adds a prefix to bar'
66
+ c.option '--suffix STRING', String, 'Adds a suffix to bar'
67
+ c.action do |args, options|
68
+ options.default :prefix => '(', :suffix => ')'
69
+ say "#{options.prefix}bar#{options.suffix}"
70
+ end
71
+ end
72
+ ```
73
+
74
+ Example output:
75
+ ```
76
+ $ foobar bar
77
+ # => (bar)
78
+
79
+ $ foobar bar --suffix '}' --prefix '{'
80
+ # => {bar}
81
+ ```
82
+
83
+ ## HighLine
84
+
85
+ As mentioned above, the highline gem is imported into the global scope. Here
86
+ are some quick examples for how to utilize highline in your commands:
87
+
88
+ ```ruby
89
+ # Ask for password masked with '*' character
90
+ ask("Password: ") { |q| q.echo = "*" }
91
+
92
+ # Ask for password
93
+ ask("Password: ") { |q| q.echo = false }
94
+
95
+ # Ask if the user agrees (yes or no)
96
+ agree("Do something?")
97
+
98
+ # Asks on a single line (note the space after ':')
99
+ ask("Name: ")
100
+
101
+ # Asks with new line after "Description:"
102
+ ask("Description:")
103
+
104
+ # Calls Date#parse to parse the date string passed
105
+ ask("Birthday? ", Date)
106
+
107
+ # Ensures Integer is within the range specified
108
+ ask("Age? ", Integer) { |q| q.in = 0..105 }
109
+
110
+ # Asks for a list of strings, converts to array
111
+ ask("Fav colors?", Array)
112
+ ```
113
+
114
+ ## HighLine & Interaction Additions
115
+
116
+ In addition to highline's fantastic choice of methods, commander adds the
117
+ following methods to simplify common tasks:
118
+
119
+ ```ruby
120
+ # Ask for password
121
+ password
122
+
123
+ # Ask for password with specific message and mask character
124
+ password "Enter your password please:", '-'
125
+
126
+ # Ask for CLASS, which may be any valid class responding to #parse. Date, Time, Array, etc
127
+ names = ask_for_array 'Names: '
128
+ bday = ask_for_date 'Birthday?: '
129
+
130
+ # Simple progress bar (Commander::UI::ProgressBar)
131
+ uris = %w[
132
+ http://vision-media.ca
133
+ http://google.com
134
+ http://yahoo.com
135
+ ]
136
+ progress uris do |uri|
137
+ res = open uri
138
+ # Do something with response
139
+ end
140
+
141
+ # 'Log' action to stdout
142
+ log "create", "path/to/file.rb"
143
+
144
+ # Enable paging of output after this point
145
+ enable_paging
146
+
147
+ # Ask editor for input (EDITOR environment variable or whichever is available: TextMate, vim, vi, emacs, nano, pico)
148
+ ask_editor
149
+
150
+ # Ask editor, supplying initial text
151
+ ask_editor 'previous data to update'
152
+
153
+ # Ask editor, preferring a specific editor
154
+ ask_editor 'previous data', 'vim'
155
+
156
+ # Choose from an array of elements
157
+ choice = choose("Favorite language?", :ruby, :perl, :js)
158
+
159
+ # Alter IO for the duration of the block
160
+ io new_input, new_output do
161
+ new_input_contents = $stdin.read
162
+ puts new_input_contents # outputs to new_output stream
163
+ end
164
+ # $stdin / $stdout reset back to original streams
165
+
166
+ # Speech synthesis
167
+ speak 'What is your favorite food? '
168
+ food = ask 'favorite food?: '
169
+ speak "Wow, I like #{food} too. We have so much in common."
170
+ speak "I like #{food} as well!", "Victoria", 190
171
+
172
+ # Execute arbitrary applescript
173
+ applescript 'foo'
174
+
175
+ # Converse with speech recognition server
176
+ case converse 'What is the best food?', :cookies => 'Cookies', :unknown => 'Nothing'
177
+ when :cookies
178
+ speak 'o.m.g. you are awesome!'
179
+ else
180
+ case converse 'That is lame, shall I convince you cookies are the best?', :yes => 'Ok', :no => 'No', :maybe => 'Maybe another time'
181
+ when :yes
182
+ speak 'Well you see, cookies are just fantastic, they melt in your mouth.'
183
+ else
184
+ speak 'Ok then, bye.'
185
+ end
186
+ end
187
+ ```
188
+
189
+ ## Growl Notifications
190
+
191
+ Commander provides methods for displaying Growl notifications. To use these
192
+ methods you need to install http://github.com/visionmedia/growl which utilizes
193
+ the [growlnotify](http://growl.info/extras.php#growlnotify) executable. Note that
194
+ growl is auto-imported by Commander when available, no need to require.
195
+
196
+ ```ruby
197
+ # Display a generic Growl notification
198
+ notify 'Something happened'
199
+
200
+ # Display an 'info' status notification
201
+ notify_info 'You have #{emails.length} new email(s)'
202
+
203
+ # Display an 'ok' status notification
204
+ notify_ok 'Gems updated'
205
+
206
+ # Display a 'warning' status notification
207
+ notify_warning '1 gem failed installation'
208
+
209
+ # Display an 'error' status notification
210
+ notify_error "Gem #{name} failed"
211
+ ```
212
+
213
+ ## Commander Goodies
214
+
215
+ ### Option Defaults
216
+
217
+ The options struct passed to `#action` provides a `#default` method, allowing you
218
+ to set defaults in a clean manner for options which have not been set.
219
+
220
+ ```ruby
221
+ command :foo do |c|
222
+ c.option '--interval SECONDS', Integer, 'Interval in seconds'
223
+ c.option '--timeout SECONDS', Integer, 'Timeout in seconds'
224
+ c.action do |args, options|
225
+ options.default \
226
+ :interval => 2,
227
+ :timeout => 60
228
+ end
229
+ end
230
+ ```
231
+
232
+ ### Command Aliasing
233
+
234
+ Aliases can be created using the `#alias_command` method like below:
235
+
236
+ ```ruby
237
+ command :'install gem' do |c|
238
+ c.action { puts 'foo' }
239
+ end
240
+ alias_command :'gem install', :'install gem'
241
+ ```
242
+
243
+ Or more complicated aliases can be made, passing any arguments
244
+ as if it was invoked via the command line:
245
+
246
+ ```ruby
247
+ command :'install gem' do |c|
248
+ c.syntax = 'install gem <name> [options]'
249
+ c.option '--dest DIR', String, 'Destination directory'
250
+ c.action { |args, options| puts "installing #{args.first} to #{options.dest}" }
251
+ end
252
+ alias_command :update, :'install gem', 'rubygems', '--dest', 'some_path'
253
+ ```
254
+
255
+ ```
256
+ $ foo update
257
+ # => installing rubygems to some_path
258
+ ```
259
+
260
+ ### Command Defaults
261
+
262
+ Although working with a command executable framework provides many
263
+ benefits over a single command implementation, sometimes you still
264
+ want the ability to create a terse syntax for your command. With that
265
+ in mind we may use `#default_command` to help with this. Considering
266
+ our previous `:'install gem'` example:
267
+
268
+ ```ruby
269
+ default_command :update
270
+ ```
271
+
272
+ ```
273
+ $ foo
274
+ # => installing rubygems to some_path
275
+ ```
276
+
277
+ Keeping in mind that commander searches for the longest possible match
278
+ when considering a command, so if you were to pass arguments to foo
279
+ like below, expecting them to be passed to `:update`, this would be incorrect,
280
+ and would end up calling `:'install gem'`, so be careful that the users do
281
+ not need to use command names within the arguments.
282
+
283
+ ```
284
+ $ foo install gem
285
+ # => installing to
286
+ ```
287
+
288
+ ### Additional Global Help
289
+
290
+ Arbitrary help can be added using the following `#program` symbol:
291
+
292
+ ```ruby
293
+ program :help, 'Author', 'TJ Holowaychuk <tj@vision-media.ca>'
294
+ ```
295
+
296
+ Which will output the rest of the help doc, along with:
297
+
298
+ AUTHOR:
299
+
300
+ TJ Holowaychuk <tj@vision-media.ca>
301
+
302
+ ### Global Options
303
+
304
+ Although most switches will be at the command level, several are available by
305
+ default at the global level, such as `--version`, and `--help`. Using
306
+ `#global_option` you can add additional global options:
307
+
308
+ ```ruby
309
+ global_option('-c', '--config FILE', 'Load config data for your commands to use') { |file| ... }
310
+ ```
311
+
312
+ This method accepts the same syntax as `Commander::Command#option` so check it out for documentation.
313
+
314
+ All global options regardless of providing a block are accessable at the command level. This
315
+ means that instead of the following:
316
+
317
+ ```ruby
318
+ global_option('--verbose') { $verbose = true }
319
+ ...
320
+ c.action do |args, options|
321
+ say 'foo' if $verbose
322
+ ...
323
+ ```
324
+
325
+ You may:
326
+
327
+ ```ruby
328
+ global_option '--verbose'
329
+ ...
330
+ c.action do |args, options|
331
+ say 'foo' if options.verbose
332
+ ...
333
+ ```
334
+
335
+ ### Formatters
336
+
337
+ Two core formatters are currently available, the default `Terminal` formatter
338
+ as well as `TerminalCompact`. To utilize a different formatter simply use
339
+ `:help_formatter` like below:
340
+
341
+ ```ruby
342
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
343
+ ```
344
+
345
+ Or utilize the help formatter aliases:
346
+
347
+ ```ruby
348
+ program :help_formatter, :compact
349
+ ```
350
+
351
+ This abstraction could be utilized to generate HTML documentation for your executable.
352
+
353
+ ### Tracing
354
+
355
+ By default the `-t` and `--trace` global options are provided to allow users to get a backtrace to aid debugging.
356
+
357
+ You can disable these options:
358
+
359
+ ```ruby
360
+ never_trace!
361
+ ```
362
+
363
+ Or make it always on:
364
+
365
+ ```ruby
366
+ always_trace!
367
+ ```
368
+
369
+ ## Tips
370
+
371
+ When adding a global or command option, OptionParser implicitly adds a small
372
+ switch even when not explicitly created, for example `-c` will be the same as
373
+ `--config` in both examples, however `-c` will only appear in the documentation
374
+ when explicitly assigning it.
375
+
376
+ ```ruby
377
+ global_option '-c', '--config FILE'
378
+ global_option '--config FILE'
379
+ ```
380
+
381
+ ## ASCII Tables
382
+
383
+ For feature rich ASCII tables for your terminal app check out visionmedia's terminal-table gem at http://github.com/visionmedia/terminal-table
384
+
385
+ +----------+-------+----+--------+-----------------------+
386
+ | Terminal | Table | Is | Wicked | Awesome |
387
+ +----------+-------+----+--------+-----------------------+
388
+ | | | | | get it while its hot! |
389
+ +----------+-------+----+--------+-----------------------+
390
+
391
+ ## Running Specifications
392
+
393
+ $ rake spec
394
+
395
+ OR
396
+
397
+ $ spec --color spec
398
+
399
+ ## Contrib
400
+
401
+ Feel free to fork and request a pull, or submit a ticket
402
+ http://github.com/visionmedia/commander/issues
403
+
404
+ ## License
405
+
406
+ This project is available under the MIT license. See LICENSE for details.
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Commander::VERSION
8
8
  s.authors = ["TJ Holowaychuk", "Gabriel Gilder"]
9
9
  s.email = ["ggilder@tractionco.com"]
10
+ s.license = "MIT"
10
11
  s.homepage = "http://visionmedia.github.com/commander"
11
12
  s.summary = "The complete solution for Ruby command-line executables"
12
13
  s.description = "The complete solution for Ruby command-line executables. Commander bridges the gap between other terminal related libraries you know and love (OptionParser, HighLine), while providing many new features, and an elegant API."
@@ -23,4 +24,4 @@ Gem::Specification.new do |s|
23
24
  s.add_development_dependency("rspec", "~> 2")
24
25
  s.add_development_dependency("rake")
25
26
  s.add_development_dependency("simplecov")
26
- end
27
+ end
@@ -1,8 +1,9 @@
1
1
 
2
2
  module Commander
3
3
  module Delegates
4
- %w( add_command command program run! global_option
5
- commands alias_command default_command ).each do |meth|
4
+ %w( add_command command program run! global_option
5
+ commands alias_command default_command
6
+ always_trace! never_trace! ).each do |meth|
6
7
  eval <<-END, binding, __FILE__, __LINE__
7
8
  def #{meth} *args, &block
8
9
  ::Commander::Runner.instance.#{meth} *args, &block
@@ -10,4 +11,4 @@ module Commander
10
11
  END
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -48,7 +48,7 @@ module Commander
48
48
  # Run command parsing and execution process.
49
49
 
50
50
  def run!
51
- trace = false
51
+ trace = @always_trace || false
52
52
  require_program :version, :description
53
53
  trap('INT') { abort program(:int_message) } if program(:int_message)
54
54
  trap('INT') { program(:int_block).call } if program(:int_block)
@@ -58,7 +58,7 @@ module Commander
58
58
  return
59
59
  end
60
60
  global_option('-v', '--version', 'Display version information') { say version; return }
61
- global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true }
61
+ global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true } unless @never_trace
62
62
  parse_global_options
63
63
  remove_global_options options, @args
64
64
  unless trace
@@ -72,7 +72,11 @@ module Commander
72
72
  OptionParser::MissingArgument => e
73
73
  abort e.to_s
74
74
  rescue => e
75
- abort "error: #{e}. Use --trace to view backtrace"
75
+ if @never_trace
76
+ abort "error: #{e}."
77
+ else
78
+ abort "error: #{e}. Use --trace to view backtrace"
79
+ end
76
80
  end
77
81
  else
78
82
  run_active_command
@@ -85,7 +89,23 @@ module Commander
85
89
  def version
86
90
  '%s %s' % [program(:name), program(:version)]
87
91
  end
88
-
92
+
93
+ ##
94
+ # Enable tracing on all executions (bypasses --trace)
95
+
96
+ def always_trace!
97
+ @always_trace = true
98
+ @never_trace = false
99
+ end
100
+
101
+ ##
102
+ # Hide the trace option from the help menus and don't add it as a global option
103
+
104
+ def never_trace!
105
+ @never_trace = true
106
+ @always_trace = false
107
+ end
108
+
89
109
  ##
90
110
  # Assign program information.
91
111
  #
@@ -284,7 +284,7 @@ module Commander
284
284
  $stdin.reopen read
285
285
  write.close; read.close
286
286
  Kernel.select [$stdin]
287
- ENV['LESS'] = 'FSRX'
287
+ ENV['LESS'] = 'FSRX' unless ENV.key? 'LESS'
288
288
  pager = ENV['PAGER'] || 'less'
289
289
  exec pager rescue exec '/bin/sh', '-c', pager
290
290
  else
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '4.1.5'
2
+ VERSION = '4.1.6'
3
3
  end
@@ -50,21 +50,21 @@ describe Commander::Command do
50
50
  end
51
51
 
52
52
  it "calling the #call method by default when an object is called" do
53
- object = mock 'Object'
53
+ object = double 'Object'
54
54
  object.should_receive(:call).once
55
55
  @command.when_called object
56
56
  @command.run 'foo'
57
57
  end
58
58
 
59
59
  it "should allow #action as an alias to #when_called" do
60
- object = mock 'Object'
60
+ object = double 'Object'
61
61
  object.should_receive(:call).once
62
62
  @command.action object
63
63
  @command.run 'foo'
64
64
  end
65
65
 
66
66
  it "calling an arbitrary method when an object is called" do
67
- object = mock 'Object'
67
+ object = double 'Object'
68
68
  object.should_receive(:foo).once
69
69
  @command.when_called object, :foo
70
70
  @command.run 'foo'
@@ -280,7 +280,7 @@ describe Commander do
280
280
  end.run!
281
281
  }.should raise_error(SystemExit, /error: cookies!. Use --trace/)
282
282
  end
283
-
283
+
284
284
  it "should display callstack when using this switch" do
285
285
  lambda {
286
286
  new_command_runner 'foo', '--trace' do
@@ -289,7 +289,54 @@ describe Commander do
289
289
  }.should raise_error(RuntimeError)
290
290
  end
291
291
  end
292
-
292
+
293
+ describe "#always_trace!" do
294
+ it "should enable tracing globally, regardless of whether --trace was passed or not" do
295
+ lambda {
296
+ new_command_runner 'foo' do
297
+ always_trace!
298
+ command(:foo) { |c| c.when_called { raise 'cookies!' } }
299
+ end.run!
300
+ }.should raise_error(RuntimeError)
301
+ end
302
+ end
303
+
304
+ describe "#never_trace!" do
305
+ it "should disable tracing globally, regardless of whether --trace was passed or not" do
306
+ lambda {
307
+ new_command_runner 'help', '--trace' do
308
+ never_trace!
309
+ end.run!
310
+ }.should raise_error(SystemExit, /invalid option: --trace/)
311
+ end
312
+
313
+ it "should not prompt to use --trace switch on errors" do
314
+ msg = nil
315
+ begin
316
+ new_command_runner 'foo' do
317
+ never_trace!
318
+ command(:foo) { |c| c.when_called { raise 'cookies!' } }
319
+ end.run!
320
+ rescue SystemExit => e
321
+ msg = e.message
322
+ end
323
+ msg.should match(/error: cookies!/)
324
+ msg.should_not match(/--trace/)
325
+ end
326
+ end
327
+
328
+ context "conflict between #always_trace! and #never_trace!" do
329
+ it "respects the last used command" do
330
+ lambda {
331
+ new_command_runner 'foo' do
332
+ never_trace!
333
+ always_trace!
334
+ command(:foo) { |c| c.when_called { raise 'cookies!' } }
335
+ end.run!
336
+ }.should raise_error(RuntimeError)
337
+ end
338
+ end
339
+
293
340
  describe "--version" do
294
341
  it "should output program version" do
295
342
  run('--version').should eq("test 1.2.3\n")
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
5
- prerelease:
4
+ version: 4.1.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - TJ Holowaychuk
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-08-11 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: highline
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rspec
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ~>
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ~>
45
40
  - !ruby/object:Gem::Version
@@ -47,33 +42,29 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rake
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: simplecov
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  description: The complete solution for Ruby command-line executables. Commander bridges
@@ -91,8 +82,9 @@ files:
91
82
  - DEVELOPMENT
92
83
  - Gemfile
93
84
  - History.rdoc
85
+ - LICENSE
94
86
  - Manifest
95
- - README.rdoc
87
+ - README.md
96
88
  - Rakefile
97
89
  - bin/commander
98
90
  - commander.gemspec
@@ -124,28 +116,28 @@ files:
124
116
  - spec/spec_helper.rb
125
117
  - spec/ui_spec.rb
126
118
  homepage: http://visionmedia.github.com/commander
127
- licenses: []
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
128
122
  post_install_message:
129
123
  rdoc_options: []
130
124
  require_paths:
131
125
  - lib
132
126
  required_ruby_version: !ruby/object:Gem::Requirement
133
- none: false
134
127
  requirements:
135
- - - ! '>='
128
+ - - '>='
136
129
  - !ruby/object:Gem::Version
137
130
  version: '0'
138
131
  required_rubygems_version: !ruby/object:Gem::Requirement
139
- none: false
140
132
  requirements:
141
- - - ! '>='
133
+ - - '>='
142
134
  - !ruby/object:Gem::Version
143
135
  version: '0'
144
136
  requirements: []
145
137
  rubyforge_project: commander
146
- rubygems_version: 1.8.22
138
+ rubygems_version: 2.2.1
147
139
  signing_key:
148
- specification_version: 3
140
+ specification_version: 4
149
141
  summary: The complete solution for Ruby command-line executables
150
142
  test_files:
151
143
  - spec/command_spec.rb
@@ -1,372 +0,0 @@
1
- {<img src="https://secure.travis-ci.org/ggilder/commander.png?branch=master" alt="Build Status" />}[http://travis-ci.org/ggilder/commander]
2
-
3
- = Commander
4
-
5
- The complete solution for Ruby command-line executables.
6
- Commander bridges the gap between other terminal related libraries
7
- you know and love (OptionParser, HighLine), while providing many new
8
- features, and an elegant API.
9
-
10
- == Features
11
-
12
- * Easier than baking cookies
13
- * Parses options using OptionParser
14
- * Auto-populates struct with options ( no more { |v| options[:recursive] = v } )
15
- * Auto-generates help documentation via pluggable help formatters
16
- * Optional default command when none is present
17
- * Global / Command level options
18
- * Packaged with two help formatters (Terminal, TerminalCompact)
19
- * Imports the highline gem for interacting with the terminal
20
- * Adds additional user interaction functionality
21
- * Highly customizable progress bar with intuitive, simple usage
22
- * Multi-word command name support such as 'drupal module install MOD', rather than 'drupal module_install MOD'
23
- * Sexy paging for long bodies of text
24
- * Support for MacOS text-to-speech
25
- * Command aliasing (very powerful, as both switches and arguments can be used)
26
- * Growl notification support for MacOS
27
- * Use the 'commander' executable to initialize a commander driven program
28
-
29
- == Installation
30
-
31
- $ gem install commander
32
-
33
- == Quick Start
34
-
35
- To generate a quick template for a commander app, run:
36
-
37
- $ commander init yourfile.rb
38
-
39
- == Example
40
-
41
- For more option examples view the Commander::Command#option method. Also
42
- an important feature to note is that action may be a class to instantiate,
43
- as well as an object, specifying a method to call, so view the RDoc for more information.
44
-
45
- require 'rubygems'
46
- require 'commander/import'
47
-
48
- # :name is optional, otherwise uses the basename of this executable
49
- program :name, 'Foo Bar'
50
- program :version, '1.0.0'
51
- program :description, 'Stupid command that prints foo or bar.'
52
-
53
- command :foo do |c|
54
- c.syntax = 'foobar foo'
55
- c.description = 'Displays foo'
56
- c.action do |args, options|
57
- say 'foo'
58
- end
59
- end
60
-
61
- command :bar do |c|
62
- c.syntax = 'foobar bar [options]'
63
- c.description = 'Display bar with optional prefix and suffix'
64
- c.option '--prefix STRING', String, 'Adds a prefix to bar'
65
- c.option '--suffix STRING', String, 'Adds a suffix to bar'
66
- c.action do |args, options|
67
- options.default :prefix => '(', :suffix => ')'
68
- say "#{options.prefix}bar#{options.suffix}"
69
- end
70
- end
71
-
72
- $ foobar bar
73
- # => (bar)
74
-
75
- $ foobar bar --suffix '}' --prefix '{'
76
- # => {bar}
77
-
78
- == HighLine
79
-
80
- As mentioned above the highline gem is imported into 'global scope', below
81
- are some quick examples for how to utilize highline in your command(s):
82
-
83
- # Ask for password masked with '*' character
84
- ask("Password: ") { |q| q.echo = "*" }
85
-
86
- # Ask for password
87
- ask("Password: ") { |q| q.echo = false }
88
-
89
- # Ask if the user agrees (yes or no)
90
- agree("Do something?")
91
-
92
- # Asks on a single line (note the space after ':')
93
- ask("Name: ")
94
-
95
- # Asks with new line after "Description:"
96
- ask("Description:")
97
-
98
- # Calls Date#parse to parse the date string passed
99
- ask("Birthday? ", Date)
100
-
101
- # Ensures Integer is within the range specified
102
- ask("Age? ", Integer) { |q| q.in = 0..105 }
103
-
104
- # Asks for a list of strings, converts to array
105
- ask("Fav colors?", Array)
106
-
107
- == HighLine & Interaction Additions
108
-
109
- In addition to highline's fantastic choice of methods, commander adds the
110
- following methods to simplify common tasks:
111
-
112
- # Ask for password
113
- password
114
-
115
- # Ask for password with specific message and mask character
116
- password "Enter your password please:", '-'
117
-
118
- # Ask for CLASS, which may be any valid class responding to #parse. Date, Time, Array, etc
119
- names = ask_for_array 'Names: '
120
- bday = ask_for_date 'Birthday?: '
121
-
122
- # Simple progress bar (Commander::UI::ProgressBar)
123
- uris = %w[
124
- http://vision-media.ca
125
- http://google.com
126
- http://yahoo.com
127
- ]
128
- progress uris do |uri|
129
- res = open uri
130
- # Do something with response
131
- end
132
-
133
- # 'Log' action to stdout
134
- log "create", "path/to/file.rb"
135
-
136
- # Enable paging of output after this point
137
- enable_paging
138
-
139
- # Ask editor for input (EDITOR environment variable or whichever is available: TextMate, vim, vi, emacs, nano, pico)
140
- ask_editor
141
-
142
- # Ask editor, supplying initial text
143
- ask_editor 'previous data to update'
144
-
145
- # Ask editor, preferring a specific editor
146
- ask_editor 'previous data', 'vim'
147
-
148
- # Choose from an array of elements
149
- choice = choose("Favorite language?", :ruby, :perl, :js)
150
-
151
- # Alter IO for the duration of the block
152
- io new_input, new_output do
153
- new_input_contents = $stdin.read
154
- puts new_input_contents # outputs to new_output stream
155
- end
156
- # $stdin / $stdout reset back to original streams
157
-
158
- # Speech synthesis
159
- speak 'What is your favorite food? '
160
- food = ask 'favorite food?: '
161
- speak "Wow, I like #{food} too. We have so much in common."
162
- speak "I like #{food} as well!", "Victoria", 190
163
-
164
- # Execute arbitrary applescript
165
- applescript 'foo'
166
-
167
- # Converse with speech recognition server
168
- case converse 'What is the best food?', :cookies => 'Cookies', :unknown => 'Nothing'
169
- when :cookies
170
- speak 'o.m.g. you are awesome!'
171
- else
172
- case converse 'That is lame, shall I convince you cookies are the best?', :yes => 'Ok', :no => 'No', :maybe => 'Maybe another time'
173
- when :yes
174
- speak 'Well you see, cookies are just fantastic, they melt in your mouth.'
175
- else
176
- speak 'Ok then, bye.'
177
- end
178
- end
179
-
180
- == Growl Notifications
181
-
182
- Commander provides methods for displaying Growl notifications. To use these
183
- methods you need to install http://github.com/visionmedia/growl which utilizes
184
- the growlnotify[http://growl.info/extras.php#growlnotify] executable. Note that
185
- growl is auto-imported by Commander when available, no need to require.
186
-
187
- # Display a generic Growl notification
188
- notify 'Something happened'
189
-
190
- # Display an 'info' status notification
191
- notify_info 'You have #{emails.length} new email(s)'
192
-
193
- # Display an 'ok' status notification
194
- notify_ok 'Gems updated'
195
-
196
- # Display a 'warning' status notification
197
- notify_warning '1 gem failed installation'
198
-
199
- # Display an 'error' status notification
200
- notify_error "Gem #{name} failed"
201
-
202
- == Commander Goodies
203
-
204
- === Option Defaults
205
-
206
- The options struct passed to #action provides a #default method, allowing you
207
- to set defaults in a clean manner for options which have not been set.
208
-
209
- command :foo do |c|
210
- c.option '--interval SECONDS', Integer, 'Interval in seconds'
211
- c.option '--timeout SECONDS', Integer, 'Timeout in seconds'
212
- c.action do |args, options|
213
- options.default \
214
- :interval => 2,
215
- :timeout => 60
216
- end
217
- end
218
-
219
- === Command Aliasing
220
-
221
- Aliases can be created using the #alias_command method like below:
222
-
223
- command :'install gem' do |c|
224
- c.action { puts 'foo' }
225
- end
226
- alias_command :'gem install', :'install gem'
227
-
228
- Or more complicated aliases can be made, passing any arguments
229
- as if it was invoked via the command line:
230
-
231
- command :'install gem' do |c|
232
- c.syntax = 'install gem <name> [options]'
233
- c.option '--dest DIR', String, 'Destination directory'
234
- c.action { |args, options| puts "installing #{args.first} to #{options.dest}" }
235
- end
236
- alias_command :update, :'install gem', 'rubygems', '--dest', 'some_path'
237
-
238
- $ foo update
239
- # => installing rubygems to some_path
240
-
241
- === Command Defaults
242
-
243
- Although working with a command executable framework provides many
244
- benefits over a single command implementation, sometimes you still
245
- want the ability to create a terse syntax for your command. With that
246
- in mind we may use #default_command to help with this. Considering
247
- our previous :'install gem' example:
248
-
249
- default_command :update
250
-
251
- $ foo
252
- # => installing rubygems to some_path
253
-
254
- Keeping in mind that commander searches for the longest possible match
255
- when considering a command, so if you were to pass arguments to foo
256
- like below, expecting them to be passed to :update, this would be incorrect,
257
- and would end up calling :'install gem', so be careful that the users do
258
- not need to use command names within the arguments.
259
-
260
- $ foo install gem
261
- # => installing to
262
-
263
- === Additional Global Help
264
-
265
- Arbitrary help can be added using the following #program symbol:
266
-
267
- program :help, 'Author', 'TJ Holowaychuk <tj@vision-media.ca>'
268
-
269
- Which will output the rest of the help doc, along with:
270
-
271
- AUTHOR:
272
-
273
- TJ Holowaychuk <tj@vision-media.ca>
274
-
275
- === Global Options
276
-
277
- Although most switches will be at the command level, several are available
278
- by default at the global level, such as --version, and --help. Using #global_option
279
- you can add additional global options:
280
-
281
- global_option('-c', '--config FILE', 'Load config data for your commands to use') { |file| ... }
282
-
283
- This method accepts the same syntax as Commander::Command#option so check it out for documentation.
284
-
285
- All global options regardless of providing a block are accessable at the command level. This
286
- means that instead of the following:
287
-
288
- global_option('--verbose') { $verbose = true }
289
- ...
290
- c.action do |args, options|
291
- say 'foo' if $verbose
292
- ...
293
-
294
- You may:
295
-
296
- global_option '--verbose'
297
- ...
298
- c.action do |args, options|
299
- say 'foo' if options.verbose
300
- ...
301
-
302
- === Formatters
303
-
304
- Two core formatters are currently available, the default Terminal formatter as well
305
- as TerminalCompact. To utilize a different formatter simply use :help_formatter like below:
306
-
307
- program :help_formatter, Commander::HelpFormatter::TerminalCompact
308
-
309
- Or utilize the help formatter aliases:
310
-
311
- program :help_formatter, :compact
312
-
313
- This abstraction could be utilized to generate HTML documentation for your executable.
314
-
315
- == Tips
316
-
317
- When adding a global or command option, OptionParser implicitly adds a small
318
- switch even when not explicitly created, for example -c will be the same as --config
319
- in both examples, however '-c' will only appear in the documentation when explicitly
320
- assigning it.
321
-
322
- global_option '-c', '--config FILE'
323
- global_option '--config FILE'
324
-
325
- == ASCII Tables
326
-
327
- For feature rich ASCII tables for your terminal app check out visionmedia's terminal-table gem at
328
- http://github.com/visionmedia/terminal-table
329
-
330
- +----------+-------+----+--------+-----------------------+
331
- | Terminal | Table | Is | Wicked | Awesome |
332
- +----------+-------+----+--------+-----------------------+
333
- | | | | | get it while its hot! |
334
- +----------+-------+----+--------+-----------------------+
335
-
336
- == Running Specifications
337
-
338
- $ rake spec
339
-
340
- OR
341
-
342
- $ spec --color spec
343
-
344
- == Contrib
345
-
346
- Feel free to fork and request a pull, or submit a ticket
347
- http://github.com/visionmedia/commander/issues
348
-
349
- == License
350
-
351
- (The MIT License)
352
-
353
- Copyright (c) 2008-2009 TJ Holowaychuk <tj@vision-media.ca>
354
-
355
- Permission is hereby granted, free of charge, to any person obtaining
356
- a copy of this software and associated documentation files (the
357
- 'Software'), to deal in the Software without restriction, including
358
- without limitation the rights to use, copy, modify, merge, publish,
359
- distribute, sublicense, and/or sell copies of the Software, and to
360
- permit persons to whom the Software is furnished to do so, subject to
361
- the following conditions:
362
-
363
- The above copyright notice and this permission notice shall be
364
- included in all copies or substantial portions of the Software.
365
-
366
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
367
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
368
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
369
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
370
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
371
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
372
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.