diff options
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r-- | lib/leap_cli/config/manager.rb | 13 | ||||
-rw-r--r-- | lib/leap_cli/config/object.rb | 23 |
2 files changed, 30 insertions, 6 deletions
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 2013217..ca739c3 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -331,6 +331,19 @@ module LeapCli @partials[partial_path] end + # + # Loads a json template file as a Hash (used only when creating a new node .json + # file for the first time). + # + def template(template) + path = Path.named_path([:template_config, template], Path.provider_base) + if File.exists?(path) + return load_json(path, Config::Object) + else + return nil + end + end + private def load_all_json(pattern, object_class, options={}) diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index 869c331..0f7376f 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -85,12 +85,23 @@ module LeapCli # # export JSON # - def dump_json(*options) + def dump_json(options={}) evaluate(@node) - if options.include? :compact - self.to_json + if options[:format] == :compact + return self.to_json else - JSON.sorted_generate(self) + excluded = {} + if options[:exclude] + options[:exclude].each do |key| + excluded[key] = self[key] + self.delete(key) + end + end + json_str = JSON.sorted_generate(self) + if excluded.any? + self.merge!(excluded) + end + return json_str end end @@ -286,7 +297,7 @@ module LeapCli keys.each do |key| obj = fetch_value(key, context) if is_required_value_not_set?(obj) - Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"." + Util::log 0, :warning, "required property \"#{key}\" is not set in node \"#{node.name}\"." elsif obj.is_a? Config::Object obj.evaluate_everything(context) end @@ -301,7 +312,7 @@ module LeapCli @late_eval_list.each do |key, value| self[key] = context.evaluate_ruby(key, value) if is_required_value_not_set?(self[key]) - Util::log 0, :warning, "required key \"#{key}\" is not set in node \"#{node.name}\"." + Util::log 0, :warning, "required property \"#{key}\" is not set in node \"#{node.name}\"." end end end |