From ea42957a5f403aef8494c3542435bccdf5420ba0 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Mon, 22 Feb 2021 17:02:54 +0200 Subject: [PATCH] `fnm exec`: Don't require double-dash (#398) --- src/cli.rs | 2 +- src/commands/exec.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 384925d..7707537 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -54,7 +54,7 @@ pub enum SubCommand { /// /// Example: /// -------- - /// fnm exec --using=v12.0.0 -- node --version + /// fnm exec --using=v12.0.0 node --version /// => v12.0.0 #[structopt(name = "exec")] Exec(commands::exec::Exec), diff --git a/src/commands/exec.rs b/src/commands/exec.rs index 75e63e7..8095476 100644 --- a/src/commands/exec.rs +++ b/src/commands/exec.rs @@ -11,14 +11,15 @@ use std::process::{Command, Stdio}; use structopt::StructOpt; #[derive(Debug, StructOpt)] +#[structopt(setting = structopt::clap::AppSettings::TrailingVarArg)] pub struct Exec { - binary: String, - arguments: Vec, #[structopt(long = "using")] version: Option, /// Deprecated. This is the default now. #[structopt(long = "using-file", hidden = true)] using_file: bool, + /// The command to run + arguments: Vec, } impl Cmd for Exec { @@ -29,6 +30,8 @@ impl Cmd for Exec { outln!(config#Error, "{} {} is deprecated. This is now the default.", "warning:".yellow().bold(), "--using-file".italic()); } + let (binary, arguments) = self.arguments.split_first().context(NoBinaryProvided)?; + let version = self .version .or_else(|| { @@ -54,8 +57,8 @@ impl Cmd for Exec { std::env::join_paths(paths).context(CantAddPathToEnvironment)? }; - let exit_status = Command::new(&self.binary) - .args(self.arguments) + let exit_status = Command::new(&binary) + .args(arguments) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -88,4 +91,6 @@ pub enum Error { ApplicableVersionError { source: UserInputError, }, + #[snafu(display("command not provided. Please provide a command to run as an argument, like {} or {}.\n{} {}", "node".italic(), "bash".italic(), "example:".yellow().bold(), "fnm exec --using=12 node --version".italic().yellow()))] + NoBinaryProvided, }