All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloudbees.sdk.commands.config.ConfigParametersDelete Maven / Gradle / Ivy

/*
 * Copyright 2010-2013, CloudBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cloudbees.sdk.commands.config;


import com.cloudbees.api.BeesClient;
import com.cloudbees.api.ConfigurationParametersDeleteResponse;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;
import com.cloudbees.sdk.utils.Helper;

/**
 * @author Fabian Donze
 */
@BeesCommand(group="Configuration")
@CLICommand("config:delete")
public class ConfigParametersDelete extends ConfigParametersBase {
    private Boolean force;

    public ConfigParametersDelete() {
    }

    public void setForce(Boolean force) {
        this.force = force;
    }

    @Override
    protected boolean preParseCommandLine() {
        if (super.preParseCommandLine()) {
            addOption( "f", "force", false, "force delete without prompting" );
            return true;
        }
        return false;
    }

    @Override
    protected boolean execute() throws Exception {
        String resourceId;
        String resourceType;
        if (isGlobal("delete all")) {
            resourceId = getAccount();
            resourceType = "global";
        } else {
            resourceId = getAppId();
            resourceType = "application";
        }

        if (force == null || !force.booleanValue()) {
            if (!Helper.promptMatches("Are you sure you want to delete the " + resourceType + " configuration parameters for [" + resourceId + "]: (y/n) ", "[yY].*")) {
                return true;
            }
        }

        BeesClient client = getBeesClient(BeesClient.class);
        ConfigurationParametersDeleteResponse res = client.configurationParametersDelete(resourceId, resourceType);
        if (isTextOutput()) {
            displayStatus(resourceType, resourceId, res.getStatus());
        } else {
            printOutput(res, ConfigurationParametersDeleteResponse.class);
        }
        return true;
    }
    }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy