bld 0.1.2 → 0.1.4

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 +2 -1
  3. data/bin/build +2 -1
  4. data/lib/commands.rb +119 -76
  5. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45419a892bc44df93ecc3719e4b1faf01623943450e3b3e6f5b52749b95987b6
4
- data.tar.gz: 7a2df108023c2b45008a0c2f378c11e497bef10ecc409a457656ea4b14f2f7ae
3
+ metadata.gz: e58ad6d7f83190c1e03e61c08d300cf30d34ca0a565935c902739712968999b4
4
+ data.tar.gz: e9836c61883993fac85828620cf0129ea2b6fe5e3b2939742189bdd833389c88
5
5
  SHA512:
6
- metadata.gz: c71f9a0e03655f2451d3c7e6ecf722806bcba0926a918b1f219214c776ffd302fd265981739fe5c86088ad3abe7737dcc75cc7188497e1abca97b809b8224e95
7
- data.tar.gz: 57e0526a93cb3758f8b7ad1f2d29ab4f8bb9c8648f5d3798f41147c20ca62ae422ace18b0b244e3033899a383cc80c1ee4f59aa9ef60e218168f98a1ca80c4ee
6
+ metadata.gz: 2d103b0fad23903d458d79a6b6b6d5a23ab72ea117ef248511bb7e733d4b9622f91fd11c77b845ec4096ee5024b87f63e45d393ea58762165b6e3976aeb614c7
7
+ data.tar.gz: 9f6a7f68f081c9e66667cf3cb345727e528df706040d6006cdd6e5fc2bffa2dab7bb7bda05e4611d4659fb0780ccfb696e1830770b18b027401d691df011c72a
data/bin/bld CHANGED
@@ -19,9 +19,10 @@ class BuildCLI
19
19
 
20
20
  def run
21
21
  program :name, 'Build CLI'
22
- program :version, '1.0.0'
22
+ program :version, '0.1.4'
23
23
  program :description, "Build's Command Line Interface"
24
24
  program :int_block, -> { exit }
25
+ default_command :help
25
26
 
26
27
  BuildCLICommands.index.each do |name, entry|
27
28
  command name.to_sym do |c|
data/bin/build CHANGED
@@ -19,9 +19,10 @@ class BuildCLI
19
19
 
20
20
  def run
21
21
  program :name, 'Build CLI'
22
- program :version, '1.0.0'
22
+ program :version, '0.1.4'
23
23
  program :description, "Build's Command Line Interface"
24
24
  program :int_block, -> { exit }
25
+ default_command :help
25
26
 
26
27
  BuildCLICommands.index.each do |name, entry|
27
28
  command name.to_sym do |c|
data/lib/commands.rb CHANGED
@@ -8,73 +8,76 @@ class BuildCLICommands
8
8
  cli_perform: Proc.new { |args, options|
9
9
  begin
10
10
  user_netrc = Netrc.read
11
- user_token = user_netrc["build.io"][1]
11
+ user_token = user_netrc.[]("build.io").[](1)
12
12
  auth = "Bearer #{user_token}"
13
-
14
13
  app_name = options.app
15
14
  if app_name.nil?
16
- puts CLI::UI.fmt "{{red:›}} Error: no app name specified"
17
- exit 1
15
+ puts(CLI::UI.fmt("{{red:›}} Error: no app name specified"))
16
+ exit(1)
18
17
  end
19
-
20
18
  query_params = {}
21
- query_params[:app] = app_name
22
- query_params[:team] = options.team if options.team
23
- query_params[:region] = options.region if options.region
24
- query_params[:stack] = options.stack if options.stack
25
-
19
+ query_params.[]=(:app, app_name)
20
+ if options.team
21
+ query_params.[]=(:team, options.team)
22
+ end
23
+ if options.region
24
+ query_params.[]=(:region, options.region)
25
+ end
26
+ if options.stack
27
+ query_params.[]=(:stack, options.stack)
28
+ end
26
29
  query_string = URI.encode_www_form(query_params)
27
-
28
30
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/apps/create?#{query_string}",
29
- headers: { "Authorization" => auth })
31
+ { headers: { "Authorization" => auth } })
30
32
  if res.code != 200
31
- puts CLI::UI.fmt "{{red:›}} Error: not authorized to create app (#{app_name})"
32
- exit 1
33
+ puts(CLI::UI.fmt("{{red:›}} Error: not authorized to create app (#{app_name})"))
34
+ exit(1)
33
35
  end
34
- app_name = JSON.parse(res.body)["name"]
35
- puts "https://#{app_name}.#{region}.antimony.io | #{app_name}"
36
+ app_name = JSON.parse(res.body).[]("name")
37
+ puts("https://#{app_name}.#{region}.antimony.io | #{app_name}")
36
38
  rescue
