Class: Bashly::Script::CatchAll
- Inherits:
-
Object
- Object
- Bashly::Script::CatchAll
- Defined in:
- lib/bashly/script/catch_all.rb
Class Method Summary collapse
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #help ⇒ Object
-
#initialize(label: nil, help: nil, required: false, enabled: true) ⇒ CatchAll
constructor
A new instance of CatchAll.
- #label ⇒ Object
- #required? ⇒ Boolean
- #usage_string ⇒ Object
Constructor Details
#initialize(label: nil, help: nil, required: false, enabled: true) ⇒ CatchAll
Returns a new instance of CatchAll.
25 26 27 28 29 30 |
# File 'lib/bashly/script/catch_all.rb', line 25 def initialize(label: nil, help: nil, required: false, enabled: true) @label = label @help = help @required = required @enabled = enabled end |
Class Method Details
.from_config(config) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bashly/script/catch_all.rb', line 9 def from_config(config) = case config when nil { enabled: false } when String { label: config } when Hash { label: config['label'], help: config['help'], required: config['required'] } else {} end new(**) end |
.option_keys ⇒ Object
5 6 7 |
# File 'lib/bashly/script/catch_all.rb', line 5 def option_keys @option_keys ||= %i[label help required] end |
Instance Method Details
#enabled? ⇒ Boolean
32 33 34 |
# File 'lib/bashly/script/catch_all.rb', line 32 def enabled? @enabled end |
#help ⇒ Object
40 41 42 |
# File 'lib/bashly/script/catch_all.rb', line 40 def help enabled? ? @help : nil end |
#label ⇒ Object
36 37 38 |
# File 'lib/bashly/script/catch_all.rb', line 36 def label enabled? ? "#{@label&.upcase}..." : nil end |
#required? ⇒ Boolean
44 45 46 |
# File 'lib/bashly/script/catch_all.rb', line 44 def required? @required end |
#usage_string ⇒ Object
48 49 50 51 52 |
# File 'lib/bashly/script/catch_all.rb', line 48 def usage_string return nil unless enabled? required? ? "[--] #{label}" : "[--] [#{label}]" end |