bld 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bld +1 -1
  3. data/bin/build +1 -1
  4. data/lib/commands.rb +116 -25
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a83ec4051e6559929aaf5a9bd63b4942e720a38e1646585b45dd92118dd9c64
4
- data.tar.gz: 4830cfc9f99c939fe2d6d5cf5cb51d8f1944006d9cd100398def42bb9f2b53f5
3
+ metadata.gz: b5e6157af2b5e12d5ee9490b4343789f7e7acf5932d3cb883bb21ec2fa68e221
4
+ data.tar.gz: 9d46125734793f9bd09a6d78b24bf873d9515b83add285d4ce978262a4cbe18f
5
5
  SHA512:
6
- metadata.gz: 3f46dbef1d40982c49622fae11a1ac9c3122e0e6c976daad1140e1d2c560edafbdd65a0dd9419ba54b03e732502e6235e32158ce6ea574a1e7eb18d073867128
7
- data.tar.gz: d731e18fecd9c703d9bc992ffbcaf467d877ad5dd9601f9f42b774cb576268eb67c56b451d02231df21510d1cccb8390fdb990a31da70a21ad4f4fac540588de
6
+ metadata.gz: dc0eb8a516a0b3bf1f2d6e827159b73c3ea996049e65b2dbe3a7c9128790a51bbe62a8a694622fc73454ae9cf5bbed32a96ce350b7996c787e7904bf0734fb5c
7
+ data.tar.gz: 5e0aabe38039a3cc9e6f7e1647a5e4cc93e23bd7493f12202c53d6194021ab10bf5673ff64c5af237442598095c5afd4fb5ec1ea67c6e51c0810cf9947c45600
data/bin/bld CHANGED
@@ -20,7 +20,7 @@ class BuildCLI
20
20
 
21
21
  def run
22
22
  program :name, 'Build CLI'
23
- program :version, '0.1.7'
23
+ program :version, '0.1.9'
24
24
  program :description, "Build's Command Line Interface"
25
25
  program :int_block, -> { exit }
26
26
  default_command :help
data/bin/build CHANGED
@@ -20,7 +20,7 @@ class BuildCLI
20
20
 
21
21
  def run
22
22
  program :name, 'Build CLI'
23
- program :version, '0.1.7'
23
+ program :version, '0.1.9'
24
24
  program :description, "Build's Command Line Interface"
25
25
  program :int_block, -> { exit }
26
26
  default_command :help
data/lib/commands.rb CHANGED
@@ -2,8 +2,81 @@
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
+ },
5
78
  "ps:restart": {
6
- cli_details: { :syntax => "build ps:restart -a <app>", :description => "Restart all the processes of an app",
79
+ cli_details: { :syntax => "build ps:restart [PROCESS] -a <app>", :description => "Restart all the processes of an app",
7
80
  :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
8
81
  cli_perform: Proc.new { |args, options|
9
82
  app_name = options.app
@@ -13,6 +86,13 @@ class BuildCLICommands
13
86
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
14
87
  exit(1)
15
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
16
96
  user_netrc = Netrc.read
17
97
  user_token = user_netrc.[]("build.io")&.password
18
98
  if user_token.nil?
@@ -22,19 +102,25 @@ class BuildCLICommands
22
102
  auth = "Bearer #{user_token}"
23
103
  query_params = {}
24
104
  query_params.[]=(:app, app_name)
105
+ if process
106
+ query_params.[]=(:process, process)
107
+ end
25
108
  query_string = URI.encode_www_form(query_params)
26
109
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/ps/restart?#{query_string}",
27
110
  { headers: { "Authorization" => auth } })
28
111
  if res.code != 200
29
- if res.body.[]("error")
30
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
31
- exit(1)
112
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
113
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
32
114
  else
33
115
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
34
- exit(1)
35
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}}}"))
36
123
  end
37
- puts(CLI::UI.fmt("{{v}} Restarted all processes for app {{cyan:#{app_name}}}"))
38
124
  },
39
125
  },
40
126
  "config": {
@@ -61,8 +147,8 @@ class BuildCLICommands
61
147
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config?#{query_string}",
62
148
  { headers: { "Authorization" => auth } })
63
149
  if res.code != 200
64
- if res.body.[]("error")
65
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
150
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
151
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
66
152
  else
67
153
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
68
154
  end
@@ -105,13 +191,12 @@ class BuildCLICommands
105
191
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/get?#{query_string}",
106
192
  { headers: { "Authorization" => auth } })
107
193
  if res.code != 200
108
- if res.body.[]("error")
109
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
110
- 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")}"))
111
196
  else
112
197
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
113
- exit(1)
114
198
  end
199
+ exit(1)
115
200
  end
116
201
  puts(res.body)
117
202
  },
@@ -150,8 +235,8 @@ class BuildCLICommands
150
235
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/set?#{query_string}",
151
236
  { headers: { "Authorization" => auth } })
152
237
  if res.code != 200
153
- if res.body && res.body.[]("error")
154
- 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")}"))
155
240
  else
156
241
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
157
242
  end
@@ -192,8 +277,8 @@ class BuildCLICommands
192
277
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/unset?#{query_string}",
193
278
  { headers: { "Authorization" => auth } })
194
279
  if res.code != 200
195
- if res.body && res.body.[]("error")
196
- 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")}"))
197
282
  else
198
283
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
199
284
  end
@@ -273,10 +358,14 @@ class BuildCLICommands
273
358
  break
274
359
  end
275
360
  }
276
- user_netrc = Netrc.read
277
- user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
278
- user_netrc.save
279
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
280
369
  puts(CLI::UI.fmt("Logged in as {{green:#{user_email}}}"))
281
370
  },
282
371
  },
@@ -318,9 +407,11 @@ class BuildCLICommands
318
407
  res = HTTParty.get("#{ANTIMONY_HOST}/api/apps/#{app_name}/logs/log_url?#{query_string}",
319
408
  { headers: { "Authorization" => auth } })
320
409
  if res.code != 200
321
- puts(CLI::UI.fmt("{{red:›}} Error: Couldn't find that app."))
322
- puts(CLI::UI.fmt("{{red:›}}"))
323
- puts(CLI::UI.fmt("{{red:›}} Error ID: not_found"))
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
324
415
  exit(1)
325
416
  end
326
417
  log_url = res.[]("url")
@@ -380,10 +471,10 @@ class BuildCLICommands
380
471
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
381
472
  { headers: { "Authorization" => auth } })
382
473
  if res.code != 200
383
- if res.body.[]("error")
384
- 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")}"))
385
476
  else
386
- puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
477
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
387
478
  end
388
479
  exit(1)
389
480
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
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-05 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abbrev