Module: TTY::Option::DSL
- Extended by:
- Forwardable
- Includes:
- Arity, Conversion, Inflection
- Defined in:
- lib/tty/option/dsl.rb,
lib/tty/option/dsl/arity.rb,
lib/tty/option/dsl/conversion.rb
Defined Under Namespace
Modules: Arity, Conversion
Instance Method Summary collapse
-
#argument(name, **settings, &block) ⇒ Object
Specify an argument.
-
#environment(name, **settings, &block) ⇒ Object
(also: #env)
Specify environment variable.
-
#flag(name, **settings, &block) ⇒ Object
A shortcut to specify flag option.
-
#ignore(*names) ⇒ Object
(also: #skip)
Remove parameter from the parameters definitions list.
-
#keyword(name, **settings, &block) ⇒ Object
Specify a keyword.
-
#option(name, **settings, &block) ⇒ Object
(also: #opt)
Specify an option.
-
#parameters ⇒ Object
Holds all parameters.
-
#usage(**properties, &block) ⇒ Object
Holds the usage information.
Methods included from Inflection
dasherize, demodulize, underscore
Methods included from Conversion
Methods included from Arity
#at_least, #one, #one_or_more, #two, #two_or_more, #zero_or_more
Instance Method Details
#argument(name, **settings, &block) ⇒ Object
Specify an argument
40 41 42 |
# File 'lib/tty/option/dsl.rb', line 40 def argument(name, **settings, &block) parameters << Parameter::Argument.create(name.to_sym, **settings, &block) end |
#environment(name, **settings, &block) ⇒ Object Also known as: env
Specify environment variable
50 51 52 |
# File 'lib/tty/option/dsl.rb', line 50 def environment(name, **settings, &block) parameters << Parameter::Environment.create(name.to_sym, **settings, &block) end |
#flag(name, **settings, &block) ⇒ Object
A shortcut to specify flag option
71 72 73 74 |
# File 'lib/tty/option/dsl.rb', line 71 def flag(name, **settings, &block) defaults = {default: false} option(name, **defaults.merge(settings), &block) end |
#ignore(*names) ⇒ Object Also known as: skip
Remove parameter from the parameters definitions list
92 93 94 |
# File 'lib/tty/option/dsl.rb', line 92 def ignore(*names) parameters.delete(*names) end |
#keyword(name, **settings, &block) ⇒ Object
Specify a keyword
61 62 63 |
# File 'lib/tty/option/dsl.rb', line 61 def keyword(name, **settings, &block) parameters << Parameter::Keyword.create(name.to_sym, **settings, &block) end |
#option(name, **settings, &block) ⇒ Object Also known as: opt
Specify an option
84 85 86 |
# File 'lib/tty/option/dsl.rb', line 84 def option(name, **settings, &block) parameters << Parameter::Option.create(name.to_sym, **settings, &block) end |
#parameters ⇒ Object
Holds all parameters
100 101 102 |
# File 'lib/tty/option/dsl.rb', line 100 def parameters @parameters ||= Parameters.new end |
#usage(**properties, &block) ⇒ Object
Holds the usage information
29 30 31 32 33 34 35 |
# File 'lib/tty/option/dsl.rb', line 29 def usage(**properties, &block) @usage ||= Usage.create(**properties, &block).tap do |usage| unless usage.command? || usage.no_command? usage.command(dasherize(demodulize(self.name))) end end end |