yq 0.3.1 → 0.4.0
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 +5 -5
- data/.travis.yml +3 -2
- data/bin/yq +14 -8
- data/lib/yq.rb +12 -6
- data/lib/yq/version.rb +1 -1
- data/spec/yq_spec.rb +19 -9
- data/yq.gemspec +0 -2
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d07d7b73032c8c61bbf2f18b8b9de799c52cbddeef69386953ebeb74fad9b009
|
4
|
+
data.tar.gz: 35fd24192ad40d080f3b0a1a3217930ff41b0f96ad3f57e32bfc0ad990f04e27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b279062178bf1b4179de42208cc6e8eb98d831cdf7ffd75bc5a4e6ad8fc963f2a6871f52ecb72bc1efa4fcac2e1a5483f25b1c730c0c8b134bb5adcba75055
|
7
|
+
data.tar.gz: b52bbb79b6ee17a28a6fce17ca0c5c4354b1c9b4a899afcb869bd46376ea8b319b85f9ba136aeae6ceacd8c00dea19c739c0209bc4e18649ed3f22b54c0b5da8
|
data/.travis.yml
CHANGED
data/bin/yq
CHANGED
@@ -9,16 +9,16 @@ require 'yq'
|
|
9
9
|
|
10
10
|
$stdout.sync = $stderr.sync = true
|
11
11
|
unless defined?(LOGGER)
|
12
|
-
LOGGER = Logger.new($stderr)
|
12
|
+
LOGGER = Logger.new($stderr)
|
13
13
|
end
|
14
14
|
LOGGER.level = Logger::INFO
|
15
15
|
|
16
16
|
@options = {
|
17
|
-
context: :main_loop
|
17
|
+
context: :main_loop,
|
18
|
+
output: :yaml
|
18
19
|
}
|
19
20
|
|
20
|
-
|
21
|
-
def prereqs
|
21
|
+
def prereqs
|
22
22
|
ARGV << '--help' if ARGV.empty?
|
23
23
|
|
24
24
|
opts = OptionParser.new do |opts|
|
@@ -28,15 +28,21 @@ def prereqs
|
|
28
28
|
puts opts
|
29
29
|
exit 0
|
30
30
|
end
|
31
|
-
opts.on('--verbose', '-v', 'verbose') do
|
31
|
+
opts.on('--verbose', '-v', 'verbose') do
|
32
32
|
LOGGER.level = Logger::DEBUG
|
33
33
|
end
|
34
34
|
opts.on("--develop", "Run in developer mode") do
|
35
35
|
@options[:context] = :develop
|
36
36
|
end
|
37
|
+
opts.on('-r', '--raw-output') do
|
38
|
+
@options[:output] = :raw
|
39
|
+
end
|
40
|
+
opts.on('--json-output') do
|
41
|
+
@options[:output] = :json
|
42
|
+
end
|
37
43
|
end
|
38
44
|
opts.parse!
|
39
|
-
|
45
|
+
|
40
46
|
required_vars = %w[
|
41
47
|
]
|
42
48
|
required_vars.each do |v|
|
@@ -51,7 +57,7 @@ def start
|
|
51
57
|
begin
|
52
58
|
@yaml = $stdin.read
|
53
59
|
|
54
|
-
puts Yq.search_yaml(ARGV[0], @yaml)
|
60
|
+
puts Yq.search_yaml(ARGV[0], @yaml, output: @options[:output])
|
55
61
|
|
56
62
|
rescue => e
|
57
63
|
LOGGER.error "Unhandled exception #{e.class}: #{e.message}"
|
@@ -76,4 +82,4 @@ end
|
|
76
82
|
|
77
83
|
|
78
84
|
prereqs
|
79
|
-
self.send(@options[:context])
|
85
|
+
self.send(@options[:context])
|
data/lib/yq.rb
CHANGED
@@ -15,20 +15,26 @@ module Yq
|
|
15
15
|
return nil
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.search_yaml(query, yaml)
|
18
|
+
def self.search_yaml(query, yaml, output: :yaml)
|
19
19
|
req_json = yaml_to_json(yaml)
|
20
|
+
case output
|
21
|
+
when :raw
|
22
|
+
search(query, req_json, flags: ['--raw-output'])
|
23
|
+
when :json
|
24
|
+
search(query, req_json)
|
25
|
+
when :yaml
|
20
26
|
resp_json = search(query, req_json)
|
21
|
-
|
22
|
-
|
27
|
+
json_to_yaml(resp_json)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
|
-
def self.search(query, json)
|
26
|
-
cmd = which('jq') +
|
31
|
+
def self.search(query, json, flags: [])
|
32
|
+
cmd = [which('jq')] + flags + [query]
|
27
33
|
input = json
|
28
34
|
output = ""
|
29
35
|
LOGGER.debug "sending jq #{cmd}"
|
30
36
|
|
31
|
-
Open3.popen2(cmd) do |i, o, t|
|
37
|
+
Open3.popen2(*cmd) do |i, o, t|
|
32
38
|
begin
|
33
39
|
pid = t.pid
|
34
40
|
|
data/lib/yq/version.rb
CHANGED
data/spec/yq_spec.rb
CHANGED
@@ -2,22 +2,31 @@ describe Yq do
|
|
2
2
|
subject { described_class }
|
3
3
|
|
4
4
|
let(:hash) {
|
5
|
-
{ "foo" => { "bar" => { "
|
5
|
+
{ "foo" => { "bar" => { "'" => "value" }}}
|
6
6
|
}
|
7
7
|
|
8
8
|
let(:yaml) {<<EOF}
|
9
9
|
foo:
|
10
10
|
bar:
|
11
|
-
|
11
|
+
"'": value
|
12
|
+
EOF
|
13
|
+
|
14
|
+
# support equivalent YAML syntaxes (depends on ruby version)
|
15
|
+
let(:yaml_regexp) {<<EOF}
|
16
|
+
foo:
|
17
|
+
bar:
|
18
|
+
("'"|''''|! ''''): value
|
12
19
|
EOF
|
13
20
|
|
14
21
|
let(:json) {<<EOF.chomp}
|
15
|
-
{"foo":{"bar":{"
|
22
|
+
{"foo":{"bar":{"'":"value"}}}
|
16
23
|
EOF
|
17
24
|
|
25
|
+
let(:jq_query) { %q({"\\t": .foo.bar["'"]}) }
|
26
|
+
|
18
27
|
let(:jq_response) {<<EOF}
|
19
28
|
{
|
20
|
-
"
|
29
|
+
"\\t": "value"
|
21
30
|
}
|
22
31
|
EOF
|
23
32
|
|
@@ -73,13 +82,14 @@ EOF
|
|
73
82
|
EOF
|
74
83
|
|
75
84
|
describe '.search' do
|
76
|
-
|
85
|
+
|
86
|
+
subject { described_class.search(jq_query, json) }
|
77
87
|
|
78
88
|
it { is_expected.to match(jq_response) }
|
79
89
|
|
80
90
|
it 'passes it through to jq' do
|
81
91
|
allow(Yq).to receive(:which).with('jq').and_return('/bin/jq')
|
82
|
-
expect(Open3).to receive(:popen2).with(
|
92
|
+
expect(Open3).to receive(:popen2).with('/bin/jq' , jq_query).and_return(jq_response)
|
83
93
|
subject
|
84
94
|
end
|
85
95
|
|
@@ -99,7 +109,7 @@ EOF
|
|
99
109
|
|
100
110
|
describe '.hash_to_yaml' do
|
101
111
|
subject { described_class.hash_to_yaml(hash) }
|
102
|
-
it { is_expected.to match(
|
112
|
+
it { is_expected.to match(yaml_regexp) }
|
103
113
|
end
|
104
114
|
|
105
115
|
describe '.yaml_to_json' do
|
@@ -109,7 +119,7 @@ EOF
|
|
109
119
|
|
110
120
|
describe '.json_to_yaml' do
|
111
121
|
subject { described_class.json_to_yaml(json) }
|
112
|
-
it { is_expected.to match(
|
122
|
+
it { is_expected.to match(yaml_regexp) }
|
113
123
|
|
114
124
|
context 'non-json response' do
|
115
125
|
subject { described_class.json_to_yaml(jq_non_json_response) }
|
@@ -125,7 +135,7 @@ EOF
|
|
125
135
|
describe '.search_yaml' do
|
126
136
|
subject { described_class.search_yaml('.foo.bar', yaml) }
|
127
137
|
|
128
|
-
it { is_expected.to match("
|
138
|
+
it { is_expected.to match(/("'"|''''|! ''''): value/) }
|
129
139
|
end
|
130
140
|
|
131
141
|
|
data/yq.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Park
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: json2yaml
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
description: |-
|
84
70
|
This unceremoniously shells out to a jq available in $PATH.
|
85
71
|
Please make sure jq is installed.
|
@@ -125,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
111
|
version: '0'
|
126
112
|
requirements: []
|
127
113
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.7.7
|
129
115
|
signing_key:
|
130
116
|
specification_version: 4
|
131
117
|
summary: A JQ wrapper for YAML
|