Browse Source

`fnm exec`: Don't require double-dash (#398)

remotes/origin/add-with-shims
Gal Schlezinger 4 years ago committed by GitHub
parent
commit
ea42957a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/cli.rs
  2. 13
      src/commands/exec.rs

2
src/cli.rs

@ -54,7 +54,7 @@ pub enum SubCommand { @@ -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),

13
src/commands/exec.rs

@ -11,14 +11,15 @@ use std::process::{Command, Stdio}; @@ -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<String>,
#[structopt(long = "using")]
version: Option<UserVersion>,
/// Deprecated. This is the default now.
#[structopt(long = "using-file", hidden = true)]
using_file: bool,
/// The command to run
arguments: Vec<String>,
}
impl Cmd for Exec {
@ -29,6 +30,8 @@ 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 { @@ -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 { @@ -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,
}

Loading…
Cancel
Save