Skip to content

Commit ffccf69

Browse files
author
Alex Evanczuk
authored
Make sure all thor CLI commands have the right exit code (#98)
* bundle update * Make sure all commands exit with proper error codes * bump version * rubocop
1 parent 03c812b commit ffccf69

14 files changed

Lines changed: 224 additions & 174 deletions

File tree

Gemfile.lock

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
GIT
22
remote: https://github.com/Shopify/packwerk.git
3-
revision: 95caea012661e69e9f5d268044f8277c77de2743
3+
revision: e850241a4572a984bc9def8307faef7271c6890b
44
branch: main
55
specs:
6-
packwerk (3.0.1)
6+
packwerk (3.1.0)
77
activesupport (>= 6.0)
88
ast
99
better_html
@@ -17,7 +17,7 @@ GIT
1717
PATH
1818
remote: .
1919
specs:
20-
packs (0.0.23)
20+
packs (0.0.24)
2121
code_ownership (>= 1.33.0)
2222
colorize
2323
packs-specification
@@ -32,19 +32,20 @@ PATH
3232
GEM
3333
remote: https://rubygems.org/
3434
specs:
35-
actionview (7.0.4.3)
36-
activesupport (= 7.0.4.3)
35+
actionview (7.0.7)
36+
activesupport (= 7.0.7)
3737
builder (~> 3.1)
3838
erubi (~> 1.4)
3939
rails-dom-testing (~> 2.0)
4040
rails-html-sanitizer (~> 1.1, >= 1.2.0)
41-
activesupport (7.0.4.3)
41+
activesupport (7.0.7)
4242
concurrent-ruby (~> 1.0, >= 1.0.2)
4343
i18n (>= 1.6, < 2)
4444
minitest (>= 5.1)
4545
tzinfo (~> 2.0)
4646
ast (2.4.2)
47-
better_html (2.0.1)
47+
base64 (0.1.1)
48+
better_html (2.0.2)
4849
actionview (>= 6.0)
4950
activesupport (>= 6.0)
5051
ast (~> 2.0)
@@ -66,26 +67,28 @@ GEM
6667
crass (1.0.6)
6768
diff-lcs (1.5.0)
6869
erubi (1.12.0)
69-
i18n (1.13.0)
70+
i18n (1.14.1)
7071
concurrent-ruby (~> 1.0)
7172
json (2.6.3)
73+
language_server-protocol (3.17.0.3)
7274
loofah (2.21.3)
7375
crass (~> 1.0.2)
7476
nokogiri (>= 1.12.0)
7577
method_source (1.0.0)
76-
mini_portile2 (2.8.2)
77-
minitest (5.18.0)
78+
mini_portile2 (2.8.4)
79+
minitest (5.19.0)
7880
netrc (0.11.0)
79-
nokogiri (1.15.0)
81+
nokogiri (1.15.3)
8082
mini_portile2 (~> 2.8.2)
8183
racc (~> 1.4)
8284
packs-specification (0.0.9)
8385
sorbet-runtime
8486
parallel (1.23.0)
8587
parse_packwerk (0.19.3)
8688
sorbet-runtime
87-
parser (3.2.2.1)
89+
parser (3.2.2.3)
8890
ast (~> 2.4.1)
91+
racc
8992
pastel (0.8.0)
9093
tty-color (~> 0.5)
9194
pry (0.14.2)
@@ -94,21 +97,23 @@ GEM
9497
pry-byebug (3.10.1)
9598
byebug (~> 11.0)
9699
pry (>= 0.13, < 0.15)
97-
racc (1.6.2)
98-
rails-dom-testing (2.0.3)
99-
activesupport (>= 4.2.0)
100+
racc (1.7.1)
101+
rails-dom-testing (2.2.0)
102+
activesupport (>= 5.0.0)
103+
minitest
100104
nokogiri (>= 1.6)
101-
rails-html-sanitizer (1.5.0)
102-
loofah (~> 2.19, >= 2.19.1)
105+
rails-html-sanitizer (1.6.0)
106+
loofah (~> 2.21)
107+
nokogiri (~> 1.14)
103108
rainbow (3.1.1)
104109
rake (13.0.6)
105-
rbi (0.0.16)
110+
rbi (0.0.17)
106111
ast
107-
parser (>= 2.6.4.0)
112+
parser (>= 3.0.0)
108113
sorbet-runtime (>= 0.5.9204)
109-
unparser
110-
regexp_parser (2.8.0)
111-
rexml (3.2.5)
114+
unparser (>= 0.5.6)
115+
regexp_parser (2.8.1)
116+
rexml (3.2.6)
112117
rspec (3.12.0)
113118
rspec-core (~> 3.12.0)
114119
rspec-expectations (~> 3.12.0)
@@ -118,25 +123,27 @@ GEM
118123
rspec-expectations (3.12.3)
119124
diff-lcs (>= 1.2.0, < 2.0)
120125
rspec-support (~> 3.12.0)
121-
rspec-mocks (3.12.5)
126+
rspec-mocks (3.12.6)
122127
diff-lcs (>= 1.2.0, < 2.0)
123128
rspec-support (~> 3.12.0)
124-
rspec-support (3.12.0)
125-
rubocop (1.51.0)
129+
rspec-support (3.12.1)
130+
rubocop (1.56.0)
131+
base64 (~> 0.1.1)
126132
json (~> 2.3)
133+
language_server-protocol (>= 3.17.0)
127134
parallel (~> 1.10)
128-
parser (>= 3.2.0.0)
135+
parser (>= 3.2.2.3)
129136
rainbow (>= 2.2.2, < 4.0)
130137
regexp_parser (>= 1.8, < 3.0)
131138
rexml (>= 3.2.5, < 4.0)
132-
rubocop-ast (>= 1.28.0, < 2.0)
139+
rubocop-ast (>= 1.28.1, < 2.0)
133140
ruby-progressbar (~> 1.7)
134141
unicode-display_width (>= 2.4.0, < 3.0)
135-
rubocop-ast (1.28.1)
142+
rubocop-ast (1.29.0)
136143
parser (>= 3.2.1.0)
137144
rubocop-capybara (2.18.0)
138145
rubocop (~> 1.41)
139-
rubocop-factory_bot (2.23.0)
146+
rubocop-factory_bot (2.23.1)
140147
rubocop (~> 1.33)
141148
rubocop-packs (0.0.42)
142149
activesupport
@@ -145,7 +152,7 @@ GEM
145152
rubocop
146153
rubocop-sorbet
147154
sorbet-runtime
148-
rubocop-rspec (2.22.0)
155+
rubocop-rspec (2.23.2)
149156
rubocop (~> 1.33)
150157
rubocop-capybara (~> 2.17)
151158
rubocop-factory_bot (~> 2.22)
@@ -155,27 +162,27 @@ GEM
155162
rexml
156163
ruby-progressbar (1.13.0)
157164
smart_properties (1.17.0)
158-
sorbet (0.5.10826)
159-
sorbet-static (= 0.5.10826)
160-
sorbet-runtime (0.5.10826)
161-
sorbet-static (0.5.10826-universal-darwin-14)
162-
sorbet-static (0.5.10826-universal-darwin-15)
163-
sorbet-static (0.5.10826-universal-darwin-16)
164-
sorbet-static (0.5.10826-universal-darwin-17)
165-
sorbet-static (0.5.10826-universal-darwin-18)
166-
sorbet-static (0.5.10826-universal-darwin-19)
167-
sorbet-static (0.5.10826-universal-darwin-20)
168-
sorbet-static (0.5.10826-universal-darwin-21)
169-
sorbet-static (0.5.10826-universal-darwin-22)
170-
sorbet-static (0.5.10826-x86_64-linux)
171-
sorbet-static-and-runtime (0.5.10826)
172-
sorbet (= 0.5.10826)
173-
sorbet-runtime (= 0.5.10826)
165+
sorbet (0.5.10957)
166+
sorbet-static (= 0.5.10957)
167+
sorbet-runtime (0.5.10957)
168+
sorbet-static (0.5.10957-universal-darwin-14)
169+
sorbet-static (0.5.10957-universal-darwin-15)
170+
sorbet-static (0.5.10957-universal-darwin-16)
171+
sorbet-static (0.5.10957-universal-darwin-17)
172+
sorbet-static (0.5.10957-universal-darwin-18)
173+
sorbet-static (0.5.10957-universal-darwin-19)
174+
sorbet-static (0.5.10957-universal-darwin-20)
175+
sorbet-static (0.5.10957-universal-darwin-21)
176+
sorbet-static (0.5.10957-universal-darwin-22)
177+
sorbet-static (0.5.10957-x86_64-linux)
178+
sorbet-static-and-runtime (0.5.10957)
179+
sorbet (= 0.5.10957)
180+
sorbet-runtime (= 0.5.10957)
174181
spoom (1.2.1)
175182
sorbet (>= 0.5.10187)
176183
sorbet-runtime (>= 0.5.9204)
177184
thor (>= 0.19.2)
178-
tapioca (0.11.6)
185+
tapioca (0.11.8)
179186
bundler (>= 2.2.25)
180187
netrc (>= 0.11.0)
181188
parallel (>= 1.21.0)
@@ -198,7 +205,7 @@ GEM
198205
tzinfo (2.0.6)
199206
concurrent-ruby (~> 1.0)
200207
unicode-display_width (2.4.2)
201-
unparser (0.6.7)
208+
unparser (0.6.8)
202209
diff-lcs (~> 1.3)
203210
parser (>= 3.2.0)
204211
visualize_packs (0.3.1)
@@ -213,7 +220,7 @@ GEM
213220
yard-sorbet (0.8.1)
214221
sorbet-runtime (>= 0.5)
215222
yard (>= 0.9)
216-
zeitwerk (2.6.8)
223+
zeitwerk (2.6.11)
217224

218225
PLATFORMS
219226
ruby
@@ -230,6 +237,7 @@ DEPENDENCIES
230237
rubocop-rspec
231238
sorbet
232239
sorbet-static
240+
spoom (= 1.2.1)
233241
tapioca
234242

235243
BUNDLED WITH

lib/.DS_Store

6 KB
Binary file not shown.

lib/packs.rb

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ def self.start_interactive_mode!
3636
Private::InteractiveCli.start!
3737
end
3838

39+
sig { returns(T::Boolean) }
40+
def self.update
41+
Private.system_with('bin/packwerk update-todo')
42+
end
43+
44+
sig { returns(T::Boolean) }
45+
def self.validate
46+
Private.system_with('bin/packwerk validate')
47+
end
48+
49+
sig { params(files: T::Array[String]).returns(T::Boolean) }
50+
def self.check(files)
51+
Private.system_with("bin/packwerk check #{files.join(' ')}")
52+
end
53+
3954
sig do
4055
params(
4156
pack_name: String,
@@ -222,32 +237,6 @@ def self.bust_cache!
222237
Specification.bust_cache!
223238
end
224239

225-
#
226-
# execute_command is like `run` except it does not `exit`
227-
#
228-
sig { params(argv: T.untyped, formatter: T.nilable(Packwerk::OffensesFormatter)).void }
229-
def self.execute(argv, formatter = nil)
230-
Private::PackwerkWrapper.with_safe_exit_if_no_files_found do
231-
Private::PackwerkWrapper.packwerk_cli(formatter).execute_command(argv)
232-
end
233-
end
234-
235-
sig { params(files: T::Array[String]).returns(T::Array[Packwerk::ReferenceOffense]) }
236-
def self.get_offenses_for_files(files)
237-
formatter = Private::PackwerkWrapper::OffensesAggregatorFormatter.new
238-
Private::PackwerkWrapper.packwerk_cli_execute_safely(['check', *files], formatter)
239-
formatter.aggregated_offenses.compact
240-
end
241-
242-
sig { params(files: T::Array[String]).returns(T::Array[Packwerk::ReferenceOffense]) }
243-
def self.get_offenses_for_files_by_package(files)
244-
packages = Private::PackwerkWrapper.package_names_for_files(files)
245-
argv = ['check', '--packages', packages.join(',')]
246-
formatter = Private::PackwerkWrapper::OffensesAggregatorFormatter.new
247-
Private::PackwerkWrapper.packwerk_cli_execute_safely(argv, formatter)
248-
formatter.aggregated_offenses.compact
249-
end
250-
251240
sig { void }
252241
def self.lint_package_todo_yml_files!
253242
Private.lint_package_todo_yml_files!

lib/packs/cli.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CLI < Thor
1010
sig { params(pack_name: String).void }
1111
def create(pack_name)
1212
Packs.create_pack!(pack_name: pack_name)
13+
exit_successfully
1314
end
1415

1516
desc 'add_dependency packs/from_pack packs/to_pack', 'Add packs/to_pack to packs/from_pack/package.yml list of dependencies'
@@ -27,6 +28,7 @@ def add_dependency(from_pack, to_pack)
2728
pack_name: from_pack,
2829
dependency_name: to_pack
2930
)
31+
exit_successfully
3032
end
3133

3234
desc 'list_top_dependency_violations packs/your_pack', 'List the top dependency violations of packs/your_pack'
@@ -44,6 +46,7 @@ def list_top_dependency_violations(pack_name)
4446
pack_name: pack_name,
4547
limit: options[:limit]
4648
)
49+
exit_successfully
4750
end
4851

