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

io.quarkus.cli.ProjectExtensionsRemove Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.cli;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.Callable;

import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;

@CommandLine.Command(name = "remove", aliases = "rm", header = "Remove extension(s) from this project.")
public class ProjectExtensionsRemove extends BaseBuildCommand implements Callable {

    @CommandLine.Mixin
    RunModeOption runMode;

    @CommandLine.Parameters(arity = "1", paramLabel = "EXTENSION", description = "Extension(s) to remove from this project.", split = ",")
    Set extensions;

    @Override
    public Integer call() {
        try {
            output.debug("Remove extensions with initial parameters: %s", this);
            output.throwIfUnmatchedArguments(spec.commandLine());

            BuildSystemRunner runner = getRunner();
            if (runMode.isDryRun()) {
                dryRunRemove(spec.commandLine().getHelp(), runner.getBuildTool());
                return CommandLine.ExitCode.OK;
            }

            return runner.removeExtension(runMode, extensions);
        } catch (Exception e) {
            return output.handleCommandException(e,
                    "Unable to remove extension(s): " + e.getMessage());
        }
    }

    void dryRunRemove(CommandLine.Help help, BuildTool buildTool) {
        output.printText(new String[] {
                "\nRemove extensions to the current project in \n",
                "\t" + projectRoot().toString()
        });
        Map dryRunOutput = new TreeMap<>();

        dryRunOutput.put("Build tool", buildTool.name());
        dryRunOutput.put("Batch (non-interactive mode)", Boolean.toString(runMode.isBatchMode()));
        dryRunOutput.put("Extension(s) to remove", extensions.toString());

        output.info(help.createTextTable(dryRunOutput).toString());
    };

    @Override
    public String toString() {
        return "ProjectExtensionRemove [extensions=" + extensions + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy