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

Overriding command-line --help 'usage' section #24

Open
justfalter opened this issue Aug 18, 2014 · 0 comments
Open

Overriding command-line --help 'usage' section #24

justfalter opened this issue Aug 18, 2014 · 0 comments

Comments

@justfalter
Copy link

Right now, '--help' outputs a rather generic 'usage' line:

usage: foo.rb [...--param=val...]

The only thing that changes is the script file name.

I'm writing a script that accepts one of several commands ('list', 'run', 'help') before handing things over to configliere for parsing.

Unfortunately, I can't seem to cleanly override the usage output such that:

$ foo.rb
usage: foo.rb [command]

Commands:
   run  - run some stuff
   list   - list stuff to run
   help - get some help
$ foo.rb run --help
usage: foo.rb run [...--param=val...]

Params:
     bla bla bla
$ foo.rb list --help
usage: foo.rb list [...--param=val...]

Params:
     bla bla bla

It's trivial to parse the 'command' from ARGV (just an ARGV.shift) and then directing things to the appropriate instance of Configliere::Param.

Looking at Configliere::Commandline, it appears that there might have been some intent to support overriding the parsers 'usage', as there is an an 'attr_writer :usage'.

The only way I've managed to override the usage was by doing something like:

    params = Configliere::Param.new
    params.use(:commandline)
    my_usage_mod = Module.new do
      def usage
         "usage: #{raw_script_name} run [...-param=val...]"
      end
    end
    params.extend  my_usage_mod

I've no problem tweaking things and sending a pull request. I just wanted to make sure I wasn't missing something, first.

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

1 participant