diff --git a/crates/notion-core/src/catalog.rs b/crates/notion-core/src/catalog.rs index 4c8c5b273..b70a50152 100644 --- a/crates/notion-core/src/catalog.rs +++ b/crates/notion-core/src/catalog.rs @@ -19,9 +19,9 @@ use tempfile::NamedTempFile; use toml; use config::{Config, ToolConfig}; -use installer::node::NodeInstaller; -use installer::yarn::YarnInstaller; -use installer::{Install, Installed}; +use distro::node::NodeDistro; +use distro::yarn::YarnDistro; +use distro::{Distro, Fetched}; use notion_fail::{Fallible, NotionError, NotionFail, ResultExt}; use path::{self, user_catalog_file}; use semver::{Version, VersionReq}; @@ -60,18 +60,18 @@ impl LazyCatalog { } } -pub struct Collection { +pub struct Collection { /// The currently activated Node version, if any. pub default: Option, // A sorted collection of the available versions in the catalog. pub versions: BTreeSet, - pub phantom: PhantomData, + pub phantom: PhantomData, } -pub type NodeCollection = Collection; -pub type YarnCollection = Collection; +pub type NodeCollection = Collection; +pub type YarnCollection = Collection; /// The catalog of tool versions available locally. pub struct Catalog { @@ -102,8 +102,8 @@ impl Catalog { /// Sets the default Node version to one matching the specified semantic versioning requirements. pub fn set_default_node(&mut self, matching: &VersionReq, config: &Config) -> Fallible<()> { - let installed = self.install_node(matching, config)?; - let version = Some(installed.into_version()); + let fetched = self.fetch_node(matching, config)?; + let version = Some(fetched.into_version()); if self.node.default != version { self.node.default = version; @@ -113,17 +113,17 @@ impl Catalog { Ok(()) } - /// Installs a Node version matching the specified semantic versioning requirements. - pub fn install_node(&mut self, matching: &VersionReq, config: &Config) -> Fallible { - let installer = self.node.resolve_remote(&matching, config.node.as_ref())?; - let installed = installer.install(&self.node).unknown()?; + /// Fetches a Node version matching the specified semantic versioning requirements. + pub fn fetch_node(&mut self, matching: &VersionReq, config: &Config) -> Fallible { + let distro = self.node.resolve_remote(&matching, config.node.as_ref())?; + let fetched = distro.fetch(&self.node).unknown()?; - if let &Installed::Now(ref version) = &installed { + if let &Fetched::Now(ref version) = &fetched { self.node.versions.insert(version.clone()); self.save()?; } - Ok(installed) + Ok(fetched) } /// Uninstalls a specific Node version from the local catalog. @@ -152,8 +152,8 @@ impl Catalog { // And potentially share code between node and yarn /// Sets the default Yarn version to one matching the specified semantic versioning requirements. pub fn set_default_yarn(&mut self, matching: &VersionReq, config: &Config) -> Fallible<()> { - let installed = self.install_yarn(matching, config)?; - let version = Some(installed.into_version()); + let fetched = self.fetch_yarn(matching, config)?; + let version = Some(fetched.into_version()); if self.yarn.default != version { self.yarn.default = version; @@ -163,17 +163,17 @@ impl Catalog { Ok(()) } - /// Installs a Yarn version matching the specified semantic versioning requirements. - pub fn install_yarn(&mut self, matching: &VersionReq, config: &Config) -> Fallible { - let installer = self.yarn.resolve_remote(&matching, config.yarn.as_ref())?; - let installed = installer.install(&self.yarn).unknown()?; + /// Fetches a Yarn version matching the specified semantic versioning requirements. + pub fn fetch_yarn(&mut self, matching: &VersionReq, config: &Config) -> Fallible { + let distro = self.yarn.resolve_remote(&matching, config.yarn.as_ref())?; + let fetched = distro.fetch(&self.yarn).unknown()?; - if let &Installed::Now(ref version) = &installed { + if let &Fetched::Now(ref version) = &fetched { self.yarn.versions.insert(version.clone()); self.save()?; } - Ok(installed) + Ok(fetched) } /// Uninstalls a specific Yarn version from the local catalog. @@ -229,7 +229,7 @@ impl NotionFail for NoYarnVersionFoundError { } } -impl Collection { +impl Collection { /// Tests whether this Collection contains the specified Tool version. pub fn contains(&self, version: &Version) -> bool { self.versions.contains(version) @@ -246,9 +246,9 @@ impl Collection { } } -pub trait Resolve { +pub trait Resolve { /// Resolves the specified semantic versioning requirements from a remote distributor. - fn resolve_remote(&self, matching: &VersionReq, config: Option<&ToolConfig>) -> Fallible { + fn resolve_remote(&self, matching: &VersionReq, config: Option<&ToolConfig>) -> Fallible { match config { Some(ToolConfig { resolve: Some(ref plugin), @@ -259,7 +259,7 @@ pub trait Resolve { } /// Resolves the specified semantic versioning requirements from the public distributor (e.g. `https://nodejs.org`). - fn resolve_public(&self, matching: &VersionReq) -> Fallible; + fn resolve_public(&self, matching: &VersionReq) -> Fallible; } /// Thrown when the public registry for Node or Yarn could not be downloaded. @@ -286,8 +286,8 @@ impl NotionFail for RegistryFetchError { } } -impl Resolve for NodeCollection { - fn resolve_public(&self, matching: &VersionReq) -> Fallible { +impl Resolve for NodeCollection { + fn resolve_public(&self, matching: &VersionReq) -> Fallible { let index: Index = match read_cached_opt().unknown()? { Some(serial) => serial, None => { @@ -341,7 +341,7 @@ impl Resolve for NodeCollection { .next() .map(|(k, _)| k.clone()); if let Some(version) = version { - NodeInstaller::public(version) + NodeDistro::public(version) } else { throw!(NoNodeVersionFoundError { matching: matching.clone(), @@ -350,9 +350,9 @@ impl Resolve for NodeCollection { } } -impl Resolve for YarnCollection { +impl Resolve for YarnCollection { /// Resolves the specified semantic versioning requirements from the public distributor. - fn resolve_public(&self, matching: &VersionReq) -> Fallible { + fn resolve_public(&self, matching: &VersionReq) -> Fallible { let spinner = progress_spinner(&format!( "Fetching public registry: {}", PUBLIC_YARN_VERSION_INDEX @@ -369,7 +369,7 @@ impl Resolve for YarnCollection { if let Some(matching_version) = matching_version { let version = Version::parse(&matching_version).unwrap(); - YarnInstaller::public(version) + YarnDistro::public(version) } else { throw!(NoYarnVersionFoundError { matching: matching.clone(), diff --git a/crates/notion-core/src/config.rs b/crates/notion-core/src/config.rs index 18ce93cda..353ded208 100644 --- a/crates/notion-core/src/config.rs +++ b/crates/notion-core/src/config.rs @@ -6,9 +6,9 @@ use std::str::FromStr; use lazycell::LazyCell; use toml; -use installer::Install; -use installer::node::NodeInstaller; -use installer::yarn::YarnInstaller; +use distro::Distro; +use distro::node::NodeDistro; +use distro::yarn::YarnDistro; use notion_fail::{Fallible, NotionError, ResultExt}; use path::user_config_file; use plugin; @@ -37,18 +37,18 @@ impl LazyConfig { /// Notion configuration settings. pub struct Config { - pub node: Option>, - pub yarn: Option>, + pub node: Option>, + pub yarn: Option>, } /// Notion configuration settings relating to the Node executable. -pub struct ToolConfig { +pub struct ToolConfig { /// The plugin for resolving Node versions, if any. pub resolve: Option, /// The plugin for listing the set of Node versions available on the remote server, if any. pub ls_remote: Option, - pub phantom: PhantomData, + pub phantom: PhantomData, } impl Config { diff --git a/crates/notion-core/src/installer/error.rs b/crates/notion-core/src/distro/error.rs similarity index 100% rename from crates/notion-core/src/installer/error.rs rename to crates/notion-core/src/distro/error.rs diff --git a/crates/notion-core/src/installer/mod.rs b/crates/notion-core/src/distro/mod.rs similarity index 53% rename from crates/notion-core/src/installer/mod.rs rename to crates/notion-core/src/distro/mod.rs index f3bdc24ee..004a3c43e 100644 --- a/crates/notion-core/src/installer/mod.rs +++ b/crates/notion-core/src/distro/mod.rs @@ -1,4 +1,4 @@ -//! Provides types for installing tools into the Notion catalog. +//! Provides types for fetching tool distributions into the Notion catalog. mod error; pub mod node; @@ -10,43 +10,43 @@ use semver::Version; use std::fs::File; /// The result of a requested installation. -pub enum Installed { +pub enum Fetched { /// Indicates that the given tool was already installed. Already(Version), /// Indicates that the given tool was not already installed but has now been installed. Now(Version), } -impl Installed { +impl Fetched { /// Consumes this value and produces the installed version. pub fn into_version(self) -> Version { match self { - Installed::Already(version) | Installed::Now(version) => version, + Fetched::Already(version) | Fetched::Now(version) => version, } } /// Produces a reference to the installed version. pub fn version(&self) -> &Version { match self { - &Installed::Already(ref version) | &Installed::Now(ref version) => version, + &Fetched::Already(ref version) | &Fetched::Now(ref version) => version, } } } -pub trait Install: Sized { - /// Provision an `Installer` from the public distributor (e.g. `https://nodejs.org`). +pub trait Distro: Sized { + /// Provision a distribution from the public distributor (e.g. `https://nodejs.org`). fn public(version: Version) -> Fallible; - /// Provision an `Installer` from a remote distributor. + /// Provision a distribution from a remote distributor. fn remote(version: Version, url: &str) -> Fallible; - /// Provision an `Installer` from the filesystem. + /// Provision a distribution from the filesystem. fn cached(version: Version, file: File) -> Fallible; - /// Produces a reference to this installer's Tool version. + /// Produces a reference to this distro's Tool version. fn version(&self) -> &Version; - /// Installs this version of the Tool. (It is left to the responsibility of the `Collection` - /// to update its state after installation succeeds.) - fn install(self, catalog: &Collection) -> Fallible; + /// Fetches this version of the Tool. (It is left to the responsibility of the `Collection` + /// to update its state after fetching succeeds.) + fn fetch(self, catalog: &Collection) -> Fallible; } diff --git a/crates/notion-core/src/installer/node.rs b/crates/notion-core/src/distro/node.rs similarity index 68% rename from crates/notion-core/src/installer/node.rs rename to crates/notion-core/src/distro/node.rs index 16ad830fd..0a4e33dd8 100644 --- a/crates/notion-core/src/installer/node.rs +++ b/crates/notion-core/src/distro/node.rs @@ -3,9 +3,9 @@ use std::fs::{rename, File}; use std::string::ToString; -use super::{Install, Installed}; +use super::{Distro, Fetched}; use catalog::NodeCollection; -use installer::error::DownloadError; +use distro::error::DownloadError; use node_archive::{self, Archive}; use path; use style::{progress_bar, Action}; @@ -15,54 +15,54 @@ use semver::Version; const PUBLIC_NODE_SERVER_ROOT: &'static str = "https://nodejs.org/dist/"; -/// A provisioned Node installer. -pub struct NodeInstaller { +/// A provisioned Node distribution. +pub struct NodeDistro { archive: Box, version: Version, } -impl Install for NodeInstaller { - /// Provision an `Installer` from the public Node distributor (`https://nodejs.org`). +impl Distro for NodeDistro { + /// Provision a Node distribution from the public Node distributor (`https://nodejs.org`). fn public(version: Version) -> Fallible { let archive_file = path::node_archive_file(&version.to_string()); let url = format!("{}v{}/{}", PUBLIC_NODE_SERVER_ROOT, version, &archive_file); - NodeInstaller::remote(version, &url) + NodeDistro::remote(version, &url) } - /// Provision an `Installer` from a remote distributor. + /// Provision a Node distribution from a remote distributor. fn remote(version: Version, url: &str) -> Fallible { let archive_file = path::node_archive_file(&version.to_string()); let cache_file = path::node_cache_dir()?.join(&archive_file); if cache_file.is_file() { - return NodeInstaller::cached(version, File::open(cache_file).unknown()?); + return NodeDistro::cached(version, File::open(cache_file).unknown()?); } - Ok(NodeInstaller { + Ok(NodeDistro { archive: node_archive::fetch(url, &cache_file) .with_context(DownloadError::for_version(version.to_string()))?, version: version, }) } - /// Provision an `Installer` from the filesystem. + /// Provision a Node distribution from the filesystem. fn cached(version: Version, file: File) -> Fallible { - Ok(NodeInstaller { + Ok(NodeDistro { archive: node_archive::load(file).unknown()?, version: version, }) } - /// Produces a reference to this installer's Node version. + /// Produces a reference to this distribution's Node version. fn version(&self) -> &Version { &self.version } - /// Installs this version of Node. (It is left to the responsibility of the `NodeCollection` - /// to update its state after installation succeeds.) - fn install(self, collection: &NodeCollection) -> Fallible { + /// Fetches this version of Node. (It is left to the responsibility of the `NodeCollection` + /// to update its state after fetching succeeds.) + fn fetch(self, collection: &NodeCollection) -> Fallible { if collection.contains(&self.version) { - return Ok(Installed::Already(self.version)); + return Ok(Fetched::Already(self.version)); } let dest = path::node_versions_dir()?; @@ -87,6 +87,6 @@ impl Install for NodeInstaller { ).unknown()?; bar.finish_and_clear(); - Ok(Installed::Now(self.version)) + Ok(Fetched::Now(self.version)) } } diff --git a/crates/notion-core/src/installer/yarn.rs b/crates/notion-core/src/distro/yarn.rs similarity index 69% rename from crates/notion-core/src/installer/yarn.rs rename to crates/notion-core/src/distro/yarn.rs index 4212bac3b..e77c0b4a0 100644 --- a/crates/notion-core/src/installer/yarn.rs +++ b/crates/notion-core/src/distro/yarn.rs @@ -3,9 +3,9 @@ use std::fs::{rename, File}; use std::string::ToString; -use super::{Install, Installed}; +use super::{Distro, Fetched}; use catalog::YarnCollection; -use installer::error::DownloadError; +use distro::error::DownloadError; use node_archive::{self, Archive}; use path; use style::{progress_bar, Action}; @@ -16,54 +16,54 @@ use semver::Version; const PUBLIC_YARN_SERVER_ROOT: &'static str = "https://github.com/notion-cli/yarn-releases/raw/master/dist/"; -/// A provisioned Yarn installer. -pub struct YarnInstaller { +/// A provisioned Yarn distribution. +pub struct YarnDistro { archive: Box, version: Version, } -impl Install for YarnInstaller { - /// Provision an `Installer` from the public Yarn distributor (`https://yarnpkg.com`). +impl Distro for YarnDistro { + /// Provision a distribution from the public Yarn distributor (`https://yarnpkg.com`). fn public(version: Version) -> Fallible { let archive_file = path::yarn_archive_file(&version.to_string()); let url = format!("{}{}", PUBLIC_YARN_SERVER_ROOT, archive_file); - YarnInstaller::remote(version, &url) + YarnDistro::remote(version, &url) } - /// Provision an `Installer` from a remote distributor. + /// Provision a distribution from a remote distributor. fn remote(version: Version, url: &str) -> Fallible { let archive_file = path::yarn_archive_file(&version.to_string()); let cache_file = path::yarn_cache_dir()?.join(&archive_file); if cache_file.is_file() { - return YarnInstaller::cached(version, File::open(cache_file).unknown()?); + return YarnDistro::cached(version, File::open(cache_file).unknown()?); } - Ok(YarnInstaller { + Ok(YarnDistro { archive: node_archive::fetch(url, &cache_file) .with_context(DownloadError::for_version(version.to_string()))?, version: version, }) } - /// Provision an `Installer` from the filesystem. + /// Provision a distribution from the filesystem. fn cached(version: Version, file: File) -> Fallible { - Ok(YarnInstaller { + Ok(YarnDistro { archive: node_archive::load(file).unknown()?, version: version, }) } - /// Produces a reference to this installer's Yarn version. + /// Produces a reference to this distro's Yarn version. fn version(&self) -> &Version { &self.version } - /// Installs this version of Yarn. (It is left to the responsibility of the `YarnCollection` - /// to update its state after installation succeeds.) - fn install(self, collection: &YarnCollection) -> Fallible { + /// Fetches this version of Yarn. (It is left to the responsibility of the `YarnCollection` + /// to update its state after fetching succeeds.) + fn fetch(self, collection: &YarnCollection) -> Fallible { if collection.contains(&self.version) { - return Ok(Installed::Already(self.version)); + return Ok(Fetched::Already(self.version)); } let dest = path::yarn_versions_dir()?; @@ -88,6 +88,6 @@ impl Install for YarnInstaller { ).unknown()?; bar.finish_and_clear(); - Ok(Installed::Now(self.version)) + Ok(Fetched::Now(self.version)) } } diff --git a/crates/notion-core/src/lib.rs b/crates/notion-core/src/lib.rs index d497b365e..1ee0390f7 100644 --- a/crates/notion-core/src/lib.rs +++ b/crates/notion-core/src/lib.rs @@ -25,7 +25,7 @@ pub mod catalog; pub mod config; pub mod env; mod event; -mod installer; +mod distro; pub mod manifest; pub mod monitor; mod package_info; diff --git a/crates/notion-core/src/plugin.rs b/crates/notion-core/src/plugin.rs index 7ff540e1b..49434f7fe 100644 --- a/crates/notion-core/src/plugin.rs +++ b/crates/notion-core/src/plugin.rs @@ -4,7 +4,7 @@ use std::ffi::OsString; use std::io::Read; use std::process::{Command, Stdio}; -use installer::Install; +use distro::Distro; use serial; use cmdline_words_parser::StrExt; @@ -32,7 +32,7 @@ pub struct InvalidCommandError { impl ResolvePlugin { /// Performs resolution of a Tool version based on the given semantic /// versioning requirements. - pub fn resolve(&self, _matching: &VersionReq) -> Fallible { + pub fn resolve(&self, _matching: &VersionReq) -> Fallible { match self { &ResolvePlugin::Url(_) => unimplemented!(), @@ -64,7 +64,7 @@ impl ResolvePlugin { .unknown()?; let response = ResolveResponse::from_reader(child.stdout.unwrap())?; match response { - ResolveResponse::Url { version, url } => I::remote(version, &url), + ResolveResponse::Url { version, url } => D::remote(version, &url), ResolveResponse::Stream { version: _version } => { unimplemented!("bin plugin produced a stream") } diff --git a/crates/notion-core/src/serial/config.rs b/crates/notion-core/src/serial/config.rs index f5eafda2b..f203640d6 100644 --- a/crates/notion-core/src/serial/config.rs +++ b/crates/notion-core/src/serial/config.rs @@ -2,16 +2,16 @@ use super::super::config; use std::marker::PhantomData; use super::plugin::Plugin; -use installer::Install; -use installer::node::NodeInstaller; -use installer::yarn::YarnInstaller; +use distro::Distro; +use distro::node::NodeDistro; +use distro::yarn::YarnDistro; use notion_fail::Fallible; #[derive(Serialize, Deserialize)] pub struct Config { - pub node: Option>, - pub yarn: Option>, + pub node: Option>, + pub yarn: Option>, } #[derive(Serialize, Deserialize)] @@ -43,8 +43,8 @@ impl Config { } } -impl ToolConfig { - pub fn into_tool_config(self) -> Fallible> { +impl ToolConfig { + pub fn into_tool_config(self) -> Fallible> { Ok(config::ToolConfig { resolve: if let Some(p) = self.resolve { Some(p.into_resolve()?) diff --git a/crates/notion-core/src/session.rs b/crates/notion-core/src/session.rs index 5ed7742d6..0ce169f68 100644 --- a/crates/notion-core/src/session.rs +++ b/crates/notion-core/src/session.rs @@ -6,7 +6,7 @@ use std::env::{self, VarError}; use catalog::{Catalog, LazyCatalog}; use config::{Config, LazyConfig}; -use installer::Installed; +use distro::Fetched; use project::Project; use std::fmt::{self, Display, Formatter}; use std::process::exit; @@ -17,7 +17,7 @@ use semver::{Version, VersionReq}; #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy)] pub enum ActivityKind { - Install, + Fetch, Uninstall, Current, Deactivate, @@ -36,7 +36,7 @@ pub enum ActivityKind { impl Display for ActivityKind { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { let s = match self { - &ActivityKind::Install => "install", + &ActivityKind::Fetch => "fetch", &ActivityKind::Uninstall => "uninstall", &ActivityKind::Current => "current", &ActivityKind::Deactivate => "deactivate", @@ -116,9 +116,9 @@ impl Session { } let config = self.config.get()?; - let installed = catalog.install_node(&requirements, config)?; + let fetched = catalog.fetch_node(&requirements, config)?; - return Ok(Some(installed.into_version())); + return Ok(Some(fetched.into_version())); } self.global_node() @@ -132,12 +132,12 @@ impl Session { } } - /// Installs a version of Node matching the specified semantic verisoning + /// Fetches a version of Node matching the specified semantic verisoning /// requirements. - pub fn install_node(&mut self, matching: &VersionReq) -> Fallible { + pub fn fetch_node(&mut self, matching: &VersionReq) -> Fallible { let catalog = self.catalog.get_mut()?; let config = self.config.get()?; - catalog.install_node(matching, config) + catalog.fetch_node(matching, config) } /// Sets the default Node version to one matching the specified semantic versioning @@ -164,14 +164,22 @@ impl Session { } let config = self.config.get()?; - let installed = catalog.install_yarn(&requirements, config)?; + let fetched = catalog.fetch_yarn(&requirements, config)?; - return Ok(Some(installed.into_version())); + return Ok(Some(fetched.into_version())); } Ok(self.catalog()?.yarn.default.clone()) } + /// Fetches a version of Node matching the specified semantic verisoning + /// requirements. + pub fn fetch_yarn(&mut self, matching: &VersionReq) -> Fallible { + let catalog = self.catalog.get_mut()?; + let config = self.config.get()?; + catalog.fetch_yarn(matching, config) + } + pub fn add_event_start(&mut self, activity_kind: ActivityKind) { self.event_log.add_event_start(activity_kind) } diff --git a/src/command/fetch.rs b/src/command/fetch.rs new file mode 100644 index 000000000..baa2fa9c3 --- /dev/null +++ b/src/command/fetch.rs @@ -0,0 +1,69 @@ +use semver::VersionReq; + +use notion_core::serial::version::parse_requirements; +use notion_core::session::{ActivityKind, Session}; +use notion_fail::Fallible; + +use {CliParseError, Notion}; +use command::{Command, CommandName, Help}; + +#[derive(Debug, Deserialize)] +pub(crate) struct Args { + arg_toolchain: String, + arg_version: String, +} + +pub(crate) enum Fetch { + Help, + Node(VersionReq), + Yarn(VersionReq), +} + +impl Command for Fetch { + type Args = Args; + + const USAGE: &'static str = " +Fetch a toolchain to the local machine + +Usage: + notion fetch + notion fetch -h | --help + +Options: + -h, --help Display this message +"; + + fn help() -> Self { + Fetch::Help + } + + fn parse(_: Notion, Args { arg_toolchain, arg_version }: Args) -> Fallible { + match &arg_toolchain[..] { + "node" => Ok(Fetch::Node(parse_requirements(&arg_version)?)), + "yarn" => Ok(Fetch::Yarn(parse_requirements(&arg_version)?)), + ref toolchain => { + throw!(CliParseError { + usage: None, + error: format!("no such toolchain: `{}`", toolchain), + }); + } + } + } + + fn run(self, session: &mut Session) -> Fallible { + session.add_event_start(ActivityKind::Fetch); + let result = match self { + Fetch::Help => Help::Command(CommandName::Fetch).run(session), + Fetch::Node(version) => { + session.fetch_node(&version)?; + Ok(true) + } + Fetch::Yarn(version) => { + session.fetch_yarn(&version)?; + Ok(true) + } + }; + session.add_event_end(ActivityKind::Fetch, 0); + result + } +} diff --git a/src/command/help.rs b/src/command/help.rs index 3f41832ab..a5568d916 100644 --- a/src/command/help.rs +++ b/src/command/help.rs @@ -1,7 +1,7 @@ use notion_core::session::{ActivityKind, Session}; use notion_fail::Fallible; -use command::{Command, CommandName, Config, Current, Deactivate, Default, Install, Shim, +use command::{Command, CommandName, Config, Current, Deactivate, Default, Fetch, Shim, Uninstall, Use, Version}; use {CliParseError, Notion}; @@ -62,7 +62,7 @@ Options: Help::Command(CommandName::Default) => Default::USAGE, Help::Command(CommandName::Help) => Help::USAGE, Help::Command(CommandName::Version) => Version::USAGE, - Help::Command(CommandName::Install) => Install::USAGE, + Help::Command(CommandName::Fetch) => Fetch::USAGE, Help::Command(CommandName::Uninstall) => Uninstall::USAGE, Help::Command(CommandName::Shim) => Shim::USAGE, } diff --git a/src/command/install.rs b/src/command/install.rs deleted file mode 100644 index a63103567..000000000 --- a/src/command/install.rs +++ /dev/null @@ -1,56 +0,0 @@ -use semver::VersionReq; - -use notion_core::serial::version::parse_requirements; -use notion_core::session::{ActivityKind, Session}; -use notion_fail::Fallible; - -use Notion; -use command::{Command, CommandName, Help}; - -#[derive(Debug, Deserialize)] -pub(crate) struct Args { - arg_version: String, -} - -pub(crate) enum Install { - Help, - Default(VersionReq), -} - -impl Command for Install { - type Args = Args; - - const USAGE: &'static str = " -Install a toolchain to the local machine - -Usage: - notion install - notion install -h | --help - -Options: - -h, --help Display this message -"; - - fn help() -> Self { - Install::Help - } - - fn parse(_: Notion, Args { arg_version }: Args) -> Fallible { - let version = parse_requirements(&arg_version)?; - Ok(Install::Default(version)) - } - - fn run(self, session: &mut Session) -> Fallible { - session.add_event_start(ActivityKind::Install); - let result = match self { - Install::Help => Help::Command(CommandName::Install).run(session), - Install::Default(version) => { - session.install_node(&version)?; - - Ok(true) - } - }; - session.add_event_end(ActivityKind::Install, 0); - result - } -} diff --git a/src/command/mod.rs b/src/command/mod.rs index 177b4103e..c8954396c 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -3,7 +3,7 @@ mod current; mod deactivate; mod default; mod help; -mod install; +mod fetch; mod shim; mod uninstall; mod use_; @@ -14,7 +14,7 @@ pub(crate) use self::current::Current; pub(crate) use self::deactivate::Deactivate; pub(crate) use self::default::Default; pub(crate) use self::help::Help; -pub(crate) use self::install::Install; +pub(crate) use self::fetch::Fetch; pub(crate) use self::shim::Shim; pub(crate) use self::uninstall::Uninstall; pub(crate) use self::use_::Use; @@ -34,7 +34,7 @@ use std::str::FromStr; /// Represents the set of Notion command names. #[derive(Debug, Deserialize, Clone, Copy)] pub(crate) enum CommandName { - Install, + Fetch, Uninstall, Use, Config, @@ -52,7 +52,7 @@ impl Display for CommandName { fmt, "{}", match *self { - CommandName::Install => "install", + CommandName::Fetch => "fetch", CommandName::Uninstall => "uninstall", CommandName::Use => "use", CommandName::Config => "config", @@ -72,7 +72,7 @@ impl FromStr for CommandName { fn from_str(s: &str) -> Result { Ok(match s { - "install" => CommandName::Install, + "fetch" => CommandName::Fetch, "uninstall" => CommandName::Uninstall, "use" => CommandName::Use, "config" => CommandName::Config, diff --git a/src/command/use_.rs b/src/command/use_.rs index 42d5029d3..33fbeec6b 100644 --- a/src/command/use_.rs +++ b/src/command/use_.rs @@ -68,7 +68,7 @@ Options: } Use::Global(requirements) => { let shell = CurrentShell::detect()?; - let version = session.install_node(&requirements)?.into_version(); + let version = session.fetch_node(&requirements)?.into_version(); let postscript = Postscript::ToolVersion { tool: "node".to_string(), version, diff --git a/src/notion.rs b/src/notion.rs index 8d599e5f4..e41a995ef 100644 --- a/src/notion.rs +++ b/src/notion.rs @@ -23,7 +23,7 @@ use notion_core::session::{ActivityKind, Session}; use notion_core::style::{display_error, display_unknown_error, ErrorContext}; use notion_fail::{FailExt, Fallible, NotionError}; -use command::{Command, CommandName, Config, Current, Deactivate, Default, Help, Install, Shim, +use command::{Command, CommandName, Config, Current, Deactivate, Default, Help, Fetch, Shim, Uninstall, Use, Version}; use error::{CliParseError, CommandUnimplementedError, DocoptExt, NotionErrorExt}; @@ -58,8 +58,8 @@ Options: -v, --verbose Use verbose output Some common notion commands are: - install Install a toolchain to the local machine - uninstall Uninstall a toolchain from the local machine + fetch Fetch a toolchain to the local machine + uninstall Uninstall a tool from the local machine use Activate a particular toolchain version config Get or set configuration values current Display the currently activated toolchain version @@ -172,7 +172,7 @@ See 'notion help ' for more information on a specific command. fn run(self, session: &mut Session) -> Fallible { match self.command { - CommandName::Install => Install::go(self, session), + CommandName::Fetch => Fetch::go(self, session), CommandName::Uninstall => Uninstall::go(self, session), CommandName::Use => Use::go(self, session), CommandName::Config => Config::go(self, session),