gli 2.6.0.rc1 → 2.6.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.
@@ -27,7 +27,7 @@ Feature: The GLI executable works as intended
27
27
  -n - Dry run; dont change the disk
28
28
  -r, --root=arg - Root dir of project (default: .)
29
29
  -v - Be verbose
30
- --version -
30
+ --version - Display the program version
31
31
 
32
32
  COMMANDS
33
33
  help - Shows a list of commands or help for one command
@@ -66,7 +66,7 @@ Feature: The scaffold GLI generates works
66
66
  the default)
67
67
  --help - Show this message
68
68
  -s, --[no-]switch - Describe some switch here
69
- --version -
69
+ --version - Display the program version
70
70
 
71
71
  COMMANDS
72
72
  add - Describe add here
@@ -92,7 +92,7 @@ Feature: The scaffold GLI generates works
92
92
  the default)
93
93
  --help - Show this message
94
94
  -s, --[no-]switch - Describe some switch here
95
- --version -
95
+ --version - Display the program version
96
96
 
97
97
  COMMANDS
98
98
  add - Describe add here
@@ -36,7 +36,7 @@ Feature: The todo app has a nice user interface
36
36
  --help - Show this message
37
37
  --[no-]otherswitch -
38
38
  --[no-]switch -
39
- --version -
39
+ --version - Display the program version
40
40
 
41
41
  COMMANDS
42
42
  chained -
@@ -54,7 +54,13 @@ Feature: The todo app has a nice user interface
54
54
  Examples:
55
55
  | help |
56
56
  | help |
57
- | --version |
57
+
58
+ Scenario: Version display
59
+ When I successfully run `todo --version`
60
+ Then the output should contain:
61
+ """
62
+ todo version 0.0.1
63
+ """
58
64
 
59
65
  Scenario: Help completion mode
60
66
  When I successfully run `todo help -c`
@@ -121,7 +127,7 @@ Feature: The todo app has a nice user interface
121
127
  --flag=arg - (default: none)
122
128
  --[no-]switch -
123
129
  --[no-]otherswitch -
124
- --version -
130
+ --version - Display the program version
125
131
  --help - Show this message
126
132
 
127
133
  COMMANDS
@@ -171,6 +177,17 @@ Feature: The todo app has a nice user interface
171
177
  | list --help |
172
178
 
173
179
 
180
+ Scenario: Getting Help for a top level command of todo with no command options
181
+ When I successfully run `todo help chained`
182
+ Then the output should contain:
183
+ """
184
+ NAME
185
+ chained -
186
+
187
+ SYNOPSIS
188
+ todo [global options] chained
189
+ """
190
+
174
191
  Scenario: Getting Help with no wrapping
175
192
  Given the todo app is coded to avoid wrapping text
176
193
  When I successfully run `todo help list`
@@ -280,9 +297,9 @@ Feature: The todo app has a nice user interface
280
297
  create - Create a new task or context
281
298
 
282
299
  SYNOPSIS
283
- todo [global options] create [command options]
284
- todo [global options] create [command options] contexts [context_name]
285
- todo [global options] create [command options] tasks task_name[, task_name]*
300
+ todo [global options] create
301
+ todo [global options] create contexts [context_name]
302
+ todo [global options] create tasks task_name[, task_name]*
286
303
 
287
304
  COMMANDS
288
305
  <default> - Makes a new task
@@ -88,9 +88,9 @@ Feature: The todo app is backwards compatible with legacy subcommand parsing
88
88
  create - Create a new task or context
89
89
 
90
90
  SYNOPSIS
91
- todo [global options] create [command options]
92
- todo [global options] create [command options] contexts [context_name]
93
- todo [global options] create [command options] tasks task_name[, task_name]*
91
+ todo [global options] create
92
+ todo [global options] create contexts [context_name]
93
+ todo [global options] create tasks task_name[, task_name]*
94
94
 
95
95
  COMMANDS
96
96
  <default> - Makes a new task
@@ -25,7 +25,8 @@ spec = Gem::Specification.new do |s|
25
25
  s.add_development_dependency('rdoc', '~> 3.11')
26
26
  s.add_development_dependency('rainbow', '~> 1.1.1')
27
27
  s.add_development_dependency('clean_test')
28
- s.add_development_dependency('aruba')
28
+ s.add_development_dependency('cucumber', '1.2.3')
29
+ s.add_development_dependency('aruba', '0.5.1') # 0.5.3 randomly breaks with "LaunchError: no such file or directory" and only sometimes.
29
30
  s.add_development_dependency('sdoc')
30
31
  s.add_development_dependency('faker','1.0.0')
31
32
  end
@@ -104,7 +104,7 @@ module GLI
104
104
  # the command specified will not be executed.
