Browse Source

Allow `fnm use` to use a file path (#403)

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

9
src/commands/exec.rs

@ -1,12 +1,11 @@
use super::command::Command as Cmd; use super::command::Command as Cmd;
use crate::choose_version_for_user_input::Error as UserInputError; use crate::choose_version_for_user_input::{
choose_version_for_user_input, Error as UserInputError,
};
use crate::config::FnmConfig; use crate::config::FnmConfig;
use crate::outln; use crate::outln;
use crate::user_version::UserVersion; use crate::user_version::UserVersion;
use crate::{ use crate::user_version_reader::UserVersionReader;
choose_version_for_user_input::choose_version_for_user_input,
user_version_reader::UserVersionReader,
};
use colored::Colorize; use colored::Colorize;
use snafu::{OptionExt, ResultExt, Snafu}; use snafu::{OptionExt, ResultExt, Snafu};
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};

12
src/commands/use.rs

@ -1,20 +1,19 @@
use super::command::Command; use super::command::Command;
use super::install::Install; use super::install::Install;
use crate::config::FnmConfig;
use crate::fs; use crate::fs;
use crate::installed_versions; use crate::installed_versions;
use crate::outln; use crate::outln;
use crate::system_version; use crate::system_version;
use crate::user_version::UserVersion; use crate::user_version::UserVersion;
use crate::version::Version; use crate::version::Version;
use crate::version_files::get_user_version_for_directory; use crate::{config::FnmConfig, user_version_reader::UserVersionReader};
use colored::Colorize; use colored::Colorize;
use snafu::{ensure, OptionExt, ResultExt, Snafu}; use snafu::{ensure, OptionExt, ResultExt, Snafu};
use structopt::StructOpt; use structopt::StructOpt;
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
pub struct Use { pub struct Use {
version: Option<UserVersion>, version: Option<UserVersionReader>,
/// Install the version if it isn't installed yet /// Install the version if it isn't installed yet
#[structopt(long)] #[structopt(long)]
install_if_missing: bool, install_if_missing: bool,
@ -31,10 +30,11 @@ impl Command for Use {
installed_versions::list(config.installations_dir()).context(VersionListingError)?; installed_versions::list(config.installations_dir()).context(VersionListingError)?;
let requested_version = self let requested_version = self
.version .version
.or_else(|| { .unwrap_or_else(|| {
let current_dir = std::env::current_dir().unwrap(); let current_dir = std::env::current_dir().unwrap();
get_user_version_for_directory(current_dir) UserVersionReader::Path(current_dir)
}) })
.to_user_version()
.context(CantInferVersion)?; .context(CantInferVersion)?;
let version_path = if let UserVersion::Full(Version::Bypassed) = requested_version { let version_path = if let UserVersion::Full(Version::Bypassed) = requested_version {
@ -76,7 +76,7 @@ impl Command for Use {
.context(InstallError)?; .context(InstallError)?;
Self { Self {
version: Some(requested_version), version: Some(UserVersionReader::Direct(requested_version)),
install_if_missing: self.install_if_missing, install_if_missing: self.install_if_missing,
} }
.apply(config)?; .apply(config)?;

Loading…
Cancel
Save