uffizzi-cli 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac2d58dae4db13ed788532732a92f9d4a317780cb4b80ef07d185f899d10749d
4
- data.tar.gz: a1b4b37db41936eabb930febe701186027a80d0684ca371ed442168caecea779
3
+ metadata.gz: 88f0a01cdfea0ed8e8d4ad54d776f517f84d74c424f2db15569fb788e7fe3868
4
+ data.tar.gz: e690fe7b2552ae4215687aac32420cb4b39e3cd2dd4b1d4fcf723538e49b213c
5
5
  SHA512:
6
- metadata.gz: c2420a93b4b17a5efb2de11ed5a998070da7eb2f8f22a2d09bf2598b4eb88841f428f0a87cf7de7c5b49e289f12f2d85413aa96600ca3726b71b5ec962e6b68c
7
- data.tar.gz: 2dff8bd8e614d8ffaad6a2b42f528844c5a6d1232c2327bcb756c8ae6d4b014e3b310965f01fd86dc2d6eb40cb9aaab10755ef707a0dc808538620581b1f09cb
6
+ metadata.gz: 77198a935bf13d106bd191e017094ecc431cc09e307608a4f23ccd3bbd5591b7d12def5f4c3eff77f0389acfe6384f2a80ad63389d7ce8b7f51b9768d8bd0d09
7
+ data.tar.gz: c945bf73973d7a55fae9e3cf9502a1cfacafc65671b292913333c61f644fe0ca9c5402e7ae7ce54ae88bd08de117e016614d72e9474634ff725581828ea288bb
@@ -15,7 +15,7 @@ module Uffizzi
15
15
 
16
16
  desc 'list', 'List all previews'
17
17
  method_option :filter, required: false, type: :string, aliases: '-f'
18
- method_option :output, required: false, type: :string, aliases: '-o', enum: ['json']
18
+ method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'pretty-json']
19
19
  def list
20
20
  run('list')
21
21
  end
@@ -87,6 +87,7 @@ module Uffizzi
87
87
 
88
88
  def handle_create_command(file_path, project_slug, labels)
89
89
  Uffizzi.ui.disable_stdout unless options[:output].nil?
90
+
90
91
  params = prepare_params(file_path, labels)
91
92
 
92
93
  response = create_deployment(ConfigFile.read_option(:server), project_slug, params)
@@ -145,7 +146,8 @@ module Uffizzi
145
146
  end
146
147
 
147
148
  def handle_succeed_events_response(response)
148
- Uffizzi.ui.pretty_say(response[:body][:events])
149
+ Uffizzi.ui.output_format = Uffizzi::UI::Shell::PRETTY_JSON
150
+ Uffizzi.ui.say(response[:body][:events])
149
151
  end
150
152
 
151
153
  def handle_delete_command(deployment_name, project_slug)
@@ -180,13 +182,12 @@ module Uffizzi
180
182
  deployments = response[:body][:deployments] || []
181
183
  raise Uffizzi::Error.new('The project has no active deployments') if deployments.empty?
182
184
 
183
- deployments.each do |deployment|
184
- if Uffizzi.ui.output_format.nil?
185
- Uffizzi.ui.say("deployment-#{deployment[:id]}")
186
- else
187
- Uffizzi.ui.pretty_say(deployment)
188
- end
185
+ if Uffizzi.ui.output_format.nil?
186
+ deployments = deployments.reduce('') do |acc, deployment|
187
+ "#{acc}deployment-#{deployment[:id]}\n"
188
+ end.strip
189
189
  end
190
+ Uffizzi.ui.say(deployments)
190
191
  end
191
192
 
192
193
  def handle_succeed_delete_response(deployment_id)
@@ -202,9 +203,8 @@ module Uffizzi
202
203
 
203
204
  container
204
205
  end
205
- deployment.each_key do |key|
206
- Uffizzi.ui.say("#{key}: #{deployment[key]}")
207
- end
206
+ deployment_data = deployment.reduce('') { |acc, (key, value)| "#{acc}#{key}: #{value}\n" }.strip
207
+ Uffizzi.ui.say(deployment_data)
208
208
  end
209
209
 
210
210
  def hide_secrets(secret_variables)
@@ -240,7 +240,8 @@ module Uffizzi
240
240
  Uffizzi.ui.say(preview_url) if success
241
241
  else
242
242
  deployment_data = build_deployment_data(deployment)
