Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: test validation; local repo settings #18319

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions devtools/cli/src/main/java/io/quarkus/cli/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@
import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.BuildOptions;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
import picocli.CommandLine.Parameters;

@CommandLine.Command(name = "build", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, showEndOfOptionsDelimiterInUsageHelp = true, description = "Build the current project.")
@CommandLine.Command(name = "build", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, showEndOfOptionsDelimiterInUsageHelp = true, header = "Build the current project.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class Build extends BaseBuildCommand implements Callable<Integer> {

@CommandLine.Mixin
protected RunModeOption runMode;

@CommandLine.ArgGroup(order = 1, exclusive = false, validate = false, heading = "%nBuild options%n")
@CommandLine.ArgGroup(order = 1, exclusive = false, validate = false, heading = "%nBuild options:%n")
BuildOptions buildOptions = new BuildOptions();

@CommandLine.ArgGroup(order = 2, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@Parameters(description = "Additional parameters passed to the build system")
List<String> params = new ArrayList<>();

Expand All @@ -37,8 +33,7 @@ public Integer call() {
output.throwIfUnmatchedArguments(spec.commandLine());

BuildSystemRunner runner = getRunner();
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareBuild(buildOptions, propertiesOptions, runMode,
params);
BuildSystemRunner.BuildCommandArgs commandArgs = runner.prepareBuild(buildOptions, runMode, params);

if (runMode.isDryRun()) {
dryRunBuild(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs);
Expand Down
7 changes: 1 addition & 6 deletions devtools/cli/src/main/java/io/quarkus/cli/Completion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
import picocli.CommandLine;

@CommandLine.Command(name = "completion", version = "generate-completion "
+ CommandLine.VERSION, mixinStandardHelpOptions = true, description = {
"bash/zsh completion: source <(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME})",
"Run the following command to give `${ROOT-COMMAND-NAME:-$PARENTCOMMAND}` TAB completion in the current shell:",
"",
" source <(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME})",
"" }, optionListHeading = "Options:%n", helpCommand = true)
+ CommandLine.VERSION, mixinStandardHelpOptions = true, header = "bash/zsh completion: source <(${PARENT-COMMAND-FULL-NAME:-$PARENTCOMMAND} ${COMMAND-NAME})", helpCommand = true, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "Options:%n")
public class Completion extends GenerateCompletion {

}
7 changes: 4 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/Create.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import picocli.CommandLine.ParseResult;
import picocli.CommandLine.Unmatched;

@CommandLine.Command(name = "create", sortOptions = false, mixinStandardHelpOptions = false, description = "Create a new project.", subcommands = {
CreateApp.class, CreateCli.class /* , CreateExtension.class */ })
@CommandLine.Command(name = "create", sortOptions = false, mixinStandardHelpOptions = false, header = "Create a new project.", subcommands = {
CreateApp.class,
CreateCli.class /* , CreateExtension.class */ }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n")
public class Create extends BaseCreateCommand {

@Unmatched // avoids throwing errors for unmatched arguments
List<String> unmatchedArgs;

@Override
public Integer call() throws Exception {
output.info("Creating an app (the project type was inferred, see --help).");
output.info("Creating an app (default project type, see --help).");

ParseResult result = spec.commandLine().getParseResult();
CommandLine appCommand = spec.subcommands().get("app");
Expand Down
31 changes: 20 additions & 11 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@
import picocli.CommandLine.Mixin;

@CommandLine.Command(name = "app", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Create a Quarkus application project.", description = "%n"
+ "This command will create a Java project in a new ARTIFACT-ID directory. ", footer = { "%n"
+ "Using default values: a new Java project will be created in a 'code-with-quarkus' directory; "
+ "it will use Maven to build an artifact with groupId='org.acme', artifactId='code-with-quarkus', and version='1.0.0-SNAPSHOT'.%n" })
+ "This command will create a Java project in a new ARTIFACT-ID directory", footer = { "%n"
+ "For example (using default values), a new Java project will be created in a 'code-with-quarkus' directory; "
+ "it will use Maven to build an artifact with groupId='org.acme', artifactId='code-with-quarkus', and version='1.0.0-SNAPSHOT'."
+ "%n" }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class CreateApp extends BaseCreateCommand {
@Mixin
CreateProjectMixin createProject;

@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nProject identifiers%n")
@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nProject identifiers:%n")
TargetGAVGroup gav = new TargetGAVGroup();

@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version%n")
@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version:%n")
TargetQuarkusVersionGroup targetQuarkusVersion = new TargetQuarkusVersionGroup();

@CommandLine.ArgGroup(order = 3, heading = "%nBuild tool (Default: Maven)%n")
@CommandLine.ArgGroup(order = 3, heading = "%nBuild tool (Maven):%n")
TargetBuildToolGroup targetBuildTool = new TargetBuildToolGroup();

@CommandLine.ArgGroup(order = 4, heading = "%nTarget language (Default: Java)%n")
@CommandLine.ArgGroup(order = 4, heading = "%nTarget language (Java):%n")
TargetLanguageGroup targetLanguage = new TargetLanguageGroup();

@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation%n")
@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation:%n")
CodeGenerationGroup codeGeneration = new CodeGenerationGroup();

@CommandLine.ArgGroup(order = 6, exclusive = false, validate = false)
Expand All @@ -56,7 +57,9 @@ public Integer call() throws Exception {

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
createProject.projectRoot(); // verify project directories early
if (createProject.checkProjectRootAlreadyExists(output)) {
return CommandLine.ExitCode.USAGE;
}

BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN);
SourceType sourceType = targetLanguage.getSourceType(buildTool, extensions, output);
Expand All @@ -70,12 +73,18 @@ public Integer call() throws Exception {

if (runMode.isDryRun()) {
createProject.dryRun(buildTool, invocation, output);
} else if (buildTool == null || buildTool == BuildTool.JBANG) { // buildless / JBang
} else if (buildTool == BuildTool.JBANG) {
success = new CreateJBangProjectCommandHandler().execute(invocation).isSuccess();
} else { // maven or gradle
success = new CreateProjectCommandHandler().execute(invocation).isSuccess();
}
return success ? CommandLine.ExitCode.OK : CommandLine.ExitCode.SOFTWARE;

if (success) {
output.info(
"Navigate into this directory and get started: " + spec.root().qualifiedName() + " dev");
return CommandLine.ExitCode.OK;
}
return CommandLine.ExitCode.SOFTWARE;
} catch (Exception e) {
return output.handleCommandException(e,
"Unable to create project: " + e.getMessage());
Expand Down
29 changes: 19 additions & 10 deletions devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@
import picocli.CommandLine.Mixin;

@CommandLine.Command(name = "cli", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Create a Quarkus command-line project.", description = "%n"
+ "This command will create a Java project in a new ARTIFACT-ID directory. ", footer = { "%n"
+ "Using default values: a new Java project will be created in a 'code-with-quarkus' directory; "
+ "it will use Maven to build an artifact with groupId='org.acme', artifactId='code-with-quarkus', and version='1.0.0-SNAPSHOT'.%n" })
+ "This command will create a Java project in a new ARTIFACT-ID directory.", footer = { "%n"
+ "For example (using default values), a new Java project will be created in a 'code-with-quarkus' directory; "
+ "it will use Maven to build an artifact with groupId='org.acme', artifactId='code-with-quarkus', and version='1.0.0-SNAPSHOT'."
+ "%n" }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class CreateCli extends BaseCreateCommand {
@Mixin
CreateProjectMixin createProject;

@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nProject identifiers%n")
@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nProject identifiers:%n")
TargetGAVGroup gav = new TargetGAVGroup();

@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version%n")
@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version:%n")
TargetQuarkusVersionGroup targetQuarkusVersion = new TargetQuarkusVersionGroup();

@CommandLine.ArgGroup(order = 3, heading = "%nBuild tool (Default: Maven)%n")
@CommandLine.ArgGroup(order = 3, heading = "%nBuild tool (Maven):%n")
TargetBuildToolGroup targetBuildTool = new TargetBuildToolGroup();

@CommandLine.ArgGroup(order = 4, heading = "%nTarget language (Default: Java)%n")
@CommandLine.ArgGroup(order = 4, heading = "%nTarget language (Java):%n")
TargetLanguageGroup targetLanguage = new TargetLanguageGroup();

@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation%n")
@CommandLine.ArgGroup(order = 5, exclusive = false, heading = "%nCode Generation:%n")
CodeGenerationGroup codeGeneration = new CodeGenerationGroup();

@CommandLine.ArgGroup(order = 6, exclusive = false, validate = false)
Expand All @@ -58,7 +59,9 @@ public Integer call() throws Exception {

createProject.setSingleProjectGAV(gav);
createProject.setTestOutputDirectory(output.getTestDirectory());
createProject.projectRoot(); // verify project directories early
if (createProject.checkProjectRootAlreadyExists(output)) {
return CommandLine.ExitCode.USAGE;
}

BuildTool buildTool = targetBuildTool.getBuildTool(BuildTool.MAVEN);
SourceType sourceType = targetLanguage.getSourceType(buildTool, extensions, output);
Expand All @@ -76,7 +79,13 @@ public Integer call() throws Exception {
} else {
success = new CreateProjectCommandHandler().execute(invocation).isSuccess();
}
return success ? CommandLine.ExitCode.OK : CommandLine.ExitCode.SOFTWARE;

if (success) {
output.info(
"Navigate into this directory and get started: " + spec.root().qualifiedName() + " dev");
return CommandLine.ExitCode.OK;
}
return CommandLine.ExitCode.SOFTWARE;
} catch (Exception e) {
return output.handleCommandException(e,
"Unable to create project: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import picocli.CommandLine;
import picocli.CommandLine.Mixin;

@CommandLine.Command(name = "extension", sortOptions = false, mixinStandardHelpOptions = false, header = "Create a Quarkus extension project", description = "%n"
@CommandLine.Command(name = "extension", sortOptions = false, mixinStandardHelpOptions = false, showDefaultValues = true, header = "Create a Quarkus extension project", description = "%n"
+ "Quarkus extensions are built from multiple modules: runtime, deployment, and "
+ "integration-test. This command will generate a Maven multi-module project in a directory called EXTENSION-ID "
+ " by applying naming conventions to the specified EXTENSION-ID.%n", footer = { "%nDefault Naming conventions%n",
Expand Down Expand Up @@ -39,7 +39,7 @@
" hello-world/integration-test:",
" artifact:\torg.acme:hello-world-integration-tests:1.0.0-SNAPSHOT",
" name:\tHello World - Integration Tests", " package name: org.acme.hello.world.it",
"%nGenerated classes will use 'HelloWorld' as a class name prefix." }, showDefaultValues = true)
"%nGenerated classes will use 'HelloWorld' as a class name prefix." }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class CreateExtension extends BaseCreateCommand {

@Mixin
Expand Down
13 changes: 4 additions & 9 deletions devtools/cli/src/main/java/io/quarkus/cli/Dev.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.common.DebugOptions;
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.PropertiesOptions;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
import picocli.CommandLine.Parameters;

@CommandLine.Command(name = "dev", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, showEndOfOptionsDelimiterInUsageHelp = true, description = "Run the current project in dev (live coding) mode.")
@CommandLine.Command(name = "dev", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, showEndOfOptionsDelimiterInUsageHelp = true, header = "Run the current project in dev (live coding) mode.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "Options:%n")
public class Dev extends BaseBuildCommand implements Callable<Integer> {

@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nDev Mode options%n")
@CommandLine.ArgGroup(order = 1, exclusive = false, heading = "%nDev Mode options:%n")
DevOptions devOptions = new DevOptions();

@CommandLine.ArgGroup(order = 2, exclusive = false, validate = false)
PropertiesOptions propertiesOptions = new PropertiesOptions();

@CommandLine.ArgGroup(order = 3, exclusive = false, validate = true, heading = "%nDebug options%n")
@CommandLine.ArgGroup(order = 3, exclusive = false, validate = true, heading = "%nDebug options:%n")
DebugOptions debugOptions = new DebugOptions();

@Parameters(description = "Parameters passed to the application.")
Expand All @@ -38,8 +34,7 @@ public Integer call() {
output.throwIfUnmatchedArguments(spec.commandLine());

BuildSystemRunner runner = getRunner();
List<Supplier<BuildSystemRunner.BuildCommandArgs>> commandArgs = runner.prepareDevMode(devOptions,
propertiesOptions, debugOptions,
List<Supplier<BuildSystemRunner.BuildCommandArgs>> commandArgs = runner.prepareDevMode(devOptions, debugOptions,
params);

if (devOptions.isDryRun()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
import picocli.CommandLine.Unmatched;

@CommandLine.Command(name = "extension", aliases = {
"ext" }, sortOptions = false, mixinStandardHelpOptions = false, description = "List, add, and remove extensions of an existing project.", subcommands = {
"ext" }, sortOptions = false, mixinStandardHelpOptions = false, header = "List, add, and remove extensions of an existing project.", subcommands = {
ProjectExtensionsList.class, ProjectExtensionsCategories.class,
ProjectExtensionsAdd.class, ProjectExtensionsRemove.class })
ProjectExtensionsAdd.class,
ProjectExtensionsRemove.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "Options:%n")
public class ProjectExtensions extends BaseBuildCommand implements Callable<Integer> {

@Unmatched // avoids throwing errors for unmatched arguments
List<String> unmatchedArgs;

@Override
public Integer call() throws Exception {
output.info("No subcommand specified, listing current extensions (see --help).");
output.info("Listing extensions (default action, see --help).");

ParseResult result = spec.commandLine().getParseResult();
List<String> args = result.originalArgs().stream().filter(x -> !"extension".equals(x) && !"ext".equals(x))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import picocli.CommandLine;
import picocli.CommandLine.Mixin;

@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, description = "Add extension(s) to this project.")
@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Add extension(s) to this project.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "%nOptions:%n")
public class ProjectExtensionsAdd extends BaseBuildCommand implements Callable<Integer> {

@Mixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
import picocli.CommandLine;
import picocli.CommandLine.Mixin;

@CommandLine.Command(name = "categories", aliases = "cat", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, description = "List existing extension categories.")
@CommandLine.Command(name = "categories", aliases = "cat", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "List extension categories.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", parameterListHeading = "%n", optionListHeading = "%nOptions:%n")
public class ProjectExtensionsCategories extends BaseBuildCommand implements Callable<Integer> {

@Mixin
RunModeOption runMode;

@CommandLine.ArgGroup(heading = "%nOutput format%n")
@CommandLine.ArgGroup(heading = "%nOutput format:%n")
CategoryListFormatOptions format = new CategoryListFormatOptions();

@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version%n")
@CommandLine.ArgGroup(order = 2, heading = "%nQuarkus version:%n")
TargetQuarkusVersionGroup targetQuarkusVersion = new TargetQuarkusVersionGroup();

@Override
Expand Down
Loading