Class: Bashly::Models::Flag

Inherits:
Base
  • Object
show all
Defined in:
lib/bashly/models/flag.rb

Constant Summary

Constants inherited from Base

Base::OPTION_KEYS

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_missing, #respond_to?

Methods included from Renderable

#render, #strings

Constructor Details

This class inherits a constructor from Bashly::Models::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bashly::Models::Base

Instance Method Details

#aliasesObject



4
5
6
7
8
9
10
11
12
# File 'lib/bashly/models/flag.rb', line 4

def aliases
  if long and short
    [long, short]
  elsif long
    [long]
  else
    [short]
  end
end

#optionalObject



14
15
16
# File 'lib/bashly/models/flag.rb', line 14

def optional
  !required
end

#summaryObject



18
19
20
21
# File 'lib/bashly/models/flag.rb', line 18

def summary
  return "" unless help
  help.split("\n").first
end

#usage_string(extended: false) ⇒ Object



23
24
25
26
27
28
# File 'lib/bashly/models/flag.rb', line 23

def usage_string(extended: false)
  result = [aliases.join(", ")]
  result << arg.upcase if arg
  result << "(required)" if required and extended
  result.join " "
end