Feature Requests: Browse | Submit New | Admin

[#5398] Define number of args you want for an option

Date:
2006-08-12 22:57
Priority:
3
Submitted By:
Chris Wanstrath (defunkt)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Define number of args you want for an option

Detailed description
  option :flag do
    args 1
    # ...
  end
would accept command as
  # prog --flag=arg

  option :flag do
    args 0..2
    # ...
  end
would accept
  # prog --flag
or
  # prog --flag x
or
  # prog --flag x y

What if you want to accept an unlimited amount of args, though?

$ ruby script --flag these are all args that im going to join into a string

Think about it.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-09-08 18:09
Sender: Sentinel K

Chris,
I know v little about command-line parsing, but I have some
thoughts.

1. Why can you not keep it simple and insist  that multiple options
be given in a quoted form. Or with commas and no spaces like:
--file=a,b,c
--file="a,some file,another file"

This way it is easy for you. The OS gives it as one arg.

2. Also, do you support a "--" option to signify that
options are over. Take this case of a flag that has optional
params.

--debug tcp,tls    (tcp,tls belongs to debug)
--debug file.rb     (file.rb does not belong)

3. Why allow both "--long=" and "--long "
(space).
Insist on "=".
This way you know when a param is passed in an optional param
and when it is not passed. (at least for long).

I really like this project. Pls don't abandon it!

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item