243
- Uffizzi.ui.output(deployment_data)
243
+ Uffizzi.ui.enable_stdout
244
+ Uffizzi.ui.say(deployment_data)
244
245
  end
245
246
  end
246
247
 
data/lib/uffizzi/shell.rb CHANGED
@@ -7,12 +7,26 @@ module Uffizzi
7
7
  class Shell
8
8
  attr_accessor :output_format
9
9
 
10
+ PRETTY_JSON = 'pretty-json'
11
+ REGULAR_JSON = 'json'
12
+ GITHUB_ACTION = 'github-action'
13
+
10
14
  def initialize
11
15
  @shell = Thor::Shell::Basic.new
12
16
  end
13
17
 
14
18
  def say(message)
15
- @shell.say(message)
19
+ formatted_message = case output_format
20
+ when PRETTY_JSON
21
+ format_to_pretty_json(message)
22
+ when REGULAR_JSON
23
+ format_to_json(message)
24
+ when GITHUB_ACTION
25
+ format_to_github_action(message)
26
+ else
27
+ message
28
+ end
29
+ @shell.say(formatted_message)
16
30
  end
17
31
 
18
32
  def print_in_columns(messages)
@@ -34,33 +48,28 @@ module Uffizzi
34
48
  @shell.send(:stdout).string.strip
35
49
  end
36
50
 
37
- def pretty_say(collection, index = true)
38
- ap(collection, { index: index })
39
- end
40
-
41
51
  def disable_stdout
42
52
  $stdout = StringIO.new
43
53
  end
44
54
 
45
- def output(data)
55
+ def enable_stdout
46
56
  $stdout = IO.new(1, 'w')
47
- json_format? ? output_in_json(data) : output_in_github_format(data)
48
57
  end
49
58
 
50
59
  private
51
60
 
52
- def json_format?
53
- output_format == 'json'
61
+ def format_to_json(data)
62
+ data.to_json
54
63
  end
55
64
 
56
- def output_in_json(data)
57
- say(data.to_json)
65
+ def format_to_pretty_json(data)
66
+ JSON.pretty_generate(data)
58
67
  end
59
68
 
60
- def output_in_github_format(data)
61
- data.each_key do |key|
62
- say("::set-output name=#{key}::#{data[key]}")
63
- end
69
+ def format_to_github_action(data)
70
+ return '' unless data.is_a?(Hash)
71
+
72
+ data.reduce('') { |acc, (key, value)| "#{acc}::set-output name=#{key}::#{value}\n" }
64
73
  end
65
74
  end
66
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uffizzi
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  .\" generated with Ronn-NG/v0.9.1
2
2
  .\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3
- .TH "UFFIZZI\-PREVIEW\-LIST" "" "August 2022" ""
3
+ .TH "UFFIZZI\-PREVIEW\-LIST" "" "September 2022" ""
4
4
  .SH "NAME"
5
5
  \fBuffizzi\-preview\-list\fR \- list previews in a project
6
6
  .SH "SYNOPSIS"
@@ -20,7 +20,7 @@ https://github\.com/UffizziCloud/uffizzi_cli
20
20
  \-\-filter=METADATA
21
21
  Metadata to filtering list of deployments\.
22
22
 
23
- \-\-output=json
23
+ \-\-output=pretty\-json
24
24
  Use this option for a more detailed description of listed
25
25
  deployments\.
26
26
  .fi
@@ -41,7 +41,7 @@ To list all previews in a project with name my_project, run:
41
41
 
42
42
  To list all previews in json format, run:
43
43
 
44
- $ uffizzi preview list \-\-output="json"
44
+ $ uffizzi preview list \-\-output="pretty\-json"
45
45
 
46
46
  To list all previews filtered by metadata using single
47
47
  label, run:
@@ -15,7 +15,7 @@ uffizzi-preview-list - list previews in a project
15
15
  --filter=METADATA
16
16
  Metadata to filtering list of deployments.
17
17
 
18
- --output=json
18
+ --output=pretty-json
19
19
  Use this option for a more detailed description of listed
20
20
  deployments.
21
21
 
@@ -34,7 +34,7 @@ uffizzi-preview-list - list previews in a project
34
34
 
35
35
  To list all previews in json format, run:
36
36
 
37
- $ uffizzi preview list --output="json"
37
+ $ uffizzi preview list --output="pretty-json"
38
38
 
39
39
  To list all previews filtered by metadata using single
40
40
  label, run:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-31 00:00:00.000000000 Z
12
+ date: 2022-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print