diff options
author | elijah <elijah@riseup.net> | 2013-02-08 21:47:45 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-02-08 21:47:45 -0800 |
commit | 6e5289b7df7ff2f1320ba139303018d260c9b9cf (patch) | |
tree | a352c76312ea24de3924b94ad2b89dd36bb848ff | |
parent | 2cc1bf46d9486352ebb5c785201ed7753cbfc65a (diff) | |
download | leap_cli-6e5289b7df7ff2f1320ba139303018d260c9b9cf.tar.gz leap_cli-6e5289b7df7ff2f1320ba139303018d260c9b9cf.tar.bz2 |
leap inspect now works with all .json files
-rw-r--r-- | lib/leap_cli/commands/inspect.rb | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/lib/leap_cli/commands/inspect.rb b/lib/leap_cli/commands/inspect.rb index 1856ad6..97d0b20 100644 --- a/lib/leap_cli/commands/inspect.rb +++ b/lib/leap_cli/commands/inspect.rb @@ -30,16 +30,39 @@ module LeapCli; module Commands log 2, "file is of type '#{ftype}'" if FTYPE_MAP[ftype] FTYPE_MAP[ftype] - elsif ftype == "ASCII text" - nil + elsif File.extname(object) == ".json" + full_path = File.expand_path(object, Dir.pwd) + if path_match?(:node_config, full_path) + :inspect_node + elsif path_match?(:service_config, full_path) + :inspect_service + elsif path_match?(:tag_config, full_path) + :inspect_tag + elsif path_match?(:provider_config, full_path) + :inspect_provider + elsif path_match?(:common_config, full_path) + :inspect_common + end end elsif manager.nodes[object] :inspect_node + elsif manager.services[object] + :inspect_service + elsif manager.tags[object] + :inspect_tag + elsif object == "common" + :inspect_common + elsif object == "provider" + :inspect_provider else nil end end + # + # inspectors + # + def inspect_x509_key(file_path, options) assert_bin! 'openssl' puts assert_run! 'openssl rsa -in %s -text -check' % file_path @@ -59,9 +82,38 @@ module LeapCli; module Commands #def inspect_ssh_pub_key(file_path) #end - def inspect_node(node_name, options) - node = manager.nodes[node_name] - puts node.dump_json + def inspect_node(arg, options) + inspect_json(arg, options) {|name| manager.nodes[name] } + end + + def inspect_service(arg, options) + inspect_json(arg, options) {|name| manager.services[name] } + end + + def inspect_tag(arg, options) + inspect_json(arg, options) {|name| manager.tags[name] } + end + + def inspect_provider(arg, options) + inspect_json(arg, options) {|name| manager.provider } + end + + def inspect_common(arg, options) + inspect_json(arg, options) {|name| manager.common } + end + + # + # helpers + # + + def inspect_json(arg, options) + name = File.basename(arg).sub(/\.json$/, '') + config = yield name + puts config.dump_json + end + + def path_match?(path_symbol, path) + Dir.glob(Path.named_path([path_symbol, '*'])).include?(path) end end; end |