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

Indicate which arguments are required #85

Closed
davetron5000 opened this issue May 6, 2012 · 5 comments
Closed

Indicate which arguments are required #85

davetron5000 opened this issue May 6, 2012 · 5 comments
Milestone

Comments

@davetron5000
Copy link
Owner

Might be nice to indicate which arguments are required

@gshutler
Copy link

I'm interested in implementing this feature to give something back. Did you have any ideas about how you would like this implemented? Would it be something like:

desc 'Some argument'
arg_name 'some_arg'
required 'You must specify some argument'
flag :arg

The message could be optional. In the help text might it automatically append (required) to the flag/switch message to designate it being required.

Should GLI handle someone not providing a required flag/switch? What behaviour would you like then? Display the help for the command perhaps?

@davetron5000
Copy link
Owner Author

Currently, flag arguments are always required even though OptionParser doesn't really require that.

I was mostly referring to command arguments, e.g.

desc 'Complete a task'
arg_name 'task_id'
command :complete do |c|
end

It gets tricky cause GLI just gives an Array to the action block, so you could have something like:

desc 'Complete a task'
# arg name is "task_id" and exactly one is required
args :task_id => :required
command :complete do |c|
end
desc 'Complete a task'
# arg name is "task_id" and one or more are accepted
args :task_id => [:required,:multiple]
command :complete do |c|
end
desc 'Complete a task'
# two args: task_id, which is required and message, which is optional.
# Would then expect to see "todo complete task_id [message]" in the help text
args :task_id => :required, :message => :optional
command :complete do |c|
end

I suppose a minimum viable feature that helps for most cases could be just

arg_name "task_id", :required

That simply requires that at least one arg is provided. That might cover a lot of cases and avoid dealing with the crazy multiple arguments thing.

If you do feel l like working on this (thanks by the way!), Use the gli-2 branch, which is the new "master", and check out test/apps/todo, which is an app created to test more complex stuff like this that's hard to simulate inside a unit test. Check out features/todo.feature for how I'm using it; basically making the todo app use as many GLI features as I can to test them in a real running app.

@gshutler
Copy link

Great. That gives me a good idea of what you're looking for.

@sathlan
Copy link

sathlan commented Aug 31, 2012

Hi,

did someone had time to make some progress on this one?

I'm looking forward to the :multiple flag: to be able to do thing like
this "cmd action -i 1 -i 2 test" and get back something like
this : :-i => [1, 2] in the hash.

It's not yet possible unless I'm missed something.

If nobody has time, I may be able to provide some.

++

@davetron5000
Copy link
Owner Author

@sathlan you can currently do what you want via:

flag [:i], :must_match => Array

And then a command-line invocation like

your_app -i 1,2

will give you the value [1,2] for global_options[:i]

I know this isn't exactly what you want, but it's a decent workaround.

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

No branches or pull requests

3 participants