37
- puts CLI::UI.fmt "{{red:›}} Error: not logged in"
38
- exit 1
39
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
40
+ exit(1)
39
41
  end
40
42
  },
41
43
  },
42
44
  "login": {
43
45
  cli_details: { :syntax => "build login", :description => "Login to your Build account", :options => [] },
44
46
  cli_perform: Proc.new { |args, options|
45
- input = CLI::UI.any_key('Press any key to open up the browser to login or q to exit')
46
- exit if input.downcase == "q"
47
-
48
- user_token, user_email = nil
49
- CLI::UI::Spinner.spin("Waiting for login") do |spinner|
47
+ input = CLI::UI.any_key("Press any key to open up the browser to login or q to exit")
48
+ if input.downcase == "q"
49
+ exit
50
+ end
51
+ (user_token, user_email) = nil
52
+ CLI::UI::Spinner.spin("Waiting for login") { |spinner,|
50
53
  client_secret = SecureRandom.uuid
51
-
52
54
  oauth_url = "#{ANTIMONY_HOST}/cli_auth/authorize/#{client_secret}"
53
55
  Launchy.open(oauth_url)
54
-
55
56
  poll_interval = 1
56
57
  timeout = (5 * 60)
57
58
  start_time = Time.now
58
- loop do
59
+ loop {
59
60
  response = HTTParty.get("#{ANTIMONY_HOST}/api/cli_auth/resolve/#{client_secret}")
60
- if response.code == 200 && response['code'] == 'unresolved'
61
+ if response.code == 200 && response.[]("code") == "unresolved"
61
62
  sleep(poll_interval)
62
- elsif response.code == 200 && response['code'] == 'resolved'
63
- user_token = response["token"]
64
- user_email = response["email"]
65
- break
66
63
  else
67
- raise "Error: #{response.code}"
64
+ if response.code == 200 && response.[]("code") == "resolved"
65
+ user_token = response.[]("token")
66
+ user_email = response.[]("email")
67
+ break
68
+ else
69
+ raise("Error: #{response.code}")
70
+ end
68
71
  end
69
- break if Time.now - start_time > timeout
70
- end
71
-
72
+ if Time.now - start_time > timeout
73
+ break
74
+ end
75
+ }
72
76
  user_netrc = Netrc.read
73
- user_netrc["build.io"] = "#{user_email}", "#{user_token}"
77
+ user_netrc.[]=("build.io", ["#{user_email}", "#{user_token}"])
74
78
  user_netrc.save
75
- end
76
-
77
- puts CLI::UI.fmt "Logged in as {{green:#{user_email}}}"
79
+ }
80
+ puts(CLI::UI.fmt("Logged in as {{green:#{user_email}}}"))
78
81
  },
79
82
  },
80
83
  "logs": {
@@ -83,48 +86,56 @@ class BuildCLICommands
83
86
  cli_perform: Proc.new { |args, options|
84
87
  app_name = options.app
85
88
  if app_name.nil? || app_name.strip == ""
86
- puts CLI::UI.fmt "{{red:›}} Error: The following error occurred:"
87
- puts CLI::UI.fmt "{{red:›}} {{gray:Missing required flag app}}"
88
- puts CLI::UI.fmt "{{red:›}} See more help with --help"
89
- exit 1
89
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
90
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
91
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
92
+ exit(1)
90
93
  end
91
94
 
92
95
  begin
93
96
  user_netrc = Netrc.read
94
- user_token = user_netrc["build.io"][1]
97
+ user_token = user_netrc.[]("build.io").[](1)
95
98
  auth = "Bearer #{user_token}"
96
99
  rescue
97
- puts CLI::UI.fmt "{{red:›}} Error: not logged in"
98
- exit 1
100
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
101
+ exit(1)
99
102
  end
100
-
101
103
  query_params = {}
102
- query_params[:num] = options.num if options.num
103
- query_params[:process] = options.process if options.process
104
- query_params[:source] = options.source if options.source
105
- query_params[:tail] = options.trace if options.trace
106
- query_params[:tail] = options.tail if options.tail
107
-
104
+ if options.num
105
+ query_params.[]=(:num, options.num)
106
+ end
107
+ if options.process
108
+ query_params.[]=(:process, options.process)
109
+ end
110
+ if options.source
111
+ query_params.[]=(:source, options.source)
112
+ end
113
+ if options.trace
114
+ query_params.[]=(:tail, options.trace)
115
+ end
116
+ if options.tail
117
+ query_params.[]=(:tail, options.tail)
118
+ end
108
119
  query_string = URI.encode_www_form(query_params)
109
-
110
120
  res = HTTParty.get("#{ANTIMONY_HOST}/api/apps/#{app_name}/logs/log_url?#{query_string}",
111
- headers: { "Authorization" => auth })
121
+ { headers: { "Authorization" => auth } })
112
122
  if res.code != 200
113
- puts CLI::UI.fmt "{{red:›}} Error: Couldn't find that app."
114
- puts CLI::UI.fmt "{{red:›}}"
115
- puts CLI::UI.fmt "{{red:›}} Error ID: not_found"
116
- exit 1
117
- end
118
- log_url = res["url"]
119
-
120
- res = HTTParty.get(log_url, timeout: 1_000_000) do |fragment|
121
- puts fragment unless fragment.empty?
123
+ puts(CLI::UI.fmt("{{red:›}} Error: Couldn't find that app."))
124
+ puts(CLI::UI.fmt("{{red:›}}"))
125
+ puts(CLI::UI.fmt("{{red:›}} Error ID: not_found"))
126
+ exit(1)
122
127
  end
128
+ log_url = res.[]("url")
129
+ res = HTTParty.get(log_url, { timeout: 1000000 }) { |fragment,|
130
+ unless fragment.empty?
131
+ puts(fragment)
132
+ end
133
+ }
123
134
  if res.code != 200
124
- puts CLI::UI.fmt "{{red:›}} Error: Connection to logs failed."
125
- puts CLI::UI.fmt "{{red:›}}"
126
- puts CLI::UI.fmt "{{red:›}} Error ID: connection_failed"
127
- exit 1
135
+ puts(CLI::UI.fmt("{{red:›}} Error: Connection to logs failed."))
136
+ puts(CLI::UI.fmt("{{red:›}}"))
137
+ puts(CLI::UI.fmt("{{red:›}} Error ID: connection_failed"))
138
+ exit(1)
128
139
  end
129
140
  },