105
105
  # The block will receive the global-options,command,options, and arguments
106
106
  # If this block evaluates to true, the program will proceed; otherwise
107
- # the program will end immediately
107
+ # the program will end immediately and exit nonzero
108
108
  def pre(&a_proc)
109
109
  @pre_block = a_proc
110
110
  end
@@ -157,6 +157,7 @@ module GLI
157
157
  # +version+:: String containing the version of your application.
158
158
  def version(version)
159
159
  @version = version
160
+ desc 'Display the program version'
160
161
  switch :version, :negatable => false
161
162
  end
162
163
 
@@ -31,6 +31,10 @@ module GLI
31
31
  clear_nexts
32
32
  end
33
33
 
34
+ def exe_name
35
+ File.basename($0)
36
+ end
37
+
34
38
  # Get an array of commands, ordered by when they were declared
35
39
  def commands_declaration_order # :nodoc:
36
40
  @commands_declaration_order
@@ -71,8 +75,12 @@ module GLI
71
75
 
72
76
  the_command = parsing_result.command
73
77
 
74
- call_command(parsing_result) if proceed?(parsing_result)
75
- 0
78
+ if proceed?(parsing_result)
79
+ call_command(parsing_result)
80
+ 0
81
+ else
82
+ exit_now!(nil,65)
83
+ end
76
84
  rescue Exception => ex
77
85
  if the_command.nil? && ex.respond_to?(:command_in_context)
78
86
  the_command = ex.command_in_context
@@ -23,7 +23,7 @@ module GLI
23
23
  flag :format
24
24
 
25
25
  action do |global_options,options,arguments|
26
- self.document(format_class(options[:format]).new(global_options,options,arguments))
26
+ self.document(format_class(options[:format]).new(global_options,options,arguments,app))
27
27
  end
28
28
  end
29
29
 
@@ -54,6 +54,12 @@ module GLI
54
54
 
55
55
  # Interface for a listener that is called during various parts of the doc process
56
56
  class DocumentListener
57
+ def initialize(global_options,options,arguments,app)
58
+ @global_options = global_options
59
+ @options = options
60
+ @arguments = arguments
61
+ @app = app
62
+ end
57
63
  # Called before processing begins
58
64
  def beginning
59
65
  abstract!
@@ -60,7 +60,11 @@ module GLI
60
60
  switch :c
61
61
 
62
62
  action do |global_options,options,arguments|
63
- show_help(global_options,options,arguments,output,error)
63
+ if global_options[:version] && !global_options[:help]
64
+ puts "#{@app.exe_name} version #{@app.version_string}"
65
+ else
66
+ show_help(global_options,options,arguments,output,error)
67
+ end
64
68
  end
65
69
  end
66
70
 
@@ -81,7 +85,7 @@ module GLI
81
85
  name = arguments.shift
82
86
  command = command_finder.find_command(name)
83
87
  unless command.nil?
84
- out.puts HelpModules::CommandHelpFormat.new(command,@app,File.basename($0).to_s,@sorter,@text_wrapping_class).format
88
+ out.puts HelpModules::CommandHelpFormat.new(command,@app,@app.exe_name.to_s,@sorter,@text_wrapping_class).format
85
89
  end
86
90
  end
87
91
  end
@@ -47,7 +47,7 @@ module GLI
47
47
  if command.nil?
48
48
  @last_unknown_command = name
49
49
  unless @squelch_stderr
50
- error.puts "error: Unknown command '#{name}'. Use '#{File.basename($PROGRAM_NAME)} help' for a list of commands."
50
+ error.puts "error: Unknown command '#{name}'. Use '#{@app.exe_name} help' for a list of commands."
51
51
  end
52
52
  true
53
53
  else
@@ -98,8 +98,10 @@ COMMANDS
98
98
 
99
99
  def basic_usage
100
100
  usage = @basic_invocation.dup
101
- usage << " [global options] #{path_to_command} "
102
- usage << "[command options] " unless global_flags_and_switches.empty?
101
+ usage << " [global options]" unless global_flags_and_switches.empty?
102
+ usage << " #{path_to_command}"
103
+ usage << " [command options]" unless flags_and_switches(@command,@app).empty?
104
+ usage << " "
103
105
  usage
104
106
  end
105
107
 
@@ -35,7 +35,7 @@ module GLI
35
35
  private
36
36
 
