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

Methods included from Inflection

dasherize, demodulize, underscore

Methods included from Conversion

#list_of, #map_of

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

Examples:

EDITOR=vim


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

Examples:

--foo


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

Examples:

foo=bar


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

Examples:

-f
--foo
--foo bar


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

#parametersObject

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