From a1402b8dd198f9d24ea3425eb829354ad01a68cc Mon Sep 17 00:00:00 2001 From: Jan Makara Date: Wed, 27 Mar 2024 02:33:41 +0100 Subject: [PATCH] feature: expose `--help` from rails --- src/docker_client.rs | 14 ++++++++++++++ src/main.rs | 26 +++++++++++++++++++------- src/rails_new.rs | 13 +++++++++++-- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/docker_client.rs b/src/docker_client.rs index 84188e9..8520084 100644 --- a/src/docker_client.rs +++ b/src/docker_client.rs @@ -40,4 +40,18 @@ impl DockerClient { command } + + pub fn get_help(ruby_version: &str, rails_version: &str) -> Command { + let mut command = Command::new("docker"); + + command + .arg("run") + .arg("--rm") + .arg(format!("rails-new-{}-{}", ruby_version, rails_version)) + .arg("rails") + .arg("new") + .arg("--help"); + + command + } } diff --git a/src/main.rs b/src/main.rs index 91084e9..50d313d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ // use std::process::Command; mod docker_client; mod rails_new; -use rails_new::Cli; +use rails_new::{Cli, Commands}; use std::io::Write; use clap::Parser; @@ -34,10 +34,22 @@ fn main() { assert!(status.success()); - // Run the image with docker run -v $(pwd):/$(pwd) -w $(pwd) rails-new-$RUBY_VERSION-$RAILS_VERSION rails new $@ - let status = DockerClient::run_image(&ruby_version, &rails_version, cli.args) - .status() - .expect("Failed to execute process"); - - assert!(status.success()); + match &cli.command { + Some(Commands::RailsHelp {}) => { + let mut child = DockerClient::get_help(&ruby_version, &rails_version) + .spawn() + .expect("Failed to execute process"); + let status = child.wait().expect("failed to wait on child"); + assert!(status.success()); + } + + None => { + // Run the image with docker run -v $(pwd):/$(pwd) -w $(pwd) rails-new-$RUBY_VERSION-$RAILS_VERSION rails new $@ + let status = DockerClient::run_image(&ruby_version, &rails_version, cli.args) + .status() + .expect("Failed to execute process"); + + assert!(status.success()); + } + } } diff --git a/src/rails_new.rs b/src/rails_new.rs index b0ca823..919b700 100644 --- a/src/rails_new.rs +++ b/src/rails_new.rs @@ -1,7 +1,7 @@ -use clap::Parser; +use clap::{Parser, Subcommand}; #[derive(Parser)] -#[command(version, about, long_about = None)] +#[command(version, about, long_about = None, subcommand_negates_reqs = true)] pub struct Cli { #[clap(trailing_var_arg = true, required = true)] /// arguments passed to `rails new` @@ -10,6 +10,15 @@ pub struct Cli { pub ruby_version: String, #[clap(long, short = 'r', default_value = "7.1.3")] pub rails_version: String, + + #[command(subcommand)] + pub command: Option, +} + +#[derive(Subcommand)] +pub enum Commands { + /// Prints `rails --help` + RailsHelp {}, } #[test]