Skip to content

Commit aa8adc4

Browse files
authored
Merge pull request #501 from rundeck/fix/exit-code
RUN-1634: Fix exit codes on command failures
2 parents 196b5f1 + eb5fc9c commit aa8adc4

34 files changed

Lines changed: 1164 additions & 116 deletions

File tree

rd-cli-acl/src/main/java/org/rundeck/client/ext/acl/Acl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ static class TestOptions
477477
}
478478

479479
@CommandLine.Command(description = "Test ACL Policies")
480-
public boolean test(@CommandLine.Mixin TestOptions opts) {
480+
public int test(@CommandLine.Mixin TestOptions opts) {
481481
if (!applyArgValidate(opts)) {
482-
return false;
482+
return 2;
483483
}
484484
final RuleEvaluator authorization = createAuthorization(opts);
485485
AuthRequest authRequest = createAuthRequestFromArgs(opts);
@@ -562,7 +562,7 @@ public boolean test(@CommandLine.Mixin TestOptions opts) {
562562
);
563563
}
564564
log("The test " + (testPassed ? "passed" : "failed"));
565-
return testPassed;
565+
return testPassed?0:2;
566566
}
567567

568568
@CommandLine.Command(description = "Create ACL Policies")
@@ -580,11 +580,11 @@ public void create(@CommandLine.Mixin AclCreateOptions opts) throws IOException
580580
}
581581

