Class: Bashly::Script::CatchAll

Inherits:
Object
  • Object
show all
Defined in:
lib/bashly/script/catch_all.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, help: nil, required: false, enabled: true) ⇒ CatchAll

Returns a new instance of CatchAll.



21
22
23
# File 'lib/bashly/script/catch_all.rb', line 21

def initialize(label: nil, help: nil, required: false, enabled: true)
  @label, @help, @required, @enabled = label, help, required, enabled
end

Class Method Details

.from_config(config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bashly/script/catch_all.rb', line 5

def from_config(config)
  options = case config
  when nil
    { enabled: false }
  when String
    { label: config }
  when Hash
    { label: config['label'], help: config['help'], required: config['required'] }
  else
    {}
  end

  new **options
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/bashly/script/catch_all.rb', line 25

def enabled?
  @enabled
end

#helpObject



33
34
35
# File 'lib/bashly/script/catch_all.rb', line 33

def help
  enabled? ? @help : nil
end

#labelObject



29
30
31
# File 'lib/bashly/script/catch_all.rb', line 29

def label
  enabled? ? "#{@label&.upcase}..." : nil
end

#required?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bashly/script/catch_all.rb', line 37

def required?
  @required
end

#usage_stringObject



41
42
43
44
# File 'lib/bashly/script/catch_all.rb', line 41

def usage_string
  return nil unless enabled?
  required? ? label : "[#{label}]"
end