Class: Oxidized::Script::Command::ListNodes
- Defined in:
- lib/oxidized/script/commands/list-nodes.rb
Constant Summary collapse
- Name =
'list-nodes'
- Description =
'list nodes in oxidized source'
Class Method Summary collapse
-
.cmdline(slop, cli) ⇒ Object
this is not needed this this command, just shown how todo more complex commands, this could use slop sub-commands etc.
- .run(opts = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.cmdline(slop, cli) ⇒ Object
this is not needed this this command, just shown how todo more complex commands, this could use slop sub-commands etc. As long as it sets cli.cmd_class when you want to run it, it gets ran after parsing commandline
12 13 14 15 16 |
# File 'lib/oxidized/script/commands/list-nodes.rb', line 12 def self.cmdline slop, cli slop.on "--#{Name}", Description do cli.cmd_class = self end end |
.run(opts = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/oxidized/script/commands/list-nodes.rb', line 18 def self.run opts={} if opts[:opts][:terse] # find if 'terse' global option is set puts new(opts).nodes_terse else puts new(opts).nodes end end |
Instance Method Details
#nodes ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/oxidized/script/commands/list-nodes.rb', line 26 def nodes out = '' Nodes.new.each do |node| out += "#{node.name}:\n" node.instance_variables.each do |var| name = var.to_s[1..-1] next if name == 'name' value = node.instance_variable_get var value = value.class if name == 'model' out += " %10s => %s\n" % [name, value.to_s] end end out end |
#nodes_terse ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/oxidized/script/commands/list-nodes.rb', line 41 def nodes_terse out = '' i = 0 Nodes.new.each do |node| out += "#{i += 1} - #{node.name}\n" end out end |