bld 0.1.6 → 0.1.9
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/bin/bld +1 -1
- data/bin/build +1 -1
- data/lib/commands.rb +154 -24
- metadata +65 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e6157af2b5e12d5ee9490b4343789f7e7acf5932d3cb883bb21ec2fa68e221
|
4
|
+
data.tar.gz: 9d46125734793f9bd09a6d78b24bf873d9515b83add285d4ce978262a4cbe18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0eb8a516a0b3bf1f2d6e827159b73c3ea996049e65b2dbe3a7c9128790a51bbe62a8a694622fc73454ae9cf5bbed32a96ce350b7996c787e7904bf0734fb5c
|
7
|
+
data.tar.gz: 5e0aabe38039a3cc9e6f7e1647a5e4cc93e23bd7493f12202c53d6194021ab10bf5673ff64c5af237442598095c5afd4fb5ec1ea67c6e51c0810cf9947c45600
|
data/bin/bld
CHANGED
data/bin/build
CHANGED
data/lib/commands.rb
CHANGED
@@ -2,6 +2,127 @@
|
|
2
2
|
class BuildCLICommands
|
3
3
|
def self.index
|
4
4
|
return {
|
5
|
+
"ps": {
|
6
|
+
cli_details: { :syntax => "build ps -a <app>", :description => "List all the processes of an app",
|
7
|
+
:options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
|
8
|
+
cli_perform: Proc.new { |args, options|
|
9
|
+
app_name = options.app
|
10
|
+
if app_name.nil? || app_name.strip == ""
|
11
|
+
puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
|
12
|
+
puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
|
13
|
+
puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
user_netrc = Netrc.read
|
17
|
+
user_token = user_netrc.[]("build.io")&.password
|
18
|
+
if user_token.nil?
|
19
|
+
puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
|
20
|
+
exit(1)
|
21
|
+
end
|
22
|
+
auth = "Bearer #{user_token}"
|
23
|
+
query_params = {}
|
24
|
+
query_params.[]=(:app, app_name)
|
25
|
+
query_string = URI.encode_www_form(query_params)
|
26
|
+
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/ps?#{query_string}",
|
27
|
+
{ headers: { "Authorization" => auth } })
|
28
|
+
if res.code != 200
|
29
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
30
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
31
|
+
else
|
32
|
+
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
33
|
+
end
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
processes = JSON.parse(res.body).[]("processes")
|
37
|
+
if processes.empty?
|
38
|
+
puts(CLI::UI.fmt("{{green:›}} No processes found for app #{app_name}"))
|
39
|
+
exit(1)
|
40
|
+
end
|
41
|
+
processes.each { |process,|
|
42
|
+
puts(CLI::UI.fmt("{{gray:===}} {{bold:{{green:#{process.[]("type")}}} ({{cyan:#{process.[]("size")}}}): {{white:#{[
|
43
|
+
process.[]("command"), process.[]("args")
|
44
|
+
].compact.join(" ")}}} ({{yellow:#{process.[]("quantity")}}})}}"))
|
45
|
+
process.[]("processes").each { |instance,|
|
46
|
+
started_at = Time.parse(instance.[]("started_at")).localtime
|
47
|
+
status = if instance.[]("status") == "Running"
|
48
|
+
"{{green:up}}"
|
49
|
+
else
|
50
|
+
"{{red:down}}"
|
51
|
+
end
|
52
|
+
days_ago = ((Time.now - started_at) / 86400).to_i
|
53
|
+
hours_ago = ((Time.now - started_at) / 3600).to_i % 24
|
54
|
+
minutes_ago = ((Time.now - started_at) / 60).to_i % 60
|
55
|
+
seconds_ago = (Time.now - started_at).to_i % 60
|
56
|
+
dotiw = ""
|
57
|
+
if days_ago > 0
|
58
|
+
dotiw = "#{days_ago}d "
|
59
|
+
end
|
60
|
+
if hours_ago > 0 || days_ago > 0
|
61
|
+
dotiw += "#{hours_ago}h "
|
62
|
+
end
|
63
|
+
if minutes_ago > 0 || hours_ago > 0 || days_ago > 0
|
64
|
+
dotiw += "#{minutes_ago}m "
|
65
|
+
end
|
66
|
+
if seconds_ago > 0 || minutes_ago > 0 || hours_ago > 0 || days_ago > 0
|
67
|
+
dotiw += "#{seconds_ago}s"
|
68
|
+
end
|
69
|
+
if dotiw == ""
|
70
|
+
dotiw = "0s"
|
71
|
+
end
|
72
|
+
puts(CLI::UI.fmt("{{white:#{process.[]("type")}.#{instance.[]("index")}}}: #{status} {{gray:#{started_at} (~ #{dotiw} ago)}}"))
|
73
|
+
}
|
74
|
+
puts("")
|
75
|
+
}
|
76
|
+
},
|
77
|
+
},
|
78
|
+
"ps:restart": {
|
79
|
+
cli_details: { :syntax => "build ps:restart [PROCESS] -a <app>", :description => "Restart all the processes of an app",
|
80
|
+
:options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
|
81
|
+
cli_perform: Proc.new { |args, options|
|
82
|
+
app_name = options.app
|
83
|
+
if app_name.nil? || app_name.strip == ""
|
84
|
+
puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
|
85
|
+
puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
|
86
|
+
puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
|
87
|
+
exit(1)
|
88
|
+
end
|
89
|
+
if args.length > 1
|
90
|
+
puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
|
91
|
+
puts(CLI::UI.fmt("{{red:›}} {{gray:Too many arguments provided}}"))
|
92
|
+
puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
|
93
|
+
exit(1)
|
94
|
+
end
|
95
|
+
process = args.first
|
96
|
+
user_netrc = Netrc.read
|
97
|
+
user_token = user_netrc.[]("build.io")&.password
|
98
|
+
if user_token.nil?
|
99
|
+
puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
|
100
|
+
exit(1)
|
101
|
+
end
|
102
|
+
auth = "Bearer #{user_token}"
|
103
|
+
query_params = {}
|
104
|
+
query_params.[]=(:app, app_name)
|
105
|
+
if process
|
106
|
+
query_params.[]=(:process, process)
|
107
|
+
end
|
108
|
+
query_string = URI.encode_www_form(query_params)
|
109
|
+
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/ps/restart?#{query_string}",
|
110
|
+
{ headers: { "Authorization" => auth } })
|
111
|
+
if res.code != 200
|
112
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
113
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
114
|
+
else
|
115
|
+
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
116
|
+
end
|
117
|
+
exit(1)
|
118
|
+
end
|
119
|
+
if process
|
120
|
+
puts(CLI::UI.fmt("{{v}} Restarted process {{cyan:#{process}}} for app {{cyan:#{app_name}}}"))
|
121
|
+
else
|
122
|
+
puts(CLI::UI.fmt("{{v}} Restarted all processes for app {{cyan:#{app_name}}}"))
|
123
|
+
end
|
124
|
+
},
|
125
|
+
},
|
5
126
|
"config": {
|
6
127
|
cli_details: { :syntax => "build config -a <app>", :description => "Get the config variables for an app",
|
7
128
|
:options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
|
@@ -26,13 +147,12 @@ class BuildCLICommands
|
|
26
147
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config?#{query_string}",
|
27
148
|
{ headers: { "Authorization" => auth } })
|
28
149
|
if res.code != 200
|
29
|
-
if res.body.
|
30
|
-
puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
|
31
|
-
exit(1)
|
150
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
151
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
32
152
|
else
|
33
153
|
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
34
|
-
exit(1)
|
35
154
|
end
|
155
|
+
exit(1)
|
36
156
|
end
|
37
157
|
JSON.parse(res.body).each { |key, value|
|
38
158
|
puts("#{key}=#{value}")
|
@@ -71,13 +191,12 @@ class BuildCLICommands
|
|
71
191
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/get?#{query_string}",
|
72
192
|
{ headers: { "Authorization" => auth } })
|
73
193
|
if res.code != 200
|
74
|
-
if res.body.
|
75
|
-
puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
|
76
|
-
exit(1)
|
194
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
195
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
77
196
|
else
|
78
197
|
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
79
|
-
exit(1)
|
80
198
|
end
|
199
|
+
exit(1)
|
81
200
|
end
|
82
201
|
puts(res.body)
|
83
202
|
},
|
@@ -116,8 +235,8 @@ class BuildCLICommands
|
|
116
235
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/set?#{query_string}",
|
117
236
|
{ headers: { "Authorization" => auth } })
|
118
237
|
if res.code != 200
|
119
|
-
if res.body && res.body.
|
120
|
-
puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
|
238
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
239
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
121
240
|
else
|
122
241
|
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
123
242
|
end
|
@@ -158,8 +277,8 @@ class BuildCLICommands
|
|
158
277
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/unset?#{query_string}",
|
159
278
|
{ headers: { "Authorization" => auth } })
|
160
279
|
if res.code != 200
|
161
|
-
if res.body && res.body.
|
162
|
-
puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
|
280
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
281
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
163
282
|
else
|
164
283
|
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
165
284
|
end
|
@@ -214,9 +333,10 @@ class BuildCLICommands
|
|
214
333
|
exit
|
215
334
|
end
|
216
335
|
(user_token, user_email) = nil
|
336
|
+
client_secret = SecureRandom.uuid
|
337
|
+
oauth_url = "#{ANTIMONY_HOST}/cli_auth/authorize/#{client_secret}"
|
338
|
+
puts(CLI::UI.fmt("Opening browser to {{underline:#{oauth_url}}}"))
|
217
339
|
CLI::UI::Spinner.spin("Waiting for login") { |spinner,|
|
218
|
-
client_secret = SecureRandom.uuid
|
219
|
-
oauth_url = "#{ANTIMONY_HOST}/cli_auth/authorize/#{client_secret}"
|
220
340
|
Launchy.open(oauth_url)
|
221
341
|
poll_interval = 1
|
222
342
|
timeout = (5 * 60)
|
@@ -238,10 +358,14 @@ class BuildCLICommands
|
|
238
358
|
break
|
239
359
|
end
|
240
360
|
}
|
241
|
-
user_netrc = Netrc.read
|
242
|
-
user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
|
243
|
-
user_netrc.save
|
244
361
|
}
|
362
|
+
if user_token.nil? || user_email.nil? || user_token.empty? || user_email.empty?
|
363
|
+
puts(CLI::UI.fmt("{{red:Login failed}}"))
|
364
|
+
exit(1)
|
365
|
+
end
|
366
|
+
user_netrc = Netrc.read
|
367
|
+
user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
|
368
|
+
user_netrc.save
|
245
369
|
puts(CLI::UI.fmt("Logged in as {{green:#{user_email}}}"))
|
246
370
|
},
|
247
371
|
},
|
@@ -283,9 +407,11 @@ class BuildCLICommands
|
|
283
407
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/apps/#{app_name}/logs/log_url?#{query_string}",
|
284
408
|
{ headers: { "Authorization" => auth } })
|
285
409
|
if res.code != 200
|
286
|
-
|
287
|
-
|
288
|
-
|
410
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
411
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
412
|
+
else
|
413
|
+
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
414
|
+
end
|
289
415
|
exit(1)
|
290
416
|
end
|
291
417
|
log_url = res.[]("url")
|
@@ -331,7 +457,11 @@ class BuildCLICommands
|
|
331
457
|
exit(1)
|
332
458
|
end
|
333
459
|
user_netrc = Netrc.read
|
334
|
-
user_token = user_netrc.[]("build.io")
|
460
|
+
user_token = user_netrc.[]("build.io")&.password
|
461
|
+
if user_token.nil?
|
462
|
+
puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
|
463
|
+
exit(1)
|
464
|
+
end
|
335
465
|
auth = "Bearer #{user_token}"
|
336
466
|
query_params = {}
|
337
467
|
if options.app
|
@@ -341,10 +471,10 @@ class BuildCLICommands
|
|
341
471
|
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
|
342
472
|
{ headers: { "Authorization" => auth } })
|
343
473
|
if res.code != 200
|
344
|
-
if res.body.
|
345
|
-
puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
|
474
|
+
if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
|
475
|
+
puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
|
346
476
|
else
|
347
|
-
puts(CLI::UI.fmt("{{red:›}} Error:
|
477
|
+
puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
|
348
478
|
end
|
349
479
|
exit(1)
|
350
480
|
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- usiegl00
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: abbrev
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: base64
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bigdecimal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: csv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: public_suffix
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,22 +180,22 @@ dependencies:
|
|
124
180
|
name: net-ssh
|
125
181
|
requirement: !ruby/object:Gem::Requirement
|
126
182
|
requirements:
|
127
|
-
- - "~>"
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '6.1'
|
130
183
|
- - ">="
|
131
184
|
- !ruby/object:Gem::Version
|
132
185
|
version: 6.1.0
|
186
|
+
- - "<="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 7.2.1
|
133
189
|
type: :runtime
|
134
190
|
prerelease: false
|
135
191
|
version_requirements: !ruby/object:Gem::Requirement
|
136
192
|
requirements:
|
137
|
-
- - "~>"
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version: '6.1'
|
140
193
|
- - ">="
|
141
194
|
- !ruby/object:Gem::Version
|
142
195
|
version: 6.1.0
|
196
|
+
- - "<="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 7.2.1
|
143
199
|
description: CLI for build.io
|
144
200
|
email: 50933431+usiegl00@users.noreply.github.com
|
145
201
|
executables:
|
@@ -181,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
237
|
- !ruby/object:Gem::Version
|
182
238
|
version: '0'
|
183
239
|
requirements: []
|
184
|
-
rubygems_version: 3.
|
240
|
+
rubygems_version: 3.5.3
|
185
241
|
signing_key:
|
186
242
|
specification_version: 4
|
187
243
|
summary: build cli
|