From 8eb167d873dd3329a24af7fbddd593020b88c3ed Mon Sep 17 00:00:00 2001 From: raychu86 Date: Wed, 2 Sep 2020 12:53:06 -0700 Subject: [PATCH] Add support for remote --- leo/commands/add.rs | 32 +++++++++++++++++++++++++++----- leo/errors/commands/add.rs | 3 +++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/leo/commands/add.rs b/leo/commands/add.rs index d79adcf553..0f12c6f3b7 100644 --- a/leo/commands/add.rs +++ b/leo/commands/add.rs @@ -46,7 +46,15 @@ impl CLI for AddCommand { type Output = (); const ABOUT: AboutType = "Install a package from the Aleo Package Manager"; - const ARGUMENTS: &'static [ArgumentType] = &[]; + const ARGUMENTS: &'static [ArgumentType] = &[ + // (name, description, required, index) + ( + "REMOTE", + "Install a package from the Aleo Package Manager with the given remote", + false, + 1u64, + ), + ]; const FLAGS: &'static [FlagType] = &[]; const NAME: NameType = "add"; const OPTIONS: &'static [OptionType] = &[ @@ -71,14 +79,28 @@ impl CLI for AddCommand { fn parse(arguments: &clap::ArgMatches) -> Result { // TODO update to new package manager API without an author field - if arguments.is_present("author") && arguments.is_present("package_name") { + if arguments.is_present("author") && arguments.is_present("package") { return Ok(( arguments.value_of("author").map(|s| s.to_string()), arguments.value_of("package").map(|s| s.to_string()), arguments.value_of("version").map(|s| s.to_string()), )); - } else { - return Ok((None, None, None)); + } + + match arguments.value_of("REMOTE") { + Some(remote) => { + let values: Vec<&str> = remote.split('/').collect(); + + if values.len() != 2 { + return Err(InvalidRemote.into()); + } + + let author = values[0].to_string(); + let package = values[1].to_string(); + + Ok((Some(author), Some(package), None)) + } + None => Ok((None, None, None)), } } @@ -100,7 +122,7 @@ impl CLI for AddCommand { let mut json = HashMap::new(); json.insert("author", author); - json.insert("package", package_name.clone()); + json.insert("package_name", package_name.clone()); if let Some(version) = version { json.insert("version", version); diff --git a/leo/errors/commands/add.rs b/leo/errors/commands/add.rs index 64d0309436..7e7ab8cdd3 100644 --- a/leo/errors/commands/add.rs +++ b/leo/errors/commands/add.rs @@ -24,6 +24,9 @@ pub enum AddError { #[error("missing author or package name")] MissingAuthorOrPackageName, + #[error("invalid remote")] + InvalidRemote, + #[error("{:?}", _0)] ZipError(OsString), }