Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--help with additional --options gives 'command not found' #97

Open
robertgates55 opened this issue Sep 22, 2020 · 2 comments
Open

--help with additional --options gives 'command not found' #97

robertgates55 opened this issue Sep 22, 2020 · 2 comments

Comments

@robertgates55
Copy link

robertgates55 commented Sep 22, 2020

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:

#!/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'

    command :bob do |c|
      c.syntax = 'test bob [options]'
      c.summary = ''
      c.description = ''
      c.example 'description', 'command example'
      c.option '--some-switch', 'Some switch that does something'
      c.action do |args, options|
        # Do something or c.when_called Test::Commands::Bob
      end
    end

    run!
  end
end

MyApplication.new.run if $0 == __FILE__

Results in:

➜  ruby yourfile.rb --some-switch --help
invalid command. Use --help for more information

Is there any way to make this possible?

@ggilder
Copy link
Member

ggilder commented Sep 29, 2020

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

@duco-lw
Copy link

duco-lw commented Sep 30, 2020

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__

A

Command: ruby yourfile.rb bob --help or ruby yourfile.rb --help bob
Output:

<the help text omitted for brevity>

Good 👍

B

Command: ruby yourfile.rb bob --aaa=3 --value=4
Output:

Got value: 4
Got aaa: 3

This is as expected. 👍

C

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

D

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

Summary

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants