mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-01 18:56:38 +03:00
Merge pull request #329 from AleoHQ/feature/leo-add-interface
Remote functionality in `leo add`
This commit is contained in:
commit
335526f4e5
@ -45,17 +45,25 @@ impl CLI for AddCommand {
|
||||
type Options = (Option<String>, Option<String>, Option<String>);
|
||||
type Output = ();
|
||||
|
||||
const ABOUT: AboutType = "Install a package from the package manager";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[];
|
||||
const ABOUT: AboutType = "Install a package from the Aleo Package Manager";
|
||||
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] = &[
|
||||
// (argument, conflicts, possible_values, requires)
|
||||
("[author] -a --author=<author> 'Specify a package author'", &[], &[], &[
|
||||
"package_name",
|
||||
"package",
|
||||
]),
|
||||
(
|
||||
"[package_name] -p --package_name=<package_name> 'Specify a package name'",
|
||||
"[package] -p --package=<package> 'Specify a package name'",
|
||||
&[],
|
||||
&[],
|
||||
&["author"],
|
||||
@ -64,21 +72,35 @@ impl CLI for AddCommand {
|
||||
"[version] -v --version=[version] 'Specify a package version'",
|
||||
&[],
|
||||
&[],
|
||||
&["author", "package_name"],
|
||||
&["author", "package"],
|
||||
),
|
||||
];
|
||||
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
||||
|
||||
fn parse(arguments: &clap::ArgMatches) -> Result<Self::Options, crate::errors::CLIError> {
|
||||
// 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_name").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)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +132,9 @@ impl CLI for AddCommand {
|
||||
Ok(response) => (response, package_name),
|
||||
//Cannot connect to the server
|
||||
Err(_error) => {
|
||||
return Err(ConnectionUnavailable("Could not connect to the package manager".into()).into());
|
||||
return Err(
|
||||
ConnectionUnavailable("Could not connect to the Aleo Package Manager".into()).into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ pub enum AddError {
|
||||
#[error("missing author or package name")]
|
||||
MissingAuthorOrPackageName,
|
||||
|
||||
#[error("invalid remote")]
|
||||
InvalidRemote,
|
||||
|
||||
#[error("{:?}", _0)]
|
||||
ZipError(OsString),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user