Class: Slidict::Cli::Options::Flag
- Inherits:
-
Struct
- Object
- Struct
- Slidict::Cli::Options::Flag
- Defined in:
- lib/slidict/cli/options.rb
Overview
One -x/--xxx declaration: how to parse it (arg placeholder,
coercion) and how to describe it in --help output.
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#coerce ⇒ Object
Returns the value of attribute coerce.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#key ⇒ Object
Returns the value of attribute key.
-
#switches ⇒ Object
Returns the value of attribute switches.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #long ⇒ Object
-
#name_column ⇒ Object
Left column of the help listing, e.g.
- #short ⇒ Object
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg
35 36 37 |
# File 'lib/slidict/cli/options.rb', line 35 def arg @arg end |
#coerce ⇒ Object
Returns the value of attribute coerce
35 36 37 |
# File 'lib/slidict/cli/options.rb', line 35 def coerce @coerce end |
#desc ⇒ Object
Returns the value of attribute desc
35 36 37 |
# File 'lib/slidict/cli/options.rb', line 35 def desc @desc end |
#key ⇒ Object
Returns the value of attribute key
35 36 37 |
# File 'lib/slidict/cli/options.rb', line 35 def key @key end |
#switches ⇒ Object
Returns the value of attribute switches
35 36 37 |
# File 'lib/slidict/cli/options.rb', line 35 def switches @switches end |
Instance Method Details
#boolean? ⇒ Boolean
36 37 38 |
# File 'lib/slidict/cli/options.rb', line 36 def boolean? arg.nil? end |
#long ⇒ Object
44 45 46 |
# File 'lib/slidict/cli/options.rb', line 44 def long switches.find { |s| s.start_with?("--") } end |
#name_column ⇒ Object
Left column of the help listing, e.g. "-o, --output PATH" or, for a long-only flag, " --topic TEXT" -- the leading 4 spaces keep the "--name" text column-aligned either way.
51 52 53 54 |
# File 'lib/slidict/cli/options.rb', line 51 def name_column column = "#{short ? "#{short}, " : " "}#{long}" arg ? "#{column} #{arg}" : column end |
#short ⇒ Object
40 41 42 |
# File 'lib/slidict/cli/options.rb', line 40 def short switches.find { |s| !s.start_with?("--") } end |