diff options
author | elijah <elijah@riseup.net> | 2015-06-26 16:12:17 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2015-06-26 16:12:17 -0700 |
commit | 98cf1714c70ac6833551bfdc26a50986c1e34944 (patch) | |
tree | 5636c44f38fc45b97ec4b0ec0b4ff7f1a7a648d9 | |
parent | ac28764f2b227d25a2b9d2415199ff19af8e201a (diff) |
`leap ls --print` should return values, not formulas
-rw-r--r-- | lib/leap_cli/commands/list.rb | 9 | ||||
-rw-r--r-- | lib/leap_cli/config/object.rb | 10 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb index 0b78a2d..c562b59 100644 --- a/lib/leap_cli/commands/list.rb +++ b/lib/leap_cli/commands/list.rb @@ -46,12 +46,15 @@ module LeapCli; module Commands max_width = nodes.keys.inject(0) {|max,i| [i.size,max].max} nodes.each_node do |node| value = properties.collect{|prop| - if node[prop].nil? + prop_value = node[prop] + if prop_value.nil? "null" - elsif node[prop] == "" + elsif prop_value == "" "empty" + elsif prop_value.is_a? LeapCli::Config::Object + node[prop].dump_json(:compact) # TODO: add option of getting pre-evaluation values. else - node[prop] + prop_value.to_s end }.join(', ') printf("%#{max_width}s %s\n", node.name, value) diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index 6f71a08..869c331 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -85,9 +85,13 @@ module LeapCli # # export JSON # - def dump_json + def dump_json(*options) evaluate(@node) - JSON.sorted_generate(self) + if options.include? :compact + self.to_json + else + JSON.sorted_generate(self) + end end def evaluate(context=@node) @@ -143,7 +147,7 @@ module LeapCli elsif key =~ /\./ # for keys with with '.' in them, we start from the root object (@node). keys = key.split('.') - value = @node.get!(keys.first) + value = self.get!(keys.first) if value.is_a? Config::Object value.get!(keys[1..-1].join('.')) else |