Skip to content

Commit 414fa50

Browse files
committed
CLI: Force thor to exit with a correct exit status
Long-time issues on Thor related to exit status code cause msync to return a inappropriate exit code. As example: rails/thor#244
1 parent dc88b18 commit 414fa50

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

features/cli.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ Feature: CLI
44
Scenario: When passing no arguments to the msync command
55
When I run `msync`
66
And the output should match /Commands:/
7+
Then the exit status should be 1
78

89
Scenario: When passing invalid arguments to the msync update command
910
When I run `msync update`
1011
And the output should match /No value provided for required option/
12+
Then the exit status should be 1
1113

1214
Scenario: When passing invalid arguments to the msync hook command
1315
When I run `msync hook`
1416
And the output should match /Commands:/
17+
Then the exit status should be 1
1518

16-
Scenario: When running the help subcommand
19+
Scenario: When running the help command
1720
When I run `msync help`
1821
And the output should match /Commands:/
22+
Then the exit status should be 0
1923

2024
Scenario: When overriding a setting from the config file on the command line
2125
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"

lib/modulesync/cli.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
require 'thor'
2+
23
require 'modulesync'
4+
require 'modulesync/cli/thor'
35
require 'modulesync/constants'
46
require 'modulesync/util'
57

68
module ModuleSync
7-
class CLI
9+
module CLI
810
def self.defaults
911
@defaults ||= Util.symbolize_keys(Util.parse_config(Constants::MODULESYNC_CONF_FILE))
1012
end

lib/modulesync/cli/thor.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'thor'
2+
require 'modulesync/cli'
3+
4+
module ModuleSync
5+
module CLI
6+
class Thor < ::Thor
7+
desc '_invalid_command_call', 'Invalid command', hide: true
8+
def _invalid_command_call
9+
self.class.new.help
10+
exit 1
11+
end
12+
default_task :_invalid_command_call
13+
14+
def self.exit_on_failure?
15+
true
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)