bld 0.1.7 → 0.1.10

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.
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 +114 -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: 78bc9cfc7bc1572671feab14e8fd08abb1ae8a8aa470c0f0a984772758159e88
4
+ data.tar.gz: e187478177849bc5fa26cd8649527189ed44749204dd62b0330a97a169025cb4
5
5
  SHA512:
6
- metadata.gz: 3f46dbef1d40982c49622fae11a1ac9c3122e0e6c976daad1140e1d2c560edafbdd65a0dd9419ba54b03e732502e6235e32158ce6ea574a1e7eb18d073867128
7
- data.tar.gz: d731e18fecd9c703d9bc992ffbcaf467d877ad5dd9601f9f42b774cb576268eb67c56b451d02231df21510d1cccb8390fdb990a31da70a21ad4f4fac540588de
6
+ metadata.gz: 1d54dfac9875947c80abf80bc7278c14138ae418136839cdc2c051906d132945b4026429abe97a9f779f674dcc18011cbe04e91e8ec467b013073b5de53f13f2
7
+ data.tar.gz: 7b983df8db6928b1119ab87abb01f56c339c16ff7ac515d51da0fc96ce6b95f009e0194a899f70d497a2b0f9c8860437ee956487f32d4262cb2583017276f0b1
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.10'
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.10'
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,79 @@
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:#{process.[]("display")}}} ({{yellow:#{process.[]("quantity")}}})}}"))
43
+ process.[]("processes").each { |instance,|
44
+ started_at = Time.parse(instance.[]("started_at")).localtime
45
+ status = if instance.[]("status") == "Running"
46
+ "{{green:up}}"
47
+ else
48
+ "{{red:down}}"
49
+ end
50
+ days_ago = ((Time.now - started_at) / 86400).to_i
51
+ hours_ago = ((Time.now - started_at) / 3600).to_i % 24
52
+ minutes_ago = ((Time.now - started_at) / 60).to_i % 60
53
+ seconds_ago = (Time.now - started_at).to_i % 60
54
+ dotiw = ""
55
+ if days_ago > 0
56
+ dotiw = "#{days_ago}d "
57
+ end
58
+ if hours_ago > 0 || days_ago > 0
59
+ dotiw += "#{hours_ago}h "
60
+ end
61
+ if minutes_ago > 0 || hours_ago > 0 || days_ago > 0
62
+ dotiw += "#{minutes_ago}m "
63
+ end
64
+ if seconds_ago > 0 || minutes_ago > 0 || hours_ago > 0 || days_ago > 0
65
+ dotiw += "#{seconds_ago}s"
66
+ end
67
+ if dotiw == ""
68
+ dotiw = "0s"
69
+ end
70
+ puts(CLI::UI.fmt("{{white:#{process.[]("type")}.#{instance.[]("index")}}}: #{status} {{gray:#{started_at} (~ #{dotiw} ago)}}"))
71
+ }
72
+ puts("")
73
+ }
74
+ },
75
+ },
5
76
  "ps:restart": {
6
- cli_details: { :syntax => "build ps:restart -a <app>", :description => "Restart all the processes of an app",
77
+ cli_details: { :syntax => "build ps:restart [PROCESS] -a <app>", :description => "Restart all the processes of an app",
7
78
  :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
8
79
  cli_perform: Proc.new { |args, options|
9
80
  app_name = options.app
@@ -13,6 +84,13 @@ class BuildCLICommands
13
84
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
14
85
  exit(1)
15
86
  end
87
+ if args.length > 1
88
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
89
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Too many arguments provided}}"))
90
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
91
+ exit(1)
92
+ end
93
+ process = args.first
16
94
  user_netrc = Netrc.read
17
95
  user_token = user_netrc.[]("build.io")&.password
18
96
  if user_token.nil?
@@ -22,19 +100,25 @@ class BuildCLICommands
22
100
  auth = "Bearer #{user_token}"
23
101
  query_params = {}
24
102
  query_params.[]=(:app, app_name)
103
+ if process
104
+ query_params.[]=(:process, process)
105
+ end
25
106
  query_string = URI.encode_www_form(query_params)
26
107
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/ps/restart?#{query_string}",
27
108
  { headers: { "Authorization" => auth } })
28
109
  if res.code != 200
29
- if res.body.[]("error")
30
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
31
- exit(1)
110
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
111
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
32
112
  else
33
113
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
34
- exit(1)
35
114
  end
115
+ exit(1)
116
+ end
117
+ if process
118
+ puts(CLI::UI.fmt("{{v}} Restarted process {{cyan:#{process}}} for app {{cyan:#{app_name}}}"))
119
+ else
120
+ puts(CLI::UI.fmt("{{v}} Restarted all processes for app {{cyan:#{app_name}}}"))
36
121
  end
37
- puts(CLI::UI.fmt("{{v}} Restarted all processes for app {{cyan:#{app_name}}}"))
38
122
  },
