Open robertgates55 opened 3 years ago
Hmm, the invocation in your example is missing a command, which I think is what commander is complaining about. If you run the following does it work?
ruby yourfile.rb bob --some-switch --help
Hmm, the invocation in your example is missing a command, which I think is what commander is complaining about. If you run the following does it work?
ruby yourfile.rb bob --some-switch --help
It outputs nothing, exit code 0.
Altering the test file a little:
#!/usr/bin/env ruby
require 'rubygems'
require 'commander'
class MyApplication
include Commander::Methods
# include whatever modules you need
def run
program :name, 'test'
program :version, '0.0.1'
program :description, 'test'
global_option('--aaa AAA', Integer, 'Test AAA')
command :bob do |c|
c.syntax = 'test bob [options]'
c.summary = ''
c.description = ''
c.example 'description', 'command example'
c.option '--value VALUE', 'Some switch that does something'
c.action do |args, options|
# Do something or c.when_called Test::Commands::Bob
puts "Got value: #{options.value}"
puts "Got aaa: #{options.aaa}"
end
end
run!
end
end
MyApplication.new.run if $0 == __FILE__
Command: ruby yourfile.rb bob --help
or ruby yourfile.rb --help bob
Output:
<the help text omitted for brevity>
Good :+1:
Command: ruby yourfile.rb bob --aaa=3 --value=4
Output:
Got value: 4
Got aaa: 3
This is as expected. :+1:
Command: ruby yourfile.rb bob --aaa=3 --value=4 --help
or ruby yourfile.rb bob --aaa=3 --help --value=4
Output:
Got value: 4
Got aaa: 3
Expectation is the help output you get with: ruby yourfile.rb bob --help
Command: ruby yourfile.rb bob --help --aaa=3 --value=4
or ruby yourfile.rb --help bob --aaa=3 --value=4
Got value: 4
Got aaa:
Curious, would maybe expect aaa
to be populated. But really, expectation is the help output you get with: ruby yourfile.rb bob --help
A and B are normal behaviour.
For C and D it is desired that the presence of --help
means that the help text is shown rather than the command being processed.
I often find mysql wanting to put
--help
on the end of a command to see the help text for that command. With commander, if I do that though, I first have to remove any --option options passed or I get 'command not found'Example:
Results in:
Is there any way to make this possible?