Class: Bogo::Cli::Parser::Flag
- Inherits:
-
Object
- Object
- Bogo::Cli::Parser::Flag
- Defined in:
- lib/bogo-cli/parser.rb
Instance Attribute Summary collapse
-
#callable ⇒ Proc
readonly
Block to execute on flag called.
-
#default ⇒ String
readonly
Default value.
-
#description ⇒ String
readonly
Flag description.
-
#long_name ⇒ String
readonly
Long flag.
-
#short_name ⇒ String
readonly
Short flag.
Instance Method Summary collapse
-
#boolean? ⇒ Boolean
Flag is boolean value.
-
#initialize(long_name:, short_name: nil, description: nil, default: nil, callable: nil) ⇒ Object
constructor
Create a new flag.
-
#option_name ⇒ Symbol
Option compatible name.
Constructor Details
#initialize(long_name:, short_name: nil, description: nil, default: nil, callable: nil) ⇒ Object
Create a new flag
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/bogo-cli/parser.rb', line 264 def initialize(long_name:, short_name: nil, description: nil, default: nil, callable: nil ) if short_name short_name = short_name.to_s short_name = short_name[1, short_name.size] if short_name.start_with?('-') raise ArgumentError, "Flag short name must be single character (flag: #{short_name})" if short_name.size > 1 end @short_name = short_name @long_name = long_name.to_s.sub(/^-+/, '').gsub('_', '-') @description = description @default = default @callable = callable end |
Instance Attribute Details
#callable ⇒ Proc (readonly)
255 256 257 |
# File 'lib/bogo-cli/parser.rb', line 255 def callable @callable end |
#default ⇒ String (readonly)
251 252 253 |
# File 'lib/bogo-cli/parser.rb', line 251 def default @default end |
#description ⇒ String (readonly)
253 254 255 |
# File 'lib/bogo-cli/parser.rb', line 253 def description @description end |
#long_name ⇒ String (readonly)
249 250 251 |
# File 'lib/bogo-cli/parser.rb', line 249 def long_name @long_name end |
#short_name ⇒ String (readonly)
247 248 249 |
# File 'lib/bogo-cli/parser.rb', line 247 def short_name @short_name end |
Instance Method Details
#boolean? ⇒ Boolean
291 292 293 |
# File 'lib/bogo-cli/parser.rb', line 291 def boolean? !long_name.include?('=') end |
#option_name ⇒ Symbol
286 287 288 |
# File 'lib/bogo-cli/parser.rb', line 286 def option_name long_name.split('=').first.gsub('-', '_').to_sym end |