Class: Miniparse::SwitchOption

Inherits:
Option show all
Defined in:
lib/miniparse/command.rb

Instance Attribute Summary

Attributes inherited from Option

#shortable, #value

Attributes inherited from Command

#desc, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Option

#check, #parse_value

Methods inherited from Command

#check, #help_desc, #initialize, #run, valid_spec

Constructor Details

This class inherits a constructor from Miniparse::Command

Class Method Details

.spec_to_name(spec) ⇒ Object



134
135
136
# File 'lib/miniparse/command.rb', line 134

def self.spec_to_name(spec)
  spec_pattern_to_name(spec, /\A--(\w[\w-]+)\z/)
end

Instance Method Details

#arg_to_value(arg) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/miniparse/command.rb', line 138

def arg_to_value(arg)
  if arg == "--#{name}"
    true
  elsif negatable && (arg == "--no-#{name}")
    false
  elsif shortable && (arg == '-' + name.to_s[0])
    true
  else
    nil
  end
end

#help_usageObject



150
151
152
# File 'lib/miniparse/command.rb', line 150

def help_usage
  negatable  ?  "[--[no-]#{name}]"  :  "[--#{name}]"
end