Class: Toys::DSL::Flag

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/dsl/flag.rb

Overview

DSL for a flag definition block. Lets you set flag attributes in a block instead of a long series of keyword arguments.

These directives are available inside a block passed to Tool#flag.

Instance Method Summary collapse

Instance Method Details

#accept(accept) ⇒ Toys::DSL::Tool

Set the OptionParser acceptor.

Parameters:

  • accept (Object)

Returns:



71
72
73
74
# File 'lib/toys/dsl/flag.rb', line 71

def accept(accept)
  @accept = accept
  self
end

#default(default) ⇒ Toys::DSL::Tool

Set the default value.

Parameters:

  • default (Object)

Returns:



82
83
84
85
# File 'lib/toys/dsl/flag.rb', line 82

def default(default)
  @default = default
  self
end

#desc(desc) ⇒ Toys::DSL::Tool

Set the short description. See Tool#desc for the allowed formats.

Parameters:

Returns:



121
122
123
124
# File 'lib/toys/dsl/flag.rb', line 121

def desc(desc)
  @desc = desc
  self
end

#flags(*flags) ⇒ Toys::DSL::Tool

Add flags in OptionParser format. This may be called multiple times, and the results are cumulative.

Parameters:

  • flags (String...)

Returns:



60
61
62
63
# File 'lib/toys/dsl/flag.rb', line 60

def flags(*flags)
  @flags += flags
  self
end

#handler(handler = nil, &block) ⇒ Toys::DSL::Tool

Set the optional handler for setting/updating the value when a flag is parsed. A handler should be a Proc taking two arguments, the new given value and the previous value, and it should return the new value that should be set. You may pass the handler as a Proc (or an object responding to the call method) or you may pass a block.

Parameters:

  • handler (Proc) (defaults to: nil)

Returns:



97
98
99
100
# File 'lib/toys/dsl/flag.rb', line 97

def handler(handler = nil, &block)
  @handler = handler || block
  self
end

#long_desc(*long_desc) ⇒ Toys::DSL::Tool

Adds to the long description. This may be called multiple times, and the results are cumulative. See Tool#long_desc for the allowed formats.

Parameters:

Returns:



134
135
136
137
# File 'lib/toys/dsl/flag.rb', line 134

def long_desc(*long_desc)
  @long_desc += long_desc
  self
end

#report_collisions(setting) ⇒ Toys::DSL::Tool

Set whether to raise an exception if a flag is requested that is already in use or marked as disabled.

Parameters:

  • setting (Boolean)

Returns:



109
110
111
112
# File 'lib/toys/dsl/flag.rb', line 109

def report_collisions(setting)
  @report_collisions = setting
  self
end