onering-client 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/onering +22 -6
  2. metadata +3 -3
@@ -11,12 +11,27 @@ require 'rubygems'
11
11
  require 'subcommander'
12
12
  require 'onering'
13
13
  require 'yaml'
14
+ require 'pp'
14
15
 
15
16
  include Subcommander
16
17
 
17
18
 
18
- def print_format(data)
19
- puts YAML.dump(data)
19
+ def print_format(data, format=:yaml)
20
+ case format
21
+ when :text
22
+ if data.is_a?(Hash)
23
+ pp data
24
+ elsif data.is_a?(Array)
25
+ puts data.join("\n")
26
+ else
27
+ puts data.to_s
28
+ end
29
+ when :yaml
30
+ puts YAML.dump(data)
31
+
32
+ else
33
+ STDERR.puts "Invalid format: #{format}"
34
+ end
20
35
  end
21
36
 
22
37
  subcommander.version = Gem.loaded_specs['onering-client'].version.to_s
@@ -33,7 +48,7 @@ subcommand :devices, "Operations related to Onering's assets database" do |devic
33
48
  sc.usage = "onering devices get ID"
34
49
 
35
50
  sc.exec do
36
- print_format api.get(sc[:args].first)
51
+ print_format(api.get(sc[:args].first))
37
52
  end
38
53
  end
39
54
 
@@ -41,14 +56,15 @@ subcommand :devices, "Operations related to Onering's assets database" do |devic
41
56
  devices.subcommand :list, "List field values" do |sc|
42
57
  sc.usage = "onering devices list [-f FILTER] FIELD"
43
58
  sc.opt :filter, '-f', '--filter FILTER', "A urlquery filter string"
59
+ sc.ops :as_txt, '-t', '--as-text', "Return the results as text"
44
60
 
45
61
  sc.exec do
46
62
  field = sc[:args].first
47
63
  filter = sc[:filter]
48
64
 
49
- print_format api.list(field, {
65
+ print_format(api.list(field, {
50
66
  :filter => filter
51
- })
67
+ }), (sc[:as_txt] ? :text : nil))
52
68
  end
53
69
  end
54
70
 
@@ -58,7 +74,7 @@ subcommand :devices, "Operations related to Onering's assets database" do |devic
58
74
  sc.usage = "onering devices find FILTER"
59
75
 
60
76
  sc.exec do
61
- print_format api.find(sc[:args].first)
77
+ print_format(api.find(sc[:args].first))
62
78
  end
63
79
  end
64
80
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onering-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gary Hetzel