sensu-cli 0.2.0 → 0.2.1

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.
@@ -4,6 +4,7 @@ module SensuCli
4
4
  def setup
5
5
  clis = Cli.new
6
6
  cli = clis.global
7
+ @format = cli[:fields][:format] || "long"
7
8
  settings
8
9
  api_path(cli)
9
10
  make_call
@@ -43,7 +44,13 @@ module SensuCli
43
44
  api = Api.new
44
45
  res = api.request(opts)
45
46
  msg = api.response(res.code, res.body, @api[:command])
46
- res.code != '200' ? exit : Pretty.print(msg)
47
+ if res.code != '200'
48
+ exit
49
+ elsif @format == "single"
50
+ Pretty.table(msg)
51
+ else
52
+ Pretty.print(msg)
53
+ end
47
54
  Pretty.count(msg)
48
55
  end
49
56
 
data/lib/sensu-cli/cli.rb CHANGED
@@ -137,7 +137,9 @@ module SensuCli
137
137
  p = Trollop::options do
138
138
  opt :limit, "The number if clients to return", :short => "l", :type => :string
139
139
  opt :offset, "The number of clients to offset before returning", :short => "o", :type => :string
140
+ opt :format, "Available formats; single (single line formatting)", :short => "f", :type => :string
140
141
  end
142
+ Trollop::die :format, "Available optional formats: single".color(:red) if p[:format] && p[:format] != "single"
141
143
  Trollop::die :offset, "Offset depends on the limit option --limit ( -l )".color(:red) if p[:offset] && !p[:limit]
142
144
  cli = {:command => 'clients', :method => 'Get', :fields => p}
143
145
  when 'delete'
@@ -197,7 +199,10 @@ module SensuCli
197
199
  explode_if_empty(opts,command)
198
200
  case command
199
201
  when 'list'
200
- p = Trollop::options
202
+ p = Trollop::options do
203
+ opt :format, "Available formats; single (single line formatting)", :short => "f", :type => :string
204
+ end
205
+ Trollop::die :format, "Available optional formats: single".color(:red) if p[:format] && p[:format] != "single"
201
206
  cli = {:command => 'events', :method => 'Get', :fields => p}
202
207
  when 'show'
203
208
  p = Trollop::options do
@@ -31,5 +31,47 @@ module SensuCli
31
31
  puts "#{count} total items".color(:yellow) if count
32
32
  end
33
33
 
34
+ def self.clean(thing)
35
+ thing = thing.gsub("\n",'/\n') if thing.is_a?(String)
36
+ thing
37
+ end
38
+
39
+ def self.table(res)
40
+ if !res.empty?
41
+ if res.is_a?(Array)
42
+ keys = res.map{|item| item.keys}.flatten.uniq.sort
43
+
44
+ # Remove fields with spaces (breaks awkage)
45
+ keys.select! do |key|
46
+ res.none?{|item| item[key].to_s.include?(' ')}
47
+ end
48
+
49
+ # Find max value lengths
50
+ value_lengths = {}
51
+ keys.each do |key|
52
+ max_value_length = res.map{|item| item[key].to_s.length}.max
53
+ value_lengths[key] = [max_value_length, key.length].max
54
+ end
55
+
56
+ # Print header
57
+ format = keys.map {|key| "%-#{value_lengths[key]}s"}.join(' ')
58
+ puts sprintf(format, *keys)
59
+
60
+ # Print value rows
61
+ res.each do |item|
62
+ if item.is_a?(Hash)
63
+ values = keys.map {|key| item[key]}
64
+ format = keys.map {|key| "%-#{value_lengths[key]}s"}.join(' ')
65
+ puts sprintf(format, *values)
66
+ else
67
+ puts item.to_s.color(:cyan)
68
+ end
69
+ end
70
+ end
71
+ else
72
+ puts "no values for this request".color(:cyan)
73
+ end
74
+ end
75
+
34
76
  end
35
77
  end
@@ -1,3 +1,3 @@
1
1
  module SensuCli
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/sensu-cli.gemspec CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency('trollop', '2.0')
16
16
  s.add_dependency('mixlib-config', '1.1.2')
17
17
 
18
+ s.add_development_dependency('rspec')
19
+
18
20
  s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu-cli.gemspec README.md settings.example.rb]
19
21
  s.executables = Dir.glob('bin/**/*').map { |file| File.basename(file) }
20
22
  s.require_paths = ['lib']
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Bryan Brandau
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-02 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rainbow
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - '='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: trollop
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - '='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - '='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: mixlib-config
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - '='
46
52
  - !ruby/object:Gem::Version
@@ -48,10 +54,27 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - '='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 1.1.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
55
78
  description: A command line utility for interacting with the Sensu api.
56
79
  email: agent462@gmail.com
57
80
  executables:
@@ -78,25 +101,26 @@ homepage: http://github.com/agent462/sensu-cli
78
101
  licenses:
79
102
  - MIT
80
103
  - APACHE
81
- metadata: {}
82
104
  post_install_message:
83
105
  rdoc_options: []
84
106
  require_paths:
85
107
  - lib
86
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
87
110
  requirements:
88
111
  - - ! '>='
89
112
  - !ruby/object:Gem::Version
90
113
  version: '0'
91
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
92
116
  requirements:
93
117
  - - ! '>='
94
118
  - !ruby/object:Gem::Version
95
119
  version: '0'
96
120
  requirements: []
97
121
  rubyforge_project:
98
- rubygems_version: 2.0.3
122
+ rubygems_version: 1.8.25
99
123
  signing_key:
100
- specification_version: 4
124
+ specification_version: 3
101
125
  summary: A command line utility for Sensu.
102
126
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTNkNGJlNWUzNzViYjgwYTYyYmVkOGQ0MzdkMzM5YjAyY2Q1ODdjMw==
5
- data.tar.gz: !binary |-
6
- NzJlM2Q0MmRmOTg2YjA1ZGY2YmYxNzY2MjAwYzIwNDEwMTBiM2U4NQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MDcyNDdhYTRhOWUwZmNlOWNiZTA2Y2I4ZTU4Y2NkZWNkNTliYmFkOTk4NTlh
10
- M2M2YzMxNWJlZGRkN2Q1MGNlMGJhNzcyZGUwNzM5MzFlZWY2NDhhYzZkNDZh
11
- OTE2Y2M4MDg4OWZmNjJiOGM0NTkxMDQyMmM5YTcwYzlhYTdiMGM=
12
- data.tar.gz: !binary |-
13
- MmIxZWZhYzc3MmI5MjI0OTcxMjY0ZjkzMGRjYzAxYTkwNmZmZTIyZjU2ODg0
14
- YzE5YjlhZjMxNWY0MjUyNDc2YmZiNTQ3MWYyOWRlZWI3MjFjYWUxMWYwZjIz
15
- ZGY0NDQ1MWJhOWRkNTMyYmJjYTFkZDU5ODNkMWJiNzg3MTJhZDY=