mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 00:07:12 -07:00
Renamed the 'create' command to 'create-rife2' and created a new 'create' command that selects the type of project.
This commit is contained in:
parent
5fa1f42f31
commit
4f176847c6
4 changed files with 140 additions and 4 deletions
|
@ -15,6 +15,7 @@ import rife.bld.operations.*;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class Cli extends BuildExecutor {
|
||||
private final CreateOperation createOperation_ = new CreateOperation();
|
||||
private final CreateBaseOperation createBaseOperation_ = new CreateBaseOperation();
|
||||
private final CreateBlankOperation createBlankOperation_ = new CreateBlankOperation();
|
||||
private final CreateLibOperation createLibOperation_ = new CreateLibOperation();
|
||||
|
@ -26,12 +27,12 @@ public class Cli extends BuildExecutor {
|
|||
* The standard {@code create} command.
|
||||
*
|
||||
* @throws Exception when an error occurred during the creation process
|
||||
* @since 1.5
|
||||
* @since 1.7
|
||||
*/
|
||||
@BuildCommand(help = CreateRife2Help.class)
|
||||
@BuildCommand(help = CreateHelp.class)
|
||||
public void create()
|
||||
throws Exception {
|
||||
createRife2Operation_.executeOnce(() -> createRife2Operation_.fromArguments(arguments()));
|
||||
createOperation_.fromArguments(arguments()).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,6 +71,18 @@ public class Cli extends BuildExecutor {
|
|||
createLibOperation_.executeOnce(() -> createLibOperation_.fromArguments(arguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The standard {@code create-rife2} command.
|
||||
*
|
||||
* @throws Exception when an error occurred during the creation process
|
||||
* @since 1.5
|
||||
*/
|
||||
@BuildCommand(value = "create-rife2", help = CreateRife2Help.class)
|
||||
public void createRife2()
|
||||
throws Exception {
|
||||
createRife2Operation_.executeOnce(() -> createRife2Operation_.fromArguments(arguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The standard {@code upgrade} command.
|
||||
*
|
||||
|
|
30
src/main/java/rife/bld/help/CreateHelp.java
Normal file
30
src/main/java/rife/bld/help/CreateHelp.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.help;
|
||||
|
||||
import rife.bld.CommandHelp;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* Provides help for the create command.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.7
|
||||
*/
|
||||
public class CreateHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new project";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new project.
|
||||
|
||||
Usage : ${topic} <type> <package> <name>
|
||||
type The type of project to create (base, blank, lib, rife2)
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import rife.bld.CommandHelp;
|
|||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* Provides help for the create command.
|
||||
* Provides help for the create-rife2 command.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5
|
||||
|
|
93
src/main/java/rife/bld/operations/CreateOperation.java
Normal file
93
src/main/java/rife/bld/operations/CreateOperation.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.operations;
|
||||
|
||||
import rife.bld.operations.exceptions.OperationOptionException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creates a new project structure
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.7
|
||||
*/
|
||||
public class CreateOperation {
|
||||
/**
|
||||
* Configures a creation operation from command-line arguments.
|
||||
*
|
||||
* @param arguments the arguments that will be considered
|
||||
* @return this operation instance
|
||||
* @since 1.7
|
||||
*/
|
||||
public AbstractCreateOperation<?, ?> fromArguments(List<String> arguments) {
|
||||
String type = null;
|
||||
String package_name = null;
|
||||
String project_name = null;
|
||||
if (arguments.size() > 0) {
|
||||
type = arguments.remove(0);
|
||||
}
|
||||
if (arguments.size() > 0) {
|
||||
package_name = arguments.remove(0);
|
||||
}
|
||||
if (arguments.size() > 0) {
|
||||
project_name = arguments.remove(0);
|
||||
}
|
||||
if ((type == null || package_name == null || project_name == null) && System.console() == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the type, package and project names as the arguments.");
|
||||
}
|
||||
|
||||
if (type == null || type.isEmpty()) {
|
||||
System.out.println("Please enter a number for the project type:");
|
||||
System.out.println(" 1: base");
|
||||
System.out.println(" 2: blank");
|
||||
System.out.println(" 3: lib");
|
||||
System.out.println(" 4: rife2");
|
||||
var number = System.console().readLine();
|
||||
switch (Integer.parseInt(number)) {
|
||||
case 1 -> type = "base";
|
||||
case 2 -> type = "blank";
|
||||
case 3 -> type = "lib";
|
||||
case 4 -> type = "rife2";
|
||||
}
|
||||
} else {
|
||||
System.out.println("Using project type: " + type);
|
||||
}
|
||||
if (type == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the project type.");
|
||||
}
|
||||
|
||||
AbstractCreateOperation<?, ?> create_operation = null;
|
||||
switch (type) {
|
||||
case "base" -> create_operation = new CreateBaseOperation();
|
||||
case "blank" -> create_operation = new CreateBlankOperation();
|
||||
case "lib" -> create_operation = new CreateLibOperation();
|
||||
case "rife2" -> create_operation = new CreateRife2Operation();
|
||||
}
|
||||
if (create_operation == null) {
|
||||
throw new OperationOptionException("ERROR: Unsupported project type.");
|
||||
}
|
||||
|
||||
if (package_name == null || package_name.isEmpty()) {
|
||||
System.out.println("Please enter a package name (for instance: com.example):");
|
||||
package_name = System.console().readLine();
|
||||
} else {
|
||||
System.out.println("Using package name: " + package_name);
|
||||
}
|
||||
|
||||
if (project_name == null || project_name.isEmpty()) {
|
||||
System.out.println("Please enter a project name (for instance: myapp):");
|
||||
project_name = System.console().readLine();
|
||||
} else {
|
||||
System.out.println("Using project name: " + project_name);
|
||||
}
|
||||
|
||||
return create_operation.workDirectory(new File(System.getProperty("user.dir")))
|
||||
.packageName(package_name)
|
||||
.projectName(project_name)
|
||||
.downloadDependencies(true);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue