optica-client 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e231b226e1fd51fcf8a57d0e03c644e006a352a8
4
- data.tar.gz: 36c245aaffdd8dfbe13bffdf24a8c9d717f24b56
3
+ metadata.gz: acc987011dd7c2b81f2ba79e53830647562976ac
4
+ data.tar.gz: b3752eaf4cb62e5fd27e7067619caa7081e6b3bc
5
5
  SHA512:
6
- metadata.gz: 7395337003e0e80229826b0a9aef7a036faca0df9dbb773c6006e655ef574f2493e4508b3ac702ef98377b0a5e359a1ed9de848e189592c34b38d3167d2b06d1
7
- data.tar.gz: f6cd27ba9404d9d858d118196c9b42978aec4328265b36e76b58cdd5023ea0e552e7fe91e873dad08b12f0b8b3afedcb5551f7b499a59d7debc04da54885d365
6
+ metadata.gz: 74f13d76aafedcee686e023b0915ecba1b0d4decff838ece48668cf84dbb5901d0b8830b9a6e57b02a789bfbb14384777cf97ceee8075b245433b89467bfa7b8
7
+ data.tar.gz: c7f09d76d19fd0e740ccd591091b6623262435fa109c646b8a92ff14e582c3af554b4c39d5449337b1cc9f15d856b11ce1a8876b64fbcbe9faf11af691942bc3
data/README.md CHANGED
@@ -29,10 +29,12 @@ Usage: optical [options] [FIELD=FILTER] [FIELD2=FILTER2...]
29
29
  Options:
30
30
  -s, --select a,b,c Retrieve the given fields, in addition to the defaults
31
31
  -a, --all Retrieve all fields (default is just role,id,hostname)
32
+ -j, --just a,b,c Print just the given fields as tab-seperated strings,
33
+ instead of outputting json. Implies selecting those fields.
32
34
  -v, --verbose Print debug information to STDERR
33
35
  -p, --pretty[=false] Pretty-print JSON (default true when STDOUT is a TTY)
34
36
  -r, --refresh Delete cache before performing request.
35
- -h, --host URI Optica host (default "https://optica.d.musta.ch")
37
+ -h, --host URI Optica host (default "https://example.com")
36
38
  -H, --set-default-host URI Set the default optica host
37
39
 
38
40
  Examples:
@@ -46,7 +48,7 @@ Examples:
46
48
  optical --all launched_by=`whoami`
47
49
 
48
50
  SSH into the first matched node:
49
- ssh $(optical role=example branch=jake-test | head -n 1 | jq -r .hostname)
51
+ ssh $(optical --just hostname role=example branch=jake-test | head -n 1)
50
52
  ```
51
53
 
52
54
  ## Development
@@ -33,6 +33,7 @@ module Optica
33
33
  @config = ::Optica::Client::Config.from_file(CONFIG_PATH)
34
34
  @host = nil
35
35
  @fields = []
36
+ @outs = []
36
37
  @verbose = false
37
38
  @pretty = data_pipe.tty?
38
39
  @cache = ::FileCache.new(
@@ -80,6 +81,16 @@ module Optica
80
81
  @fields = nil if all
81
82
  end
82
83
 
84
+ o.on(
85
+ '-j',
86
+ '--just a,b,c',
87
+ ::Array,
88
+ 'Print just the given fields as tab-seperated strings, instead of outputting json. Implies selecting those fields.'
89
+ ) do |outs|
90
+ @outs.concat(outs)
91
+ @fields.concat(outs)
92
+ end
93
+
83
94
  o.on(
84
95
  '-v',
85
96
  '--verbose',
@@ -133,7 +144,7 @@ module Optica
133
144
  optical --all launched_by=`whoami`
134
145
 
135
146
  SSH into the first matched node:
136
- ssh $(optical role=example branch=jake-test | head -n 1 | jq -r .hostname)
147
+ ssh $(optical --just hostname role=example branch=jake-test | head -n 1)
137
148
  EOS
138
149
  end
139
150
  end
@@ -161,6 +172,10 @@ module Optica
161
172
  return ERR_INVALID
162
173
  end
163
174
 
175
+ if @outs.any? && @verbose
176
+ ui_pipe.puts "Will print only: #{@outs}"
177
+ end
178
+
164
179
  manage_cache
165
180
 
166
181
  req = ::Optica::Client::Request.new(host).where(filters)
@@ -204,7 +219,11 @@ module Optica
204
219
  end
205
220
 
206
221
  json.each do |_ip, node|
207
- string = @pretty ? JSON.pretty_generate(node) : JSON.fast_generate(node)
222
+ if @outs.any?
223
+ string = node.values_at(*@outs.uniq).join("\t")
224
+ else
225
+ string = @pretty ? JSON.pretty_generate(node) : JSON.fast_generate(node)
226
+ end
208
227
  data_pipe.puts string
209
228
  # easier Ctrl-C in Tmux
210
229
  sleep TTY_TIMEOUT if use_sleep
@@ -1,5 +1,5 @@
1
1
  module Optica
2
2
  module Client
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optica-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Teton-Landis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filecache