39
123
  },
40
124
  "config": {
@@ -61,8 +145,8 @@ class BuildCLICommands
61
145
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config?#{query_string}",
62
146
  { headers: { "Authorization" => auth } })
63
147
  if res.code != 200
64
- if res.body.[]("error")
65
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
148
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
149
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
66
150
  else
67
151
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
68
152
  end
@@ -105,13 +189,12 @@ class BuildCLICommands
105
189
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/get?#{query_string}",
106
190
  { headers: { "Authorization" => auth } })
107
191
  if res.code != 200
108
- if res.body.[]("error")
109
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
110
- exit(1)
192
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
193
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
111
194
  else
112
195
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
113
- exit(1)
114
196
  end
197
+ exit(1)
115
198
  end
116
199
  puts(res.body)
117
200
  },
@@ -150,8 +233,8 @@ class BuildCLICommands
150
233
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/set?#{query_string}",
151
234
  { headers: { "Authorization" => auth } })
152
235
  if res.code != 200
153
- if res.body && res.body.[]("error")
154
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
236
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
237
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
155
238
  else
156
239
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
157
240
  end
@@ -192,8 +275,8 @@ class BuildCLICommands
192
275
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/unset?#{query_string}",
193
276
  { headers: { "Authorization" => auth } })
194
277
  if res.code != 200
195
- if res.body && res.body.[]("error")
196
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
278
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
279
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
197
280
  else
198
281
  puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
199
282
  end
@@ -273,10 +356,14 @@ class BuildCLICommands
273
356
  break
274
357
  end
275
358
  }
276
- user_netrc = Netrc.read
277
- user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
278
- user_netrc.save
279
359
  }
360
+ if user_token.nil? || user_email.nil? || user_token.empty? || user_email.empty?
361
+ puts(CLI::UI.fmt("{{red:Login failed}}"))
362
+ exit(1)
363
+ end
364
+ user_netrc = Netrc.read
365
+ user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
366
+ user_netrc.save
280
367
  puts(CLI::UI.fmt("Logged in as {{green:#{user_email}}}"))
281
368
  },
282
369
  },
@@ -318,9 +405,11 @@ class BuildCLICommands
318
405
  res = HTTParty.get("#{ANTIMONY_HOST}/api/apps/#{app_name}/logs/log_url?#{query_string}",
319
406
  { headers: { "Authorization" => auth } })
320
407
  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"))
408
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
409
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
410
+ else
411
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
412
+ end
324
413
  exit(1)
325
414
  end
326
415
  log_url = res.[]("url")
@@ -380,10 +469,10 @@ class BuildCLICommands
380
469
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
381
470
  { headers: { "Authorization" => auth } })
382
471
  if res.code != 200
383
- if res.body.[]("error")
384
- puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
472
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
473
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
385
474
  else
386
- puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
475
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
387
476
  end
388
477
  exit(1)
389
478
  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.10
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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abbrev