Search in sources :

Example 1 with Option

use of com.lexicalscope.jewel.cli.Option in project rundeck-cli by rundeck.

the class UploadPlugin method upload.

@Command(isDefault = true)
public void upload(UploadPluginOption option, CommandOutput output) throws InputError, IOException {
    File binary = new File(option.getBinaryPath());
    if (!binary.exists())
        throw new IOException(String.format("Unable to find specified file: %s", option.getBinaryPath()));
    RequestBody fileUpload = RequestBody.create(Client.MEDIA_TYPE_OCTET_STREAM, binary);
    RepositoryResponseHandler.handle(rdTool.apiWithErrorResponse(api -> api.uploadPlugin(option.getRepoName(), fileUpload)), output);
}
Also used : Command(org.rundeck.toolbelt.Command) CommandOutput(org.rundeck.toolbelt.CommandOutput) CommandLineInterface(com.lexicalscope.jewel.cli.CommandLineInterface) InputError(org.rundeck.client.tool.InputError) Setter(lombok.Setter) Option(com.lexicalscope.jewel.cli.Option) RdCommandExtension(org.rundeck.client.tool.extension.RdCommandExtension) RdTool(org.rundeck.client.tool.extension.RdTool) Client(org.rundeck.client.util.Client) IOException(java.io.IOException) File(java.io.File) RequestBody(okhttp3.RequestBody) IOException(java.io.IOException) File(java.io.File) RequestBody(okhttp3.RequestBody) Command(org.rundeck.toolbelt.Command)

Example 2 with Option

use of com.lexicalscope.jewel.cli.Option in project rundeck-cli by rundeck.

the class Files method list.

@Command(description = "List files uploaded for a Job or Execution (API v19). Specify Job ID or Execution ID")
public void list(FileListOpts opts, CommandOutput out) throws IOException, InputError {
    if (!opts.isJobId() && !opts.isExecId() || opts.isExecId() && opts.isJobId()) {
        throw new InputError("One of -j/--jobid or -e/--eid is required");
    }
    if (opts.isExecId() && opts.isFileState()) {
        throw new InputError("-s/--state not a valid option for -e/--eid");
    }
    int offset = opts.isOffset() ? opts.getOffset() : 0;
    int max = opts.isMax() ? opts.getMax() : 20;
    JobFileItemList result;
    if (opts.isJobId()) {
        result = apiCall(api -> api.listJobFiles(opts.getJobId(), opts.isFileState() ? opts.getFileState().toString() : null, offset, max));
    } else {
        result = apiCall(api -> api.listExecutionFiles(opts.getExecId(), offset, max));
    }
    Paging paging = result.getPaging();
    if (paging != null) {
        out.info(paging);
    }
    out.output(result.asList());
    if (paging != null && paging.hasMoreResults()) {
        out.info(paging.moreResults("-o"));
    }
}
Also used : Command(org.rundeck.toolbelt.Command) CommandOutput(org.rundeck.toolbelt.CommandOutput) CommandLineInterface(com.lexicalscope.jewel.cli.CommandLineInterface) Option(com.lexicalscope.jewel.cli.Option) AppCommand(org.rundeck.client.tool.commands.AppCommand) JobFileItemList(org.rundeck.client.api.model.JobFileItemList) Client(org.rundeck.client.util.Client) IOException(java.io.IOException) JobFileUploadResult(org.rundeck.client.api.model.JobFileUploadResult) File(java.io.File) RequestBody(okhttp3.RequestBody) InputError(org.rundeck.client.tool.InputError) RdApp(org.rundeck.client.tool.RdApp) Paging(org.rundeck.client.api.model.Paging) RdTool(org.rundeck.client.tool.extension.RdTool) PagingResultOptions(org.rundeck.client.tool.options.PagingResultOptions) JobFileItem(org.rundeck.client.api.model.JobFileItem) InputError(org.rundeck.client.tool.InputError) Paging(org.rundeck.client.api.model.Paging) JobFileItemList(org.rundeck.client.api.model.JobFileItemList) Command(org.rundeck.toolbelt.Command) AppCommand(org.rundeck.client.tool.commands.AppCommand)

Aggregations

CommandLineInterface (com.lexicalscope.jewel.cli.CommandLineInterface)2 Option (com.lexicalscope.jewel.cli.Option)2 File (java.io.File)2 IOException (java.io.IOException)2 RequestBody (okhttp3.RequestBody)2 InputError (org.rundeck.client.tool.InputError)2 RdTool (org.rundeck.client.tool.extension.RdTool)2 Client (org.rundeck.client.util.Client)2 Command (org.rundeck.toolbelt.Command)2 CommandOutput (org.rundeck.toolbelt.CommandOutput)2 Setter (lombok.Setter)1 JobFileItem (org.rundeck.client.api.model.JobFileItem)1 JobFileItemList (org.rundeck.client.api.model.JobFileItemList)1 JobFileUploadResult (org.rundeck.client.api.model.JobFileUploadResult)1 Paging (org.rundeck.client.api.model.Paging)1 RdApp (org.rundeck.client.tool.RdApp)1 AppCommand (org.rundeck.client.tool.commands.AppCommand)1 RdCommandExtension (org.rundeck.client.tool.extension.RdCommandExtension)1 PagingResultOptions (org.rundeck.client.tool.options.PagingResultOptions)1