Skip to content

Commit

Permalink
feature: expose --help from rails
Browse files Browse the repository at this point in the history
  • Loading branch information
onshi committed Mar 27, 2024
1 parent 7ea800a commit 9fb6637
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/docker_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,10 +34,21 @@ 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 => {
let status = DockerClient::run_image(&ruby_version, &rails_version, cli.args)
.status()
.expect("Failed to execute process");

assert!(status.success());
}
}
}
13 changes: 11 additions & 2 deletions src/rails_new.rs
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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<Commands>,
}

#[derive(Subcommand)]
pub enum Commands {
/// Prints `rails --help`
RailsHelp {},
}

#[test]
Expand Down

0 comments on commit 9fb6637

Please sign in to comment.