582582
@CommandLine.Command(description = "Validate ACL Policies")
583-
public boolean validate(@CommandLine.Mixin AclOptions opts) {
583+
public int validate(@CommandLine.Mixin AclOptions opts) {
584584
final Validation validation = validatePolicies(opts);
585585
reportValidation(validation);
586586
log("The validation " + (validation.isValid() ? "passed" : "failed"));
587-
return validation.isValid();
587+
return validation.isValid() ? 0 : 2;
588588
}
589589

590590
private HashSet<Map<String, String>> resources(final Map<String, String> resourceMap) {

rd-cli-base/src/main/java/org/rundeck/client/tool/commands/repository/InstallPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.concurrent.Callable;
2828

2929
@CommandLine.Command(description = "Install a plugin from your plugin repository into your Rundeck instance", name = "install")
30-
public class InstallPlugin implements RdCommandExtension, RdOutput, Callable<Boolean> {
30+
public class InstallPlugin implements RdCommandExtension, RdOutput, Callable<Integer> {
3131
@Setter
3232
private RdTool rdTool;
3333

@@ -40,7 +40,7 @@ public class InstallPlugin implements RdCommandExtension, RdOutput, Callable<Boo
4040
@CommandLine.Option(names = {"--version", "-v"}, description = "(Optional) Specific version of the plugin you want to install")
4141
String version;
4242

43-
public Boolean call() throws InputError, IOException {
43+
public Integer call() throws InputError, IOException {
4444
RepositoryResponseHandler.handle(
4545
rdTool.apiWithErrorResponse(api -> {
4646
if (version != null) {
@@ -49,7 +49,7 @@ public Boolean call() throws InputError, IOException {
4949
return api.installPlugin(repoName, pluginId);
5050
}
5151
}), rdOutput);
52-
return true;
52+
return 0;
5353
}
5454

5555
}

rd-cli-base/src/main/java/org/rundeck/client/tool/commands/repository/UninstallPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.concurrent.Callable;
2828

2929
@CommandLine.Command(description = "Unistall a Rundeck plugin from your Rundeck instance", name = "uninstall")
30-
public class UninstallPlugin implements Callable<Boolean>, RdCommandExtension, RdOutput {
30+
public class UninstallPlugin implements Callable<Integer>, RdCommandExtension, RdOutput {
3131
@Setter
3232
private RdTool rdTool;
3333
@Setter
@@ -38,10 +38,10 @@ public class UninstallPlugin implements Callable<Boolean>, RdCommandExtension, R
3838
String pluginId;
3939

4040

41-
public Boolean call() throws InputError, IOException {
41+
public Integer call() throws InputError, IOException {
4242
RepositoryResponseHandler.handle(
4343
rdTool.apiWithErrorResponse(api -> api.uninstallPlugin(pluginId)), rdOutput
4444
);
45-
return true;
45+
return 0;
4646
}
4747
}

rd-cli-base/src/main/java/org/rundeck/client/tool/commands/repository/UploadPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.Callable;
2727

2828
@CommandLine.Command(description = "Upload a Rundeck plugin to your plugin repository", name = "upload")
29-
public class UploadPlugin extends BaseCommand implements Callable<Boolean> {
29+
public class UploadPlugin extends BaseCommand implements Callable<Integer> {
3030

3131
@CommandLine.Option(names = {"-r", "--repository"}, description = "Target name of repository to upload plugin into.", required = true)
3232
String repoName;
@@ -35,13 +35,13 @@ public class UploadPlugin extends BaseCommand implements Callable<Boolean> {
3535
String binaryPath;
3636

3737

38-
public Boolean call() throws InputError, IOException {
38+
public Integer call() throws InputError, IOException {
3939
File binary = new File(binaryPath);
4040
if (!binary.exists())
4141
throw new IOException(String.format("Unable to find specified file: %s", binaryPath));
4242
RequestBody fileUpload = RequestBody.create(binary, Client.MEDIA_TYPE_OCTET_STREAM);
4343

4444
RepositoryResponseHandler.handle(getRdTool().apiWithErrorResponse(api -> api.uploadPlugin(repoName, fileUpload)), getRdOutput());
45-
return true;
45+
return 0;
4646
}
4747
}

rd-cli-base/src/test/groovy/org/rundeck/client/tool/commands/repository/InstallPluginTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class InstallPluginTest extends Specification {
4646
installCmd.pluginId = 'bcf8885df1e8'
4747

4848
when:
49-
installCmd.call()
49+
def result = installCmd.call()
5050

5151
then:
5252
1 * api.installPlugin("private", 'bcf8885df1e8') >> Calls.response(new ArtifactActionMessage(msg: "Plugin Installed"))
5353
1 * out.output('Plugin Installed')
54+
result == 0
5455
}
5556
}

rd-cli-base/src/test/groovy/org/rundeck/client/tool/commands/repository/UninstallPluginTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class UninstallPluginTest extends Specification {
4343

4444

4545
when:
46-
uninstallCmd.call()
46+
def result=uninstallCmd.call()
4747

4848
then:
4949
1 * api.uninstallPlugin(_) >> Calls.response(new ArtifactActionMessage(msg: "Plugin Uninstalled"))
5050
1 * out.output('Plugin Uninstalled')
51+
result==0
5152
}
5253
}

rd-cli-base/src/test/groovy/org/rundeck/client/tool/commands/repository/UploadPluginTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class UploadPluginTest extends Specification {
4747

4848

4949
when:
50-
uploadCmd.call()
50+
def result = uploadCmd.call()
5151

5252
then:
5353
1 * api.uploadPlugin("private", _) >> Calls.response(new ArtifactActionMessage(msg: "Upload succeeded"))
5454
1 * out.output('Upload succeeded')
55+
result == 0
5556
}
5657
}

rd-cli-enterprise/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation libs.picocli
1515
annotationProcessor libs.picocliCodegen
1616

17-
testImplementation project(":rd-cli-lib"), project(":rd-api-client")
17+
testImplementation project(":rd-cli-lib"), project(":rd-api-client"), project(":rd-testing")
1818

1919
testImplementation libs.retrofitMock
2020
testImplementation libs.okhttpMockwebserver

rd-cli-enterprise/src/main/java/org/rundeck/client/tool/commands/enterprise/cluster/Mode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ static class Options {
2828
}
2929

3030
@CommandLine.Command(description = "Set cluster member execution mode Active")
31-
public boolean active(@CommandLine.Mixin Options options) throws IOException, InputError {
32-
return changeMode(ExecutionMode.active, options, EnterpriseApi::executionModeEnable);
31+
public int active(@CommandLine.Mixin Options options) throws IOException, InputError {
32+
return changeMode(ExecutionMode.active, options, EnterpriseApi::executionModeEnable) ? 0 : 1;
3333
}
3434

3535

3636
@CommandLine.Command(description = "Set cluster member execution mode Passive")
37-
public boolean passive(@CommandLine.Mixin Options options) throws IOException, InputError {
38-
return changeMode(ExecutionMode.passive, options, EnterpriseApi::executionModeDisable);
37+
public int passive(@CommandLine.Mixin Options options) throws IOException, InputError {
38+
return changeMode(ExecutionMode.passive, options, EnterpriseApi::executionModeDisable) ? 0 : 1;
3939
}
4040

4141
boolean changeMode(

rd-cli-enterprise/src/main/java/org/rundeck/client/tool/commands/enterprise/license/License.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static class StatusOpts {
5050
}
5151

5252
@CommandLine.Command(description = "license status")
53-
public boolean status(@CommandLine.Mixin StatusOpts opts) throws InputError, IOException {
53+
public int status(@CommandLine.Mixin StatusOpts opts) throws InputError, IOException {
5454
RdTool.apiVersionCheck("license status", 41, getClient().getApiVersion());
5555
LicenseResponse response = getClient().apiCall(EnterpriseApi::verifyLicense);
5656

@@ -85,9 +85,9 @@ public boolean status(@CommandLine.Mixin StatusOpts opts) throws InputError, IOE
8585
opts.getRemaining()
8686
));
8787
}
88-
return false;
88+
return 1;
8989
}
90-
return !opts.isStatus() || response.isActive();
90+
return (!opts.isStatus() || response.isActive()) ? 0 : 1;
9191
}
9292

9393

0 commit comments

Comments
 (0)