Skip to content

Commit

Permalink
Unify command line use of create operations
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Dec 27, 2024
1 parent 32052de commit 3d86aa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 49 deletions.
14 changes: 10 additions & 4 deletions src/main/java/rife/bld/operations/AbstractCreateOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,25 +390,31 @@ public T fromArguments(List<String> arguments) {
throw new OperationOptionException("ERROR: Expecting the package, project and base names as the arguments.");
}

if (package_name == null || package_name.isEmpty()) {
if (package_name == null || package_name.isBlank()) {
System.out.println("Please enter a package name (for instance: com.example):");
package_name = System.console().readLine();
if (package_name == null || package_name.isEmpty()) {
throw new OperationOptionException("ERROR: package name is required.");
}
} else {
System.out.println("Using package name: " + package_name);
}

if (project_name == null || project_name.isEmpty()) {
if (project_name == null || project_name.isBlank()) {
System.out.println("Please enter a project name (for instance: my-app):");
project_name = System.console().readLine();
if (project_name == null || project_name.isEmpty()) {
throw new OperationOptionException("ERROR: project name is required.");
}
} else {
System.out.println("Using project name: " + project_name);
}

if (base_name == null || base_name.isEmpty()) {
if (base_name == null || base_name.isBlank()) {
var default_base_name = generateBaseName(project_name);
System.out.println("Please enter the base name for generated project classes (default: " + default_base_name + "):");
base_name = System.console().readLine();
if (base_name == null || base_name.trim().isEmpty()) {
if (base_name == null || base_name.isBlank()) {
base_name = default_base_name;
System.out.println("Using base name: " + base_name);
}
Expand Down
52 changes: 7 additions & 45 deletions src/main/java/rife/bld/operations/CreateOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import rife.bld.operations.exceptions.OperationOptionException;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -37,14 +38,19 @@ public class CreateOperation {
if (!arguments.isEmpty()) {
type = arguments.remove(0);
}

var create_operation_args = new ArrayList<String>();
if (!arguments.isEmpty()) {
package_name = arguments.remove(0);
create_operation_args.add(package_name);
}
if (!arguments.isEmpty()) {
project_name = arguments.remove(0);
create_operation_args.add(project_name);
}
if (!arguments.isEmpty()) {
base_name = arguments.remove(0);
create_operation_args.add(base_name);
}
if ((package_name == null || project_name == null || base_name == null) && System.console() == null) {
throw new OperationOptionException("ERROR: Expecting the package, project and base names as the arguments.");
Expand Down Expand Up @@ -81,50 +87,6 @@ public class CreateOperation {
throw new OperationOptionException("ERROR: Unsupported project type.");
}

if (package_name == null || package_name.isBlank()) {
System.out.println("Please enter a package name (for instance: com.example):");
package_name = System.console().readLine();
if (package_name == null || package_name.isEmpty()) {
throw new OperationOptionException("ERROR: package name is required.");
}
} else {
System.out.println("Using package name: " + package_name);
}

if (project_name == null || project_name.isBlank()) {
String name_example;
if (LIB.equals(type)) {
name_example = "my-lib";
} else if (RIFE2.equals(type)) {
name_example = "my-webapp";
} else {
name_example = "my-app";
}
System.out.println("Please enter a project name (for instance: " + name_example + ")");
project_name = System.console().readLine();
if (project_name == null || project_name.isEmpty()) {
throw new OperationOptionException("ERROR: project name is required.");
}
} else {
System.out.println("Using project name: " + project_name);
}

if (base_name == null || base_name.isBlank()) {
var default_base_name = AbstractCreateOperation.generateBaseName(project_name);
System.out.println("Please enter the base name for generated project classes (default: " + default_base_name + "):");
base_name = System.console().readLine();
if (base_name == null || base_name.isBlank()) {
base_name = default_base_name;
System.out.println("Using base name: " + base_name);
}
} else {
System.out.println("Using base name: " + base_name);
}

return create_operation.workDirectory(new File(System.getProperty("user.dir")))
.packageName(package_name)
.projectName(project_name)
.baseName(base_name)
.downloadDependencies(true);
return create_operation.fromArguments(create_operation_args);
}
}

0 comments on commit 3d86aa8

Please sign in to comment.