holistics-cli 0.1.2 → 0.2.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/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/lib/holistics.rb +1 -1
- data/lib/holistics/client.rb +13 -0
- data/lib/holistics/imports.rb +2 -3
- data/lib/holistics/jobs.rb +23 -9
- data/lib/holistics/models/job.rb +5 -0
- data/lib/holistics/transforms.rb +1 -1
- data/lib/holistics/utils.rb +1 -1
- data/lib/holistics/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 763f03645d0cb884b8ed479c3da2780552671e24
|
4
|
+
data.tar.gz: be1f71741967b9c431afaec34575f2296c464236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2eaea5ddcfeb4aebee7d05ca9d558ee847bddcf87ef005c94e97eb14c5438fb7c1a1e942750dbdcf7ea2a2bbe1ea8a7d1a664ec1f6e2514a287be4858f3c0a
|
7
|
+
data.tar.gz: 7d270cd11e0be8ce7ea3eace4e0d6615a96859c6ef523aaa31a60e26d0633e5b9e580297d4b47a6c3b0dea191dd2d393af463e7bc740eb11ebce06ca7eb84960
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Holistics CLI
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/holistics-cli)
|
3
|
+
[](https://badge.fury.io/rb/holistics-cli) [](https://codeclimate.com/github/pmint93/holistics-cli/coverage) [](https://codeclimate.com/github/pmint93/holistics-cli) [](https://codeclimate.com/github/pmint93/holistics-cli)
|
4
4
|
|
5
5
|
CommandLine Interface to [Holistics API](https://docs.holistics.io/api/)
|
6
6
|
|
7
|
-
>
|
7
|
+
> Disclaim: The official Holistics-CLI is quite limit for me, so I made this gem as an alternative
|
8
8
|
|
9
9
|
:warning: This gem use the same command `holistics` as [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/), so it may confict if both installed.
|
10
10
|
|
@@ -49,4 +49,4 @@ Everyone interacting in the Holistics-CLI project’s codebases, issue trackers,
|
|
49
49
|
|
50
50
|
## Related
|
51
51
|
|
52
|
-
* [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/)
|
52
|
+
* [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/)
|
data/lib/holistics.rb
CHANGED
@@ -56,7 +56,7 @@ module Holistics
|
|
56
56
|
unless token
|
57
57
|
current_config = configured? ? read_config : {}
|
58
58
|
current_token = current_config[:token]
|
59
|
-
new_token = ask "Your Holistics token [#{current_token.light_black}]: "
|
59
|
+
new_token = ask "Your Holistics token [#{current_token.to_s.light_black}]: "
|
60
60
|
new_token = nil if new_token.blank?
|
61
61
|
unless token = new_token || current_token
|
62
62
|
STDERR.puts 'Failed to config, empty token provided !'
|
data/lib/holistics/client.rb
CHANGED
@@ -25,6 +25,19 @@ module Holistics
|
|
25
25
|
[response.status, response.body]
|
26
26
|
end
|
27
27
|
|
28
|
+
def put(path, options = {})
|
29
|
+
options[:params] ||= {}
|
30
|
+
options[:headers] ||= {}
|
31
|
+
options[:headers].merge!('Content-Type': 'application/json')
|
32
|
+
response = @conn.put do |req|
|
33
|
+
req.url path
|
34
|
+
req.headers.merge!(options[:headers])
|
35
|
+
req.params['_utoken'] = @token
|
36
|
+
req.body = options[:params].to_s
|
37
|
+
end
|
38
|
+
[response.status, response.body]
|
39
|
+
end
|
40
|
+
|
28
41
|
def post(path, options = {})
|
29
42
|
options[:params] ||= {}
|
30
43
|
options[:headers] ||= {}
|
data/lib/holistics/imports.rb
CHANGED
@@ -61,9 +61,8 @@ Examples:
|
|
61
61
|
def execute(id)
|
62
62
|
puts "`imports execute #{id}` called with options: #{options}" if Holistics.debug?
|
63
63
|
result = @this.execute(id)
|
64
|
-
puts 'Job ID: ' + result['job_id'].to_s.yellow
|
65
|
-
|
66
|
-
invoke 'holistics:jobs:logs', [result['job_id']], { watch: true }
|
64
|
+
puts 'Job ID: ' + result['job_id'].to_s.yellow + " Submit: " + Holistics::Utils.colorize(result['status'])
|
65
|
+
invoke 'holistics:jobs:logs', [result['job_id']], { follow: true }
|
67
66
|
end
|
68
67
|
map %w[exec] => :execute
|
69
68
|
|
data/lib/holistics/jobs.rb
CHANGED
@@ -61,35 +61,49 @@ Examples:
|
|
61
61
|
method_option :number, aliases: '-n', desc: 'Only print number of last lines', type: :numeric
|
62
62
|
def logs(id)
|
63
63
|
puts "`jobs logs #{id}` called with options: #{options}" if Holistics.debug?
|
64
|
-
if options[:
|
64
|
+
if options[:follow]
|
65
65
|
last_id = 0
|
66
66
|
loop do
|
67
67
|
data = @this.logs(id, { 'last_id': last_id })
|
68
|
-
print_logs(data['logs'])
|
68
|
+
print_logs(id, data['logs'])
|
69
69
|
last_id = data['logs'].last['id'] if data['logs'].length > 0
|
70
70
|
break unless data['has_more']
|
71
71
|
sleep 0.5
|
72
72
|
end
|
73
73
|
else
|
74
74
|
data = @this.logs(id)
|
75
|
-
print_logs(data['logs'], options[:number])
|
75
|
+
print_logs(id, data['logs'], options[:number])
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
desc 'cancel', 'Cancel a running job'
|
80
|
+
def cancel(id)
|
81
|
+
puts "`jobs cancel #{id}` called with options: #{options}" if Holistics.debug?
|
82
|
+
print "Cancelling Job #{id} ...".yellow
|
83
|
+
result = @this.cancel(id)
|
84
|
+
if result['status'].to_s.upcase == 'OK'
|
85
|
+
loop do
|
86
|
+
job_info = @this.find(id)
|
87
|
+
unless job_info['status'] == 'cancelling'
|
88
|
+
puts Holistics::Utils.colorize(job_info['status'])
|
89
|
+
break
|
90
|
+
end
|
91
|
+
sleep 0.5
|
92
|
+
end
|
93
|
+
else
|
94
|
+
puts "Failed to cancel the job #{id}".red
|
95
|
+
end
|
96
|
+
end
|
83
97
|
|
84
98
|
private
|
85
99
|
|
86
|
-
def print_logs(log_lines, line_count = 0)
|
100
|
+
def print_logs(job_id, log_lines, line_count = 0)
|
87
101
|
line_count ||= 0
|
88
102
|
log_lines ||= []
|
89
103
|
log_lines[(-[line_count, log_lines.length].min)..-1]
|
90
104
|
log_lines.each do |log_line|
|
91
105
|
t = log_line['timestamp'] || Time.now.utc
|
92
|
-
puts "#{t}
|
106
|
+
puts "[#{t} ##{job_id}] #{log_line['level']}: #{log_line['message']}"
|
93
107
|
end
|
94
108
|
end
|
95
109
|
|
data/lib/holistics/models/job.rb
CHANGED
@@ -5,6 +5,11 @@ module Holistics
|
|
5
5
|
status, body = @client.get("/jobs/#{id}/logs.json", { params: params })
|
6
6
|
handle_http_result(status, body)
|
7
7
|
end
|
8
|
+
|
9
|
+
def cancel(id, params = {})
|
10
|
+
status, body = @client.put("/jobs/#{id}/cancel.json", { params: params })
|
11
|
+
handle_http_result(status, body)
|
12
|
+
end
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
data/lib/holistics/transforms.rb
CHANGED
@@ -38,7 +38,7 @@ Examples:
|
|
38
38
|
puts "`transforms execute #{id}` called with options: #{options}" if Holistics.debug?
|
39
39
|
result = @this.execute(id)
|
40
40
|
puts 'Job ID: ' + result['job_id'].to_s.yellow + " Submit: " + Holistics::Utils.colorize(result['status'])
|
41
|
-
invoke 'holistics:jobs:logs', [result['job_id']], {
|
41
|
+
invoke 'holistics:jobs:logs', [result['job_id']], { follow: true }
|
42
42
|
end
|
43
43
|
map %w[exec] => :execute
|
44
44
|
|
data/lib/holistics/utils.rb
CHANGED
@@ -4,7 +4,7 @@ module Holistics
|
|
4
4
|
COLORIZE_MAPPING = {
|
5
5
|
green: %w{active success ok},
|
6
6
|
red: %w{fail failure error cancelled},
|
7
|
-
yellow: %w{new running pending unknown}
|
7
|
+
yellow: %w{new running pending unknown cancelling}
|
8
8
|
}
|
9
9
|
def colorize(text)
|
10
10
|
color = COLORIZE_MAPPING.find { |color, values| values.include?(text) }
|
data/lib/holistics/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holistics-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thanh Pham Minh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.6.
|
194
|
+
rubygems_version: 2.6.13
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Holistics CommandLine Interface
|