Skip to content

Commit

Permalink
feat(workspace): initialize a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorin committed Apr 21, 2023
1 parent 394e53e commit 5e93ecb
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 135 deletions.
25 changes: 22 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::str::FromStr;
use log::LevelFilter;

use crate::cli::build_cli;
use crate::cmd::execute_diagram_generate;
use crate::cmd::execute_library_generate;
use crate::cmd::{execute_completion, execute_library_schema};
use crate::cmd::{
execute_completion, execute_diagram_generate, execute_library_generate, execute_library_schema,
execute_workspace_init,
};

pub fn start_app<I, T>(args: I) -> i32
where
Expand Down Expand Up @@ -70,6 +71,24 @@ where
2
}
},
Some(("workspace", m)) => match m.subcommand() {
Some(("init", m)) => {
return match execute_workspace_init(m) {
Ok(_) => 0,
Err(e) => {
log::error!("the command failed: {}", e);
2
}
};
}
_ => {
log::warn!("the SUBCOMMAND is missing");
app.write_help(&mut io::stderr())
.expect("unable to write help message");
eprintln!();
2
}
},
Some(("diagram", m)) => match m.subcommand() {
Some(("generate", m)) => {
return match execute_diagram_generate(m) {
Expand Down
260 changes: 143 additions & 117 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ use clap::{
use clap_complete::Shell;

pub fn build_cli() -> Command {
let arg_source_directory: Arg = Arg::new("source_directory")
.short('s')
.long("source")
.default_value(".")
.action(ArgAction::Set)
.num_args(1)
.env("PLANTUML_GENERATOR_SOURCE_DIRECTORY")
.help("The directory where the .puml will be discovered.");

let arg_cache_directory: Arg = Arg::new("cache_directory")
.short('C')
.long("cache")
Expand Down Expand Up @@ -47,6 +56,133 @@ pub fn build_cli() -> Command {
.env("PLANTUML_GENERATOR_INKSCAPE_BINARY")
.help("The inkscape binary path or command line.");

let arg_workspace_manifest = Arg::new("workspace_manifest")
.short('w')
.long("manifest")
.action(ArgAction::Set)
.num_args(1)
.env("PLANTUML_GENERATOR_WORKSPACE_MANIFEST")
.help("The manifest of the workspace.");

let command_library = Command::new("library")
.about("Manage libraries")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("generate")
.about("Generate a library from a manifest.")
.arg(Arg::new("MANIFEST")
.index(1)
.required(true)
.action(ArgAction::Set)
.num_args(1)
.help("The manifest of the library.")
)
.arg(Arg::new("output_directory")
.short('O')
.long("output")
.env("PLANTUML_GENERATOR_OUTPUT_DIRECTORY")
.action(ArgAction::Set)
.num_args(1)
.help("The output directory.")
)
.arg(Arg::new("urns")
.help("Handle only artifacts included in the URN.")
.short('u')
.long("urn")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(ValueParser::string())
)
.arg(Arg::new("do_clean_cache")
.long("clean-cache")
.action(ArgAction::SetTrue)
.help("Delete the cache directory before the generation-"))
.arg(Arg::new("urns_to_clean")
.help("Delete the given URN in the output directory before the generation.")
.long("clean-urn")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(ValueParser::string())
)
.arg(Arg::new("cleanup_scopes")
.help("The scopes to cleanup before the generation.")
.long_help("By default, artifacts which are already generated won't be generated again. The cleanup-scope option helps to target artifacts which will be re-generated.")
.short('c')
.long("cleanup-scope")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new([
"All",
"Example",
"Item",
"ItemIcon",
"ItemSource",
"Snippet",
"SnippetSource",
"SnippetImage",
"Sprite",
"SpriteIcon",
"SpriteValue",
]))
)
.arg(&arg_cache_directory)
.arg(&arg_plantuml_version)
.arg(&arg_plantuml_jar)
.arg(&arg_java_binary)
.arg(&arg_inkscape_binary),
)
.subcommand(
Command::new("schema")
.about("Generate the JSON Schema of the library manifest.")
);

let command_workspace = Command::new("workspace")
.about("Manage workspaces")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("init")
.about("Initialize a workspace")
.arg(&arg_workspace_manifest)
.arg(&arg_source_directory)
.arg(&arg_cache_directory),
);

let command_diagram = Command::new("diagram")
.about("Manage diagrams")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("generate")
.about("Generate discovered .puml files which has been mutated since the last generation.")
.arg(&arg_source_directory)
.arg(Arg::new("do_force_generation")
.short('f')
.long("force")
.help("Force the rendering of discovered .puml file."))
.arg(&arg_cache_directory)
.arg(&arg_plantuml_version)
.arg(&arg_plantuml_jar)
.arg(&arg_java_binary)
);

let command_completion = Command::new("completion")
.about("Generate resources for autocompletion")
.arg_required_else_help(true)
.arg(
Arg::new("SHELL")
.help("set the shell")
.index(1)
.action(ArgAction::Set)
.num_args(1)
.required(true)
.value_parser(value_parser!(Shell)),
);

Command::new("plantuml-generator")
.version(crate_version!())
.author(crate_authors!())
Expand All @@ -60,123 +196,13 @@ pub fn build_cli() -> Command {
.action(ArgAction::Set)
.num_args(1)
.default_value("Info")
.value_parser(PossibleValuesParser::new(["Off", "Trace", "Debug", "Info", "Warn", "Error"]))
.value_parser(PossibleValuesParser::new([
"Off", "Trace", "Debug", "Info", "Warn", "Error",
]))
.help("Set the verbosity of the logs."),
)
.subcommand(
Command::new("library")
.about("Manage libraries")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("generate")
.about("Generate a library from a manifest.")
.arg(Arg::new("MANIFEST")
.index(1)
.required(true)
.action(ArgAction::Set)
.num_args(1)
.help("The manifest of the library.")
)
.arg(Arg::new("output_directory")
.short('O')
.long("output")
.env("PLANTUML_GENERATOR_OUTPUT_DIRECTORY")
.action(ArgAction::Set)
.num_args(1)
.help("The output directory.")
)
.arg(Arg::new("urns")
.help("Handle only artifacts included in the URN.")
.short('u')
.long("urn")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(ValueParser::string())
)
.arg(Arg::new("do_clean_cache")
.long("clean-cache")
.action(ArgAction::SetTrue)
.help("Delete the cache directory before the generation-"))
.arg(Arg::new("urns_to_clean")
.help("Delete the given URN in the output directory before the generation.")
.long("clean-urn")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(ValueParser::string())
)
.arg(Arg::new("cleanup_scopes")
.help("The scopes to cleanup before the generation.")
.long_help("By default, artifacts which are already generated won't be generated again. The cleanup-scope option helps to target artifacts which will be re-generated.")
.short('c')
.long("cleanup-scope")
.action(ArgAction::Set)
.num_args(1)
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new([
"All",
"Example",
"Item",
"ItemIcon",
"ItemSource",
"Snippet",
"SnippetSource",
"SnippetImage",
"Sprite",
"SpriteIcon",
"SpriteValue",
]))
)
.arg(&arg_cache_directory)
.arg(&arg_plantuml_version)
.arg(&arg_plantuml_jar)
.arg(&arg_java_binary)
.arg(&arg_inkscape_binary),
)
.subcommand(
Command::new("schema").about("Generate the JSON Schema of the library manifest.")
),

)
.subcommand(
Command::new("diagram")
.about("Manage diagrams")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Command::new("generate")
.about("Generate discovered .puml files which has been mutated since the last generation.")
.arg(Arg::new("source_directory")
.short('s')
.long("source")
.default_value(".")
.action(ArgAction::Set)
.num_args(1)
.env("PLANTUML_GENERATOR_SOURCE_DIRECTORY")
.help("The directory where the .puml will be discovered."))
.arg(Arg::new("do_force_generation")
.short('f')
.long("force")
.help("Force the rendering of discovered .puml file."))
.arg(&arg_cache_directory)
.arg(&arg_plantuml_version)
.arg(&arg_plantuml_jar)
.arg(&arg_java_binary)
),
)
.subcommand(Command::new("completion")
.about("Generate resources for autocompletion")
.arg_required_else_help(true)
.arg(
Arg::new("SHELL")
.help("set the shell")
.index(1)
.action(ArgAction::Set)
.num_args(1)
.required(true)
.value_parser(value_parser!(Shell))
)
)
.subcommand(command_library)
.subcommand(command_workspace)
.subcommand(command_diagram)
.subcommand(command_completion)
}
6 changes: 3 additions & 3 deletions src/cmd/library/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod test {
fn test_urns() {
delete_file_or_directory("target/tests/cmd/library/generate/urns/distribution".as_ref())
.unwrap();
let arg_matches = build_cli().get_matches_from(&[
let arg_matches = build_cli().get_matches_from([
"plantuml-generator",
"-l=Off",
"library",
Expand Down Expand Up @@ -146,7 +146,7 @@ mod test {
Path::new("target/tests/cmd/library/generate/clean_cache/cache/a_package");
create_dir_all(path_in_cache).unwrap();
assert!(path_in_cache.exists());
let arg_matches = build_cli().get_matches_from(&[
let arg_matches = build_cli().get_matches_from([
"plantuml-generator",
"-l=Off",
"library",
Expand Down Expand Up @@ -175,7 +175,7 @@ mod test {
);
create_dir_all(path_in_output).unwrap();
assert!(path_in_output.exists());
let arg_matches = build_cli().get_matches_from(&[
let arg_matches = build_cli().get_matches_from([
"plantuml-generator",
"-l=Off",
"library",
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/library/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod test {
#[test]
fn test_generation() {
let arg_matches =
build_cli().get_matches_from(&["plantuml-generator", "-l=Off", "library", "schema"]);
build_cli().get_matches_from(["plantuml-generator", "-l=Off", "library", "schema"]);
execute_library_schema(
arg_matches
.subcommand_matches("library")
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ pub use self::completion::execute_completion;
pub use self::diagram::execute_diagram_generate;
pub use self::library::execute_library_generate;
pub use self::library::execute_library_schema;
pub use self::workspace::execute_workspace_init;

mod completion;
mod diagram;
mod library;
mod workspace;
Loading

0 comments on commit 5e93ecb

Please sign in to comment.