Class: CLASP::FlagSpecification
- Inherits:
-
SpecificationBase
- Object
- SpecificationBase
- CLASP::FlagSpecification
- Defined in:
- lib/clasp/specifications.rb
Overview
A class that represents the specification for a command-line flag
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
(Proc) The procedure.
-
#aliases ⇒ Object
readonly
The flag’s aliases array.
-
#extras ⇒ Object
readonly
The flag’s extras.
-
#help ⇒ Object
readonly
The flag’s help string.
-
#name ⇒ Object
readonly
The flag’s name string.
Class Method Summary collapse
-
.Help(extras = nil, &blk) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information.
-
.Version(extras = nil, &blk) ⇒ Object
An instance of FlagSpecification that provides default ‘–version’ information.
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
Compares instance against another FlagSpecification or against a name (String).
-
#initialize(name, aliases, help, extras = nil, &blk) ⇒ FlagSpecification
constructor
Creates a FlagSpecification instance from the given name, aliases, and help.
-
#to_s ⇒ Object
String form of the flag.
Constructor Details
#initialize(name, aliases, help, extras = nil, &blk) ⇒ FlagSpecification
Creates a FlagSpecification instance from the given name, aliases, and help
Signature
-
Parameters
-
name(String) The name, or long-form, of the flag -
aliases(Array) 0 or more strings specifying short-form or option-value aliases -
help(String) The help string, which may benil -
extrasAn application-defined additional parameter. Ifnil, it is assigned an emptyHash
-
-
Block An optional block that is called when a matching flag argument is found
NOTE: Users should prefer the CLASP::Flag() method
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/clasp/specifications.rb', line 108 def initialize(name, aliases, help, extras = nil, &blk) check_arity_(blk, 0..3, "flag") @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @extras = extras || {} @action = blk end |
Instance Attribute Details
#action ⇒ Object
(Proc) The procedure
129 130 131 |
# File 'lib/clasp/specifications.rb', line 129 def action @action end |
#aliases ⇒ Object (readonly)
The flag’s aliases array
122 123 124 |
# File 'lib/clasp/specifications.rb', line 122 def aliases @aliases end |
#extras ⇒ Object (readonly)
The flag’s extras
126 127 128 |
# File 'lib/clasp/specifications.rb', line 126 def extras @extras end |
#help ⇒ Object (readonly)
The flag’s help string
124 125 126 |
# File 'lib/clasp/specifications.rb', line 124 def help @help end |
#name ⇒ Object (readonly)
The flag’s name string
120 121 122 |
# File 'lib/clasp/specifications.rb', line 120 def name @name end |
Class Method Details
.Help(extras = nil, &blk) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information
If you wish to specify extras or attach a block, you may do so
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/clasp/specifications.rb', line 188 def self.Help(extras = nil, &blk) h = @@Help_ if extras || blk return self.new(h.name, h.aliases, h.help, extras, &blk) end h end |
.Version(extras = nil, &blk) ⇒ Object
An instance of FlagSpecification that provides default ‘–version’ information
If you wish to specify extras or attach a block, you may do so
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/clasp/specifications.rb', line 203 def self.Version(extras = nil, &blk) h = @@Version_ if extras || blk return self.new(h.name, h.aliases, h.help, extras, &blk) end h end |
Instance Method Details
#==(rhs) ⇒ Object
Compares instance against another FlagSpecification or against a name (String)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/clasp/specifications.rb', line 166 def == rhs case rhs when self.class return self.eql? rhs when String return name == rhs else false end end |
#to_s ⇒ Object
String form of the flag
140 141 142 143 |
# File 'lib/clasp/specifications.rb', line 140 def to_s "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}" end |