rbdash 0.2.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 +4 -4
- data/lib/rbdash.rb +1 -1
- data/lib/rbdash/cli.rb +39 -13
- data/lib/rbdash/cli/pull.rb +34 -3
- data/lib/rbdash/cli/push.rb +11 -9
- data/lib/rbdash/models/base_model.rb +9 -8
- data/lib/rbdash/models/query.rb +0 -1
- data/lib/rbdash/utils.rb +15 -0
- data/lib/rbdash/version.rb +1 -1
- metadata +2 -2
- data/lib/rbdash/cli/push_all.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb38bbb5168551aa34c9d8b19a7365257c5eafc0
|
4
|
+
data.tar.gz: 797eab469029bd4e9f82489b8f51513e24574104
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05f284cbae5b8cb5749b1aea82de9af83ba3267daa26bbe6d7a53b32f1c2fe0dd86827929a56eb66a3585cee2432ba0b4f6be62ca903471de884ed8f1e1e2ee
|
7
|
+
data.tar.gz: 0a5127285700d4401575ca46cc3ee4ccfd207c69f31db3abda15f7d0505b9fc635133a31eeec92af6fe74cc2a30a0059684a45693b17d420c23df7b73a280d0e
|
data/lib/rbdash.rb
CHANGED
data/lib/rbdash/cli.rb
CHANGED
@@ -3,6 +3,8 @@ require 'thor'
|
|
3
3
|
module Rbdash
|
4
4
|
class CLI < Thor
|
5
5
|
include Thor::Actions
|
6
|
+
OPT_DRY_RUN = 'dry-run'.freeze
|
7
|
+
OPT_ALL = 'all'.freeze
|
6
8
|
|
7
9
|
desc 'init', 'create a configuration file.'
|
8
10
|
def init
|
@@ -13,26 +15,50 @@ module Rbdash
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
desc 'pull', 'pulls existing configurations.'
|
17
|
-
method_option
|
18
|
-
|
19
|
-
|
18
|
+
desc 'pull <id1> <id2> ... [options]', 'pulls existing remote configurations.'
|
19
|
+
method_option OPT_DRY_RUN
|
20
|
+
method_option OPT_ALL
|
21
|
+
def pull(*ids)
|
22
|
+
if all? && !ids.empty?
|
23
|
+
puts "'CONFLICT: Cannot assign ids with --#{OPT_ALL} option.'"
|
24
|
+
return
|
25
|
+
end
|
26
|
+
if !all? && ids.empty?
|
27
|
+
puts "'You may pass either ids or --#{OPT_ALL} option.'"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
CLI::Pull.new.run(*ids, command_options)
|
20
32
|
end
|
21
33
|
|
22
|
-
desc 'push <id1> <id2> ...', 'push configurations'
|
23
|
-
method_option
|
34
|
+
desc 'push <id1> <id2> ... [options]', 'push local configurations to remote.'
|
35
|
+
method_option OPT_DRY_RUN
|
36
|
+
method_option OPT_ALL
|
24
37
|
def push(*ids)
|
25
|
-
if
|
26
|
-
|
38
|
+
if all? && !ids.empty?
|
39
|
+
puts "'CONFLICT: Cannot assign ids with --#{OPT_ALL} option.'"
|
40
|
+
return
|
41
|
+
end
|
42
|
+
if !all? && ids.empty?
|
43
|
+
puts "'You may pass either ids or --#{OPT_ALL} option.'"
|
27
44
|
return
|
28
45
|
end
|
29
|
-
|
46
|
+
|
47
|
+
CLI::Push.new.run(*ids, command_options)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def command_options
|
53
|
+
{ is_all: all?, is_dry: dry? }
|
54
|
+
end
|
55
|
+
|
56
|
+
def dry?
|
57
|
+
options[OPT_DRY_RUN]
|
30
58
|
end
|
31
59
|
|
32
|
-
|
33
|
-
|
34
|
-
def push_all
|
35
|
-
CLI::PushAll.new.run
|
60
|
+
def all?
|
61
|
+
options[OPT_ALL]
|
36
62
|
end
|
37
63
|
end
|
38
64
|
end
|
data/lib/rbdash/cli/pull.rb
CHANGED
@@ -1,8 +1,39 @@
|
|
1
1
|
module Rbdash
|
2
2
|
class CLI::Pull
|
3
|
-
def run
|
4
|
-
|
5
|
-
queries
|
3
|
+
def run(*ids, **options)
|
4
|
+
# find remote queries
|
5
|
+
queries = if options[:is_all]
|
6
|
+
Rbdash::Models::Query.find_all
|
7
|
+
else
|
8
|
+
ids.map do |id|
|
9
|
+
Rbdash::Models::Query.find(id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
# save
|
13
|
+
queries.each do |query|
|
14
|
+
show_diff(query)
|
15
|
+
next if options[:is_dry]
|
16
|
+
|
17
|
+
# update local states
|
18
|
+
query.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def show_diff(query)
|
25
|
+
id = query.id
|
26
|
+
local_state = Rbdash::Models::Query.load(id)
|
27
|
+
diff = Diffy::Diff.new(local_state.to_json, query.to_json, diff_opt).to_s(:color)
|
28
|
+
|
29
|
+
unless diff.chomp.empty?
|
30
|
+
puts "[changed] #{id}"
|
31
|
+
puts diff
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def diff_opt
|
36
|
+
{ include_diff_info: true, context: 2 }
|
6
37
|
end
|
7
38
|
end
|
8
39
|
end
|
data/lib/rbdash/cli/push.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
require 'diffy'
|
2
2
|
module Rbdash
|
3
3
|
class CLI::Push
|
4
|
-
|
5
|
-
|
4
|
+
def run(*ids, **options)
|
5
|
+
ids = Utils.find_local_ids if options[:is_all]
|
6
6
|
ids.each do |id|
|
7
7
|
show_diff(id)
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
8
|
+
next if options[:is_dry]
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
show_diff(id)
|
10
|
+
# update remote resources
|
11
|
+
update(id)
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
@@ -24,7 +21,12 @@ module Rbdash
|
|
24
21
|
def show_diff(id)
|
25
22
|
remote_state = Rbdash::Models::Query.find(id)
|
26
23
|
local_state = Rbdash::Models::Query.load(id)
|
27
|
-
|
24
|
+
diff = Diffy::Diff.new(remote_state.to_json, local_state.to_json, diff_opt).to_s(:color)
|
25
|
+
|
26
|
+
unless diff.chomp.empty?
|
27
|
+
puts "[changed] #{id}"
|
28
|
+
puts diff
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
def diff_opt
|
@@ -3,10 +3,11 @@ require_relative '../request'
|
|
3
3
|
module Rbdash
|
4
4
|
module Models
|
5
5
|
class BaseModel
|
6
|
-
attr_accessor :body
|
6
|
+
attr_accessor :body, :id
|
7
7
|
|
8
|
-
def initialize(body)
|
8
|
+
def initialize(body, id)
|
9
9
|
@body = body
|
10
|
+
@id = id
|
10
11
|
end
|
11
12
|
|
12
13
|
def to_json
|
@@ -14,7 +15,6 @@ module Rbdash
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def save
|
17
|
-
id = @body['id']
|
18
18
|
dirname = self.class.dirname
|
19
19
|
Dir.mkdir(dirname) unless File.exist?(dirname)
|
20
20
|
filename = "#{dirname}/query-#{id}.json"
|
@@ -37,7 +37,7 @@ module Rbdash
|
|
37
37
|
end
|
38
38
|
h = JSON.parse(response.body)
|
39
39
|
body = h.select { |k, _| attributes.map(&:to_s).include?(k) }
|
40
|
-
new(body)
|
40
|
+
new(body, id)
|
41
41
|
end
|
42
42
|
|
43
43
|
def find_all
|
@@ -52,7 +52,8 @@ module Rbdash
|
|
52
52
|
results = h['results']
|
53
53
|
all_results += results.map do |result|
|
54
54
|
body = result.select { |k, _| attributes.map(&:to_s).include?(k) }
|
55
|
-
|
55
|
+
id = result['id']
|
56
|
+
new(body, id)
|
56
57
|
end
|
57
58
|
|
58
59
|
count = h['count']
|
@@ -76,10 +77,10 @@ module Rbdash
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def load(id)
|
79
|
-
file =
|
80
|
-
|
80
|
+
file = Utils.find_local_file(id)
|
81
|
+
return new(nil, id) unless file
|
81
82
|
body = JSON.parse(File.read(file))
|
82
|
-
new(body)
|
83
|
+
new(body, id)
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
data/lib/rbdash/models/query.rb
CHANGED
data/lib/rbdash/utils.rb
ADDED
data/lib/rbdash/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbdash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shotat
|
@@ -129,10 +129,10 @@ files:
|
|
129
129
|
- lib/rbdash/cli.rb
|
130
130
|
- lib/rbdash/cli/pull.rb
|
131
131
|
- lib/rbdash/cli/push.rb
|
132
|
-
- lib/rbdash/cli/push_all.rb
|
133
132
|
- lib/rbdash/models/base_model.rb
|
134
133
|
- lib/rbdash/models/query.rb
|
135
134
|
- lib/rbdash/request.rb
|
135
|
+
- lib/rbdash/utils.rb
|
136
136
|
- lib/rbdash/version.rb
|
137
137
|
- local_install.sh
|
138
138
|
- rbdash.gemspec
|