io.quarkus.cli.Dev Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-cli Show documentation
Show all versions of quarkus-cli Show documentation
Quarkus command line utility
package io.quarkus.cli;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.DebugOptions;
import io.quarkus.cli.common.DevOptions;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
import picocli.CommandLine.Parameters;
@CommandLine.Command(name = "dev", showEndOfOptionsDelimiterInUsageHelp = true, header = "Run the current project in dev (live coding) mode.")
public class Dev extends BaseBuildCommand implements Callable {
@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nDev Mode options:%n")
DevOptions devOptions = new DevOptions();
@CommandLine.ArgGroup(order = 3, exclusive = false, validate = true, heading = "%nDebug options:%n")
DebugOptions debugOptions = new DebugOptions();
@Parameters(description = "Parameters passed to the application.")
List params = new ArrayList<>();
@Override
public Integer call() {
try {
output.debug("Run project in dev mode with initial parameters: %s", this);
output.throwIfUnmatchedArguments(spec.commandLine());
BuildSystemRunner runner = getRunner();
List> commandArgs = runner.prepareDevTestMode(
true, devOptions, debugOptions, params);
if (devOptions.isDryRun()) {
dryRunDev(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs.iterator().next().get());
return CommandLine.ExitCode.OK;
}
Integer ret = 1;
for (Supplier i : commandArgs) {
ret = runner.run(i.get());
if (ret != 0) {
return ret;
}
}
return ret;
} catch (Exception e) {
return output.handleCommandException(e,
"Unable to launch project in dev mode: " + e.getMessage());
}
}
void dryRunDev(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.BuildCommandArgs args) {
output.printText(new String[] {
"\nRun current project in dev mode\n",
"\t" + projectRoot().toString()
});
Map dryRunOutput = new TreeMap<>();
dryRunOutput.put("Build tool", buildTool.name());
output.info(help.createTextTable(dryRunOutput).toString());
output.printText(new String[] {
"\nCommand line:\n",
args.showCommand()
});
}
@Override
public String toString() {
return "Dev [debugOptions=" + debugOptions
+ ", devOptions=" + devOptions
+ ", properties=" + propertiesOptions.properties
+ ", output=" + output
+ ", params=" + params + "]";
}
}