4952
desc 'list_top_privacy_violations packs/your_pack', 'List the top privacy violations of packs/your_pack'
@@ -61,6 +64,7 @@ def list_top_privacy_violations(pack_name)
6164
pack_name: pack_name,
6265
limit: options[:limit]
6366
)
67+
exit_successfully
6468
end
6569

6670
desc 'make_public path/to/file.rb path/to/directory', 'Make files or directories public API'
@@ -75,6 +79,7 @@ def make_public(*paths)
7579
paths_relative_to_root: paths,
7680
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
7781
)
82+
exit_successfully
7883
end
7984

8085
desc 'move packs/destination_pack path/to/file.rb path/to/directory', 'Move files or directories from one pack to another'
@@ -91,6 +96,7 @@ def move(pack_name, *paths)
9196
paths_relative_to_root: paths,
9297
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
9398
)
99+
exit_successfully
94100
end
95101

96102
desc 'lint_package_todo_yml_files', 'Lint `package_todo.yml` files to check for formatting issues'
@@ -108,37 +114,40 @@ def lint_package_yml_files(*pack_names)
108114
desc 'validate', 'Run bin/packwerk validate (detects cycles)'
109115
sig { void }
110116
def validate
111-
system('bin/packwerk validate')
117+
Private.exit_with(Packs.validate)
112118
end
113119

