diff --git a/crates/turborepo-lib/src/cli.rs b/crates/turborepo-lib/src/cli.rs index 0d7b992c9b58f..0e0924c25fb34 100644 --- a/crates/turborepo-lib/src/cli.rs +++ b/crates/turborepo-lib/src/cli.rs @@ -264,11 +264,13 @@ pub enum Command { #[clap(long, value_enum, default_value_t = LinkTarget::RemoteCache)] target: LinkTarget, }, - // Generate a new app / package + /// Generate a new app / package G { + #[clap(long, default_value_t = String::from("latest"), hide = true)] + tag: String, #[clap(subcommand)] #[serde(flatten)] - command: Option, + command: GenerateCommand, }, /// Login to your Vercel account Login { @@ -307,7 +309,6 @@ pub enum Command { } #[derive(Parser, Clone, Debug, Default, Serialize, PartialEq)] -#[serde(rename_all = "camelCase")] pub struct GenerateArgs { /// The name of the generator to run pub generator_name: Option, @@ -317,13 +318,12 @@ pub struct GenerateArgs { /// The root of your repository (default: directory with root turbo.json) #[clap(short = 'r', long)] pub root: Option, - /// Arguments passed directly to generator - #[clap(short = 'a', long)] + /// Answers passed directly to generator + #[clap(short = 'a', long, value_delimiter = ' ', num_args = 1..)] pub args: Vec, } #[derive(Parser, Clone, Debug, Default, Serialize, PartialEq)] -#[serde(rename_all = "camelCase")] pub struct GenerateAddArgs { /// Name for the new workspace #[clap(short = 'n', long)] @@ -369,7 +369,7 @@ pub enum GenerateCommand { #[clap(name = "add", aliases = &["a"])] Add(GenerateAddArgs), /// Run custom generators - #[clap(name = "gen", aliases = &["g"])] + #[clap(name = "generate", aliases = &["g", "gen"])] Gen(GenerateArgs), } @@ -640,12 +640,8 @@ pub async fn run( Ok(Payload::Rust(Ok(0))) } - Command::G { command } => { - match command { - Some(command) => generate::run(command), - None => generate::run(&GenerateCommand::Add(GenerateAddArgs::default())), - }?; - + Command::G { command, tag } => { + generate::run(command, tag)?; Ok(Payload::Rust(Ok(0))) } Command::Daemon { command, idle_time } => { diff --git a/crates/turborepo-lib/src/commands/generate.rs b/crates/turborepo-lib/src/commands/generate.rs index 125b671751e2f..8449044b57a1e 100644 --- a/crates/turborepo-lib/src/commands/generate.rs +++ b/crates/turborepo-lib/src/commands/generate.rs @@ -25,10 +25,10 @@ fn verify_requirements() -> Result<()> { } } -fn call_turbo_gen(command: &str, raw_args: &str) -> Result { +fn call_turbo_gen(command: &str, tag: &String, raw_args: &str) -> Result { let mut npx = Command::new("npx"); npx.arg("--yes") - .arg("@turbo/gen@latest") + .arg(format!("@turbo/gen@{}", tag)) .arg("raw") .arg(command) .args(["--json", raw_args]) @@ -40,7 +40,7 @@ fn call_turbo_gen(command: &str, raw_args: &str) -> Result { Ok(exit_code) } -pub fn run(command: &GenerateCommand) -> Result<()> { +pub fn run(command: &GenerateCommand, tag: &String) -> Result<()> { // ensure npx is available verify_requirements()?; @@ -48,11 +48,12 @@ pub fn run(command: &GenerateCommand) -> Result<()> { GenerateCommand::Add(args) => { // convert args to json let raw_args = serde_json::to_string(args)?; - call_turbo_gen("add", &raw_args)?; + call_turbo_gen("add", tag, &raw_args)?; } GenerateCommand::Gen(args) => { let raw_args = serde_json::to_string(args)?; - call_turbo_gen("generate", &raw_args)?; + println!("{:?}", raw_args); + call_turbo_gen("generate", tag, &raw_args)?; } };