Class: Collins::CLI::State
- Inherits:
-
Object
- Object
- Collins::CLI::State
- Defined in:
- lib/collins/cli/state.rb
Constant Summary collapse
- PROG_NAME =
'collins state'- OPTIONS_DEFAULTS =
{ :format => :table, :separator => "\t", :timeout => 120, :show_header => false, :config => nil }
Constants included from Formatter
Formatter::ADDRESS_POOL_COLUMNS, Formatter::FORMATTING_DEFAULTS, Formatter::STATUS_STATE_COLUMNS
Constants included from Mixins
Mixins::COLORS, Mixins::ERROR, Mixins::SUCCESS
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ State
constructor
A new instance of State.
- #parse!(argv = ARGV) ⇒ Object
- #run! ⇒ Object
- #validate! ⇒ Object
Methods included from Formatter
#display_as_link, #display_as_robot_talk, #display_as_table, #format_assets, #format_pools, #format_states
Methods included from Mixins
#api_call, #as_query?, #collins, #convert_to_query
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
18 19 20 21 22 |
# File 'lib/collins/cli/state.rb', line 18 def initialize = OPTIONS_DEFAULTS.clone @validated = false @parsed = false end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/collins/cli/state.rb', line 16 def end |
Instance Method Details
#parse!(argv = ARGV) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/collins/cli/state.rb', line 24 def parse!(argv = ARGV) OptionParser.new do |opts| opts. = "Usage: #{PROG_NAME} [options]" opts.on('-l','--list',"List states.") { [:mode] = :list } opts.on('-h','--help',"Help") {puts opts ; exit 0} opts.separator "" opts.separator "Table formatting:" opts.on('-H','--show-header',"Show header fields in output") {[:show_header] = true} opts.on('-f','--field-separator SEPARATOR',String,"Separator between columns in output (Default: #{options[:separator]})") {|v| [:separator] = v} opts.separator "" opts.separator "Extra options:" opts.on('--timeout SECONDS',Integer,"Timeout in seconds (0 == forever)") {|v| [:timeout] = v} opts.on('-C','--config CONFIG',String,'Use specific Collins config yaml for Collins::Client') {|v| [:config] = v} opts.separator "" opts.separator "Examples:" opts.separator " Show states and statuses:\n\#{PROG_NAME} --list\n" end.parse!(argv) @parsed = true self end |
#run! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/collins/cli/state.rb', line 54 def run! exit_clean = true case [:mode] when :list states = collins.state_get_all format_states(states, ) else raise "I dunno what you want me to do! See #{PROG_NAME} --help" end exit_clean end |
#validate! ⇒ Object
48 49 50 51 52 |
# File 'lib/collins/cli/state.rb', line 48 def validate! raise "See --help for #{PROG_NAME} usage" if [:mode].nil? @validated = true self end |