130
141
  },
@@ -134,19 +145,51 @@ class BuildCLICommands
134
145
  cli_perform: Proc.new { |args, options|
135
146
  begin
136
147
  user_netrc = Netrc.read
137
- user_token = user_netrc["build.io"][1]
148
+ user_token = user_netrc.[]("build.io").[](1)
138
149
  auth = "Bearer #{user_token}"
139
-
140
150
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/whoami",
141
- headers: { "Authorization" => auth })
151
+ { headers: { "Authorization" => auth } })
152
+ if res.code != 200
153
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
154
+ exit(1)
155
+ end
156
+ puts(JSON.parse(res.body).[]("email"))
157
+ rescue
158
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
159
+ exit(1)
160
+ end
161
+ },
162
+ },
163
+ "run": {
164
+ cli_details: { :syntax => "build run COMMAND -a <app>", :description => "Run a once-off process in an app",
165
+ :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
166
+ cli_perform: Proc.new { |args, options|
167
+ begin
168
+ if args.empty?
169
+ puts(CLI::UI.fmt("{{red:›}} Error: no command provided"))
170
+ exit(1)
171
+ end
172
+ user_netrc = Netrc.read
173
+ user_token = user_netrc.[]("build.io").[](1)
174
+ auth = "Bearer #{user_token}"
175
+ query_params = {}
176
+ if options.app
177
+ query_params.[]=(:app, options.app)
178
+ end
179
+ query_string = URI.encode_www_form(query_params)
180
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
181
+ { headers: { "Authorization" => auth } })
142
182
  if res.code != 200
143
- puts CLI::UI.fmt "{{red:›}} Error: not logged in"
144
- exit 1
183
+ puts(CLI::UI.fmt("{{red:›}} Error: app not found"))
184
+ exit(1)
145
185
  end
146
- puts JSON.parse(res.body)["email"]
186
+ ruby = JSON.parse(res.body).[]("ruby")
187
+ require("shellwords")
188
+ command = "/cnb/lifecycle/launcher #{Shellwords.join(args)}"
189
+ eval(ruby)
147
190
  rescue
148
- puts CLI::UI.fmt "{{red:›}} Error: not logged in"
149
- exit 1
191
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
192
+ exit(1)
150
193
  end
151
194
  },
152
195
  }
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegl00
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-27 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -135,7 +135,18 @@ homepage: https://build.io
135
135
  licenses:
136
136
  - ''
137
137
  metadata: {}
138
- post_install_message:
138
+ post_install_message: |2+
139
+
140
+
141
+
142
+ ██████╗ ██╗ ██╗██╗██╗ ██████╗
143
+ ██╔══██╗██║ ██║██║██║ ██╔══██╗
144
+ ██████╔╝██║ ██║██║██║ ██║ ██║
145
+ ██╔══██╗██║ ██║██║██║ ██║ ██║
146
+ ██████╔╝╚██████╔╝██║███████╗██████╔╝
147
+ ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝
148
+ Use `build login` to get started.
149
+
139
150
  rdoc_options: []
140
151
  require_paths:
141
152
  - lib
@@ -155,3 +166,4 @@ signing_key:
155
166
  specification_version: 4
156
167
  summary: build cli
157
168
  test_files: []
169
+ ...