Add possible values for argument type

This commit is contained in:
raychu86 2020-09-03 00:21:07 -07:00
parent f06d28188e
commit 063c4b3f3b
7 changed files with 31 additions and 11 deletions

View File

@ -33,7 +33,13 @@ pub trait CLI {
fn new<'a, 'b>() -> App<'a, 'b> { fn new<'a, 'b>() -> App<'a, 'b> {
let arguments = &Self::ARGUMENTS let arguments = &Self::ARGUMENTS
.iter() .iter()
.map(|a| Arg::with_name(a.0).help(a.1).required(a.2).index(a.3)) .map(|a| {
let mut args = Arg::with_name(a.0).help(a.1).required(a.3).index(a.4);
if a.2.len() > 0 {
args = args.possible_values(a.2);
}
args
})
.collect::<Vec<Arg<'static, 'static>>>(); .collect::<Vec<Arg<'static, 'static>>>();
let flags = &Self::FLAGS let flags = &Self::FLAGS
.iter() .iter()
@ -56,7 +62,13 @@ pub trait CLI {
.about(s.1) .about(s.1)
.args( .args(
&s.2.iter() &s.2.iter()
.map(|a| Arg::with_name(a.0).help(a.1).required(a.2).index(a.3)) .map(|a| {
let mut args = Arg::with_name(a.0).help(a.1).required(a.3).index(a.4);
if a.2.len() > 0 {
args = args.possible_values(a.2);
}
args
})
.collect::<Vec<Arg<'static, 'static>>>(), .collect::<Vec<Arg<'static, 'static>>>(),
) )
.args( .args(

View File

@ -24,9 +24,11 @@ pub type DescriptionType = &'static str;
pub type RequiredType = bool; pub type RequiredType = bool;
pub type PossibleValuesType = &'static [&'static str];
pub type IndexType = u64; pub type IndexType = u64;
pub type ArgumentType = (NameType, DescriptionType, RequiredType, IndexType); pub type ArgumentType = (NameType, DescriptionType, PossibleValuesType, RequiredType, IndexType);
// Format // Format
// "[flag] -f --flag 'Add flag description here'" // "[flag] -f --flag 'Add flag description here'"

View File

@ -51,6 +51,7 @@ impl CLI for AddCommand {
( (
"REMOTE", "REMOTE",
"Install a package from the Aleo Package Manager with the given remote", "Install a package from the Aleo Package Manager with the given remote",
&[],
false, false,
1u64, 1u64,
), ),

View File

@ -46,6 +46,7 @@ impl CLI for LoginCommand {
( (
"NAME", "NAME",
"Sets the authentication token for login to the package manager", "Sets the authentication token for login to the package manager",
&[],
false, false,
1u64, 1u64,
), ),

View File

@ -37,6 +37,7 @@ impl CLI for NewCommand {
( (
"NAME", "NAME",
"Sets the resulting package name, defaults to the directory name", "Sets the resulting package name, defaults to the directory name",
&[],
true, true,
1u64, 1u64,
), ),

View File

@ -30,7 +30,13 @@ impl CLI for RemoveCommand {
const ABOUT: AboutType = "Uninstall a package from the current package"; const ABOUT: AboutType = "Uninstall a package from the current package";
const ARGUMENTS: &'static [ArgumentType] = &[ const ARGUMENTS: &'static [ArgumentType] = &[
// (name, description, required, index) // (name, description, required, index)
("NAME", "Removes the package from the current directory", true, 1u64), (
"NAME",
"Removes the package from the current directory",
&[],
true,
1u64,
),
]; ];
const FLAGS: &'static [FlagType] = &[]; const FLAGS: &'static [FlagType] = &[];
const NAME: NameType = "remove"; const NAME: NameType = "remove";

View File

@ -133,12 +133,13 @@ impl CLI for UpdateAutomatic {
// (name, description, required, index) // (name, description, required, index)
( (
"automatic", "automatic",
"Enable or disable automatic updates [possible values: true, false]", "Enable or disable automatic updates",
&["true", "false"],
false, false,
1u64, 1u64,
), ),
]; ];
const FLAGS: &'static [FlagType] = &[("--quiet")]; const FLAGS: &'static [FlagType] = &["[quiet] -q --quiet 'Suppress outputs to terminal'"];
const NAME: NameType = "automatic"; const NAME: NameType = "automatic";
const OPTIONS: &'static [OptionType] = &[]; const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[]; const SUBCOMMANDS: &'static [SubCommandType] = &[];
@ -152,11 +153,7 @@ impl CLI for UpdateAutomatic {
let automatic = match automatic { let automatic = match automatic {
"true" => Some(true), "true" => Some(true),
"false" => Some(false), "false" => Some(false),
_ => { _ => unreachable!(),
// TODO (raychu86) fix this log output
tracing::info!("Possible values for this flag are `true` or `false`.");
None
}
}; };
Ok((automatic, quiet)) Ok((automatic, quiet))