Skip to content

Commit

Permalink
Merge pull request #500 from rundeck/RUN-1631
Browse files Browse the repository at this point in the history
RUN-1631: fix exit code for executions deletebulk --require
  • Loading branch information
gschueler authored Apr 20, 2023
2 parents ca24e74 + 039ab71 commit 196b5f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.rundeck.client.tool.commands;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import okhttp3.ResponseBody;
Expand Down Expand Up @@ -48,9 +47,6 @@
*/
@CommandLine.Command(name = "executions", description = "List running executions, attach and follow their output, or kill them.")
public class Executions extends BaseCommand {

private static final ObjectMapper JSON = new ObjectMapper();

@Getter
@Setter
static class KillOptions extends ExecutionIdOption{
Expand Down Expand Up @@ -532,7 +528,7 @@ public boolean deleteall(@CommandLine.Mixin DeleteAllExecCmd options) throws IOE

// End Delete all executions.

static interface HasJobIdList {
interface HasJobIdList {
List<String> getJobIdList();

default boolean isJobIdList() {
Expand Down Expand Up @@ -568,7 +564,7 @@ public boolean isIdlist() {

@CommandLine.Command(description = "Find and delete executions in a project. Use the query options to find and delete " +
"executions, or specify executions with the `idlist` option.")
public boolean deletebulk(@CommandLine.Mixin BulkDeleteCmd options,
public int deletebulk(@CommandLine.Mixin BulkDeleteCmd options,
@CommandLine.Mixin PagingResultOptions paging,
@CommandLine.Mixin ExecutionOutputFormatOption outputFormatOption) throws IOException, InputError {

Expand All @@ -588,7 +584,7 @@ public boolean deletebulk(@CommandLine.Mixin BulkDeleteCmd options,
} else {
getRdOutput().warning("No executions found to delete");
}
return !options.isRequire();
return options.isRequire()?2:0;
}
}

Expand All @@ -598,7 +594,7 @@ public boolean deletebulk(@CommandLine.Mixin BulkDeleteCmd options,

if (!"y".equals(s)) {
getRdOutput().warning("Not deleting executions.");
return false;
return 1;
}
}
final List<String> finalExecIds = execIds;
Expand All @@ -613,7 +609,7 @@ public boolean deletebulk(@CommandLine.Mixin BulkDeleteCmd options,
}else{
getRdOutput().info(String.format("Deleted %d executions.", result.getSuccessCount()));
}
return result.isAllsuccessful();
return result.isAllsuccessful()?0:1;
}

public static boolean maybeFollow(
Expand Down Expand Up @@ -651,7 +647,7 @@ public static boolean maybeFollow(
/**
* @param millis wait time
*
* @return wait function which returns false if interrupted, true otherwise
* @return wait function which returns false if interrupted true otherwise
*/
private static BooleanSupplier waitUnlessInterrupt(final int millis) {
return () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class ExecutionsSpec extends Specification {

where:
reqd | expect
true | false
false | true
true | 2
false | 0
}

private RdTool setupMock(RundeckApi api) {
Expand Down Expand Up @@ -199,7 +199,7 @@ class ExecutionsSpec extends Specification {

def "parse execution"() {
given:
MockWebServer server = new MockWebServer();
MockWebServer server = new MockWebServer()
server.enqueue(new MockResponse().setBody('''{
"id": 5418,
"href": "http://ecto1.local:4440/api/19/execution/5418",
Expand Down Expand Up @@ -233,7 +233,7 @@ class ExecutionsSpec extends Specification {
]
}'''
).addHeader('content-type', 'application/json')
);
)
server.start()

def retrofit = new Retrofit.Builder().baseUrl(server.url('/api/19/')).
Expand All @@ -256,7 +256,7 @@ class ExecutionsSpec extends Specification {

def "parse compacted log"() {
given:
MockWebServer server = new MockWebServer();
MockWebServer server = new MockWebServer()
server.enqueue(new MockResponse().setBody('''{
"id": 5418,
"compacted":true,
Expand All @@ -269,7 +269,7 @@ class ExecutionsSpec extends Specification {
"serverUUID": "3425B691-7319-4EEE-8425-F053C628B4BA"
}'''
).addHeader('content-type', 'application/json')
);
)
server.start()

def retrofit = new Retrofit.Builder().baseUrl(server.url('/api/19/')).
Expand Down

0 comments on commit 196b5f1

Please sign in to comment.