114120
desc 'check [ packs/my_pack ]', 'Run bin/packwerk check'
115121
sig { params(paths: String).void }
116122
def check(*paths)
117-
Packs.execute(['check', *paths])
123+
Private.exit_with(Packs.check(paths))
118124
end
119125

120126
desc 'update', 'Run bin/packwerk update-todo'
121127
sig { void }
122128
def update
123-
system('bin/packwerk update-todo')
129+
Private.exit_with(Packs.update)
124130
end
125131

126132
desc 'get_info [ packs/my_pack packs/my_other_pack ]', 'Get info about size and violations for packs'
127133
sig { params(pack_names: String).void }
128134
def get_info(*pack_names)
129135
Private.get_info(packs: parse_pack_names(pack_names))
136+
exit_successfully
130137
end
131138

132139
desc 'visualize [ packs/my_pack packs/my_other_pack ]', 'Visualize packs'
133140
sig { params(pack_names: String).void }
134141
def visualize(*pack_names)
135142
Private.visualize(packs: parse_pack_names(pack_names))
143+
exit_successfully
136144
end
137145

138146
desc 'rename', 'Rename a pack'
139147
sig { void }
140148
def rename
141149
puts Private.rename_pack
150+
exit_successfully
142151
end
143152

144153
desc 'move_to_parent packs/child_pack packs/parent_pack ', 'Set packs/child_pack as a child of packs/parent_pack'
@@ -149,6 +158,7 @@ def move_to_parent(child_pack_name, parent_pack_name)
149158
pack_name: child_pack_name,
150159
per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
151160
)
161+
exit_successfully
152162
end
153163

154164
private
@@ -159,6 +169,11 @@ def move_to_parent(child_pack_name, parent_pack_name)
159169
def parse_pack_names(pack_names)
160170
pack_names.empty? ? Packs.all : pack_names.map { |p| Packs.find(p.gsub(%r{/$}, '')) }.compact
161171
end
172+
173+
sig { void }
174+
def exit_successfully
175+
Private.exit_with(true)
176+
end
162177
end
163178
end
164179
end

0 commit comments

Comments
 (0)