#126 ✓resolved
bahuvrihi

Remove OptionParser

Reported by bahuvrihi | November 16th, 2008 @ 10:21 AM


# [Argument style:]
#   One of the following:
#     :NONE, :REQUIRED, :OPTIONAL
#
# [Argument pattern:]
#   Acceptable option argument format, must be pre-defined with
#   OptionParser.accept or OptionParser#accept, or Regexp. This can appear
#   once or assigned as String if not present, otherwise causes an
#   ArgumentError. Examples:
#     Float, Time, Array
#
# [Possible argument values:]
#   Hash or Array.
#     [:text, :binary, :auto]
#     %w[iso-2022-jp shift_jis euc-jp utf8 binary]
#     { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
#
# [Long style switch:]
#   Specifies a long style switch which takes a mandatory, optional or no
#   argument. It's a string of the following form:
#     "--switch=MANDATORY" or "--switch MANDATORY"
#     "--switch[=OPTIONAL]"
#     "--switch"
#
# [Short style switch:]
#   Specifies short style switch which takes a mandatory, optional or no
#   argument. It's a string of the following form:
#     "-xMANDATORY"
#     "-x[OPTIONAL]"
#     "-x"
#   There is also a special form which matches character range (not full
#   set of regural expression):
#     "-[a-z]MANDATORY"
#     "-[a-z][OPTIONAL]"
#     "-[a-z]"
#
# [Argument style and description:]
#   Instead of specifying mandatory or optional orguments directly in the
#   switch parameter, this separate parameter can be used.
#     "=MANDATORY"
#     "=[OPTIONAL]"
#
# [Description:]
#   Description string for the option.
#     "Run verbosely"
#
# [Handler:]
#   Handler for the parsed argument value. Either give a block or pass a
#   Proc or Method as an argument.
#

Base:
  long              # --opt
  short             # -o -ooo (special short form specifies multiple switches)
  description

BooleanType:
  switch            # --[no]-switch (true or false)
  flag              # --flag (toggles default)

ArgumentType:
  option            # --opt ARG --opt=ARG -oARG -oooARG (special short passes ARG to each switch)

  Options:
    list              # --list a --list b --list c (concat before passing on)
    select            # limited set of args, code completion

=====================

  --opt, -o ARG     # description
  --[no-]switch     # a description that is really long
                    # should wrap around like this
  --flag
  --selection, -s ARG
                    # Selection: (a, b, c, d)
  --really-long-option, -r REALLY_LONG_ARG
                    # a description that is really long
                    # should wrap around like this
  --nested:config ARG
                    # a nested configuration (no short)

=====================
  switch, flag => checkbox

  option => input
  list => input + add/remove

  selection => select box
  list_selection => select list

=====================

  # must have boolean default value
  config :switch, false, &c.switch
  config :flag, false, &c.flag

  # any default value
  config :opt, 'value'
  config :opt, 0, :select => [1,2,3]             # ok values are [0,1,2,3]
  config :opt, 0, :select => [0,1,2,3], &c.list  # selection list

  default_options = {
    :reader => nil,
    :writer => nil,
    :short => nil,
    :desc => nil,
    :list => nil,
    :select => nil,  # conflict with switch/flag
    :switch => nil,  # conflict with select/flag
    :flag => nil     # conflict with select/switch
  }

  # warn override/conflicting long/short option names?

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A framework for making configurable, file-based tasks and workflows.

People watching this ticket

Pages