37
37
  GLOBAL_HELP = ERB.new(%q(NAME
38
- <%= File.basename($0) %> - <%= program_desc %>
38
+ <%= @app.exe_name %> - <%= program_desc %>
39
39
  <%= program_long_desc %>
40
40
  SYNOPSIS
41
41
  <%= usage_string %>
@@ -58,7 +58,7 @@ COMMANDS
58
58
  end
59
59
 
60
60
  def usage_string
61
- "#{File.basename($0)} ".tap do |string|
61
+ "#{@app.exe_name} ".tap do |string|
62
62
  string << "[global options] " unless global_flags_and_switches.empty?
63
63
  string << "command "
64
64
  string << "[command options] [arguments...]"
@@ -1,6 +1,7 @@
1
1
  require 'gli'
2
2
  require 'gli/command'
3
3
  require 'yaml'
4
+ require 'fileutils'
4
5
 
5
6
  module GLI
6
7
  # Command that initializes the configuration file for apps that use it.
@@ -4,8 +4,8 @@ module GLI
4
4
  module Commands
5
5
  class RdocDocumentListener
6
6
 
7
- def initialize(global_options,options,arguments)
8
- @io = File.new(File.basename($0) + ".rdoc",'w')
7
+ def initialize(global_options,options,arguments,app)
8
+ @io = File.new("#{app.exe_name}.rdoc",'w')
9
9
  @nest = ''
10
10
  @arg_name_formatter = GLI::Commands::HelpModules::ArgNameFormatter.new
11
11
  end
@@ -20,7 +20,7 @@ module GLI
20
20
 
21
21
  # Gives you the program description
22
22
  def program_desc(desc)
23
- @io.puts "== #{File.basename($0)} - #{desc}"
23
+ @io.puts "== #{@app.exe_name} - #{desc}"
24
24
  @io.puts
25
25
  end
26
26
 
@@ -59,6 +59,10 @@ module GLI
59
59
  lambda { (jruby? || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput') },
60
60
  lambda { [run_command('tput cols').to_i, run_command('tput lines').to_i] }
61
61
  ],
62
+ [
63
+ lambda { (solaris? && STDIN.tty? && command_exists?('stty')) },
64
+ lambda { run_command('stty').split("\n")[1].scan(/\d+/)[0..1].map { |size_element| size_element.to_i }.reverse }
65
+ ],
62
66
  [
63
67
  lambda { STDIN.tty? && command_exists?('stty') },
64
68
  lambda { run_command('stty size').scan(/\d+/).map { |size_element| size_element.to_i }.reverse }
@@ -90,5 +94,8 @@ module GLI
90
94
  # True if we are JRuby; exposed to allow for testing
91
95
  def self.jruby?; RUBY_PLATFORM =~ /java/; end
92
96
 
97
+ # True if this is running under Solaris Sparc
98
+ def self.solaris?; RUBY_PLATFORM =~ /solaris/; end
99
+
93
100
  end
94
101
  end
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.6.0.rc1'
3
+ VERSION = '2.6.0'
4
4
  end
5
5
  end
@@ -351,6 +351,14 @@ class TC_testCommand < Clean::Test::TestCase
351
351
  assert_equal [:blah], command.aliases
352
352
  end
353
353
 
354
+ def test_pre_exiting_false_causes_nonzero_exit
355
+ @app.pre { |*| false }
356
+
357
+ assert_equal 65,@app.run(["bs"]) # BSD for "input data incorrect in some way"
358
+ assert_equal '',@fake_stderr.to_s
359
+ assert_equal '',@fake_stdout.to_s
360
+ end
361
+
354
362
  private
355
363
 
356
364
  def assert_contained(output,regexp)
@@ -252,6 +252,7 @@ switch: s
252
252
  long_desc: switch long_desc 5
253
253
  negatable: false
254
254
  switch: version
255
+ desc: Display the program version
255
256
  negatable: false
256
257
  command: command1
257
258
  aliases: com1
@@ -157,6 +157,95 @@ class TC_testHelp < Clean::Test::TestCase
157
157
  }
158
158
  end
159
159
 
160
+ test_that "invoking help with a known command when no global options are present omits [global options] from the usage string" do
161
+ Given a_GLI_app(:no_options)
162
+ And {
163
+ @command_name = cm = any_command_name
164
+ @desc = d = any_desc
165
+ @long_desc = ld = any_desc
166
+ @switch = s = any_option
167
+ @switch_desc = sd = any_desc
168
+ @flag = f = any_option
169
+ @flag_desc = fd = any_desc
170
+
171
+ @app.instance_eval do
172
+ desc d
173
+ long_desc ld
174
+ command cm do |c|
175
+
176
+ c.desc sd
177
+ c.switch s
178
+
179
+ c.desc fd
180
+ c.flag f
181
+
182
+ c.action {}
183
+ end
184
+ end
185
+ @command = GLI::Commands::Help.new(@app,@output,@error)
186
+ }
187
+ When {
188
+ @command.execute({},{},[@command_name])
189
+ }
190
+ Then {
191
+ refute_output_contained(/\[global options\]/)
192
+ assert_output_contained(/\[command options\]/)
193
+ assert_output_contained('COMMAND OPTIONS')
194
+ }
195
+ end
196
+
197
+ test_that "invoking help with a known command when no global options nor command options are present omits [global options] and [command options] from the usage string" do
198
+ Given a_GLI_app(:no_options)
199
+ And {
200
+ @command_name = cm = any_command_name
201
+ @desc = d = any_desc
202
+ @long_desc = ld = any_desc
203
+
204
+ @app.instance_eval do
205
+ desc d
206
+ long_desc ld
207
+ command cm do |c|
208
+ c.action {}
209
+ end
210
+ end
211
+ @command = GLI::Commands::Help.new(@app,@output,@error)
212
+ }
213
+ When {
214
+ @command.execute({},{},[@command_name])
215
+ }
216
+ Then {
217
+ refute_output_contained(/\[global options\]/)
218
+ refute_output_contained(/\[command options\]/)
219
+ refute_output_contained('COMMAND OPTIONS')
220
+ }
221
+ end
222
+
223
+ test_that "invoking help with a known command that has no command options omits [command options] from the usage string" do
224
+ Given a_GLI_app
225
+ And {
226
+ @command_name = cm = any_command_name
227
+ @desc = d = any_desc
228
+ @long_desc = ld = any_desc
229
+
230
+ @app.instance_eval do
231
+ desc d
232
+ long_desc ld
233
+ command cm do |c|
234
+ c.action {}
235
+ end
236
+ end
237
+ @command = GLI::Commands::Help.new(@app,@output,@error)
238
+ }
239
+ When {
240
+ @command.execute({},{},[@command_name])
241
+ }
242
+ Then {
243
+ assert_output_contained(/\[global options\]/)
244
+ refute_output_contained(/\[command options\]/)
245
+ refute_output_contained('COMMAND OPTIONS')
246
+ }
247
+ end
248
+
160
249
  test_that "omitting default_description doesn't blow up" do
161
250
  Given {
162
251
  app = TestApp.new
@@ -60,12 +60,14 @@ class TC_testTerminal < Clean::Test::TestCase
60
60
  return '1234' if command == 'tput lines'
61
61
  else
62
62
  return '1234 5678' if command == 'stty size'
63
+ return '1234 5678' if command == 'stty'
63
64
  end
64
65
 
65
66
  raise "Unexpected command called: #{command} for #{RUBY_PLATFORM}"
66
67
  end
67
68
  def command_exists?(command); true; end
68
69
  def jruby?; false; end
70
+ def solaris?; false; end
69
71
  end
70
72
  ENV['COLUMNS'] = 'foo'
71
73
  assert_equal [5678,1234],terminal.size
@@ -77,6 +79,7 @@ class TC_testTerminal < Clean::Test::TestCase
77
79
  GLI::Terminal.instance_eval do
78
80
  def command_exists?(command); false; end
79
81
  def jruby?; false; end
82
+ def solaris?; false; end
80
83
  end
81
84
  ENV['COLUMNS'] = 'foo'
82
85
  assert_equal [80,24],terminal.size
@@ -89,6 +92,7 @@ class TC_testTerminal < Clean::Test::TestCase
89
92
  terminal = GLI::Terminal.new
90
93
  GLI::Terminal.instance_eval do
91
94
  def jruby?; raise "Problem"; end
95
+ def solaris?; false; end
92
96
  end
93
97
  ENV['COLUMNS'] = 'foo'
94
98
  assert_equal [80,24],terminal.size
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0.rc1
5
- prerelease: 6
4
+ version: 2.6.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Copeland
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-15 00:00:00.000000000 Z
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -75,22 +75,38 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.2.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.3
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: aruba
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
83
- - - ! '>='
99
+ - - '='
84
100
  - !ruby/object:Gem::Version
85
- version: '0'
101
+ version: 0.5.1
86
102
  type: :development
87
103
  prerelease: false
88
104
  version_requirements: !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
- - - ! '>='
107
+ - - '='
92
108
  - !ruby/object:Gem::Version
93
- version: '0'
109
+ version: 0.5.1
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: sdoc
96
112
  requirement: !ruby/object:Gem::Requirement
@@ -365,15 +381,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
365
381
  - - ! '>='
366
382
  - !ruby/object:Gem::Version
367
383
  version: '0'
368
- segments:
369
- - 0
370
- hash: -2077859074459195456
371
384
  required_rubygems_version: !ruby/object:Gem::Requirement
372
385
  none: false
373
386
  requirements:
374
- - - ! '>'
387
+ - - ! '>='
375
388
  - !ruby/object:Gem::Version
376
- version: 1.3.1
389
+ version: '0'
377
390
  requirements: []
378
391
  rubyforge_project: gli
379
392
  rubygems_version: 1.8.25