Skip to content

Commit 2f3f1fa

Browse files
author
Alex Evanczuk
authored
Improve CLI UX by more providing feedback when an unrecognized command is used (#8)
1 parent aa10870 commit 2f3f1fa

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
code_ownership (1.25.0)
4+
code_ownership (1.26.0)
55
bigrails-teams
66
parse_packwerk
77
sorbet-runtime

code_ownership.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "code_ownership"
3-
spec.version = '1.25.0'
3+
spec.version = '1.26.0'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66
spec.summary = 'A gem to help engineering teams declare ownership of code'

lib/code_ownership/cli.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ def self.run!(argv)
1111
validate!(argv)
1212
elsif command == 'for_file'
1313
for_file(argv)
14+
elsif [nil, "help"].include?(command)
15+
puts <<~USAGE
16+
Usage: bin/codeownership <subcommand>
17+
18+
Subcommands:
19+
validate - run all validations
20+
for_file - find code ownership for a single file
21+
help - display help information about code_ownership
22+
USAGE
23+
else
24+
puts "'#{command}' is not a code_ownership command. See `bin/codeownership help`."
1425
end
26+
1527
end
1628

1729
def self.validate!(argv)

spec/lib/code_ownership/cli_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,30 @@
103103
end
104104
end
105105
end
106+
107+
describe 'using unknown command' do
108+
let(:argv) { ['some_command'] }
109+
110+
it 'outputs help text' do
111+
expect(CodeOwnership::Cli).to receive(:puts).with("'some_command' is not a code_ownership command. See `bin/codeownership help`.")
112+
subject
113+
end
114+
end
115+
116+
describe 'passing in no command' do
117+
let(:argv) { [] }
118+
119+
it 'outputs help text' do
120+
expected = <<~EXPECTED
121+
Usage: bin/codeownership <subcommand>
122+
123+
Subcommands:
124+
validate - run all validations
125+
for_file - find code ownership for a single file
126+
help - display help information about code_ownership
127+
EXPECTED
128+
expect(CodeOwnership::Cli).to receive(:puts).with(expected)
129+
subject
130+
end
131+
end
106132
end

0 commit comments

Comments
 (0)