mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-04 16:15:11 +03:00
Add possible values for argument type
This commit is contained in:
parent
f06d28188e
commit
063c4b3f3b
16
leo/cli.rs
16
leo/cli.rs
@ -33,7 +33,13 @@ pub trait CLI {
|
||||
fn new<'a, 'b>() -> App<'a, 'b> {
|
||||
let arguments = &Self::ARGUMENTS
|
||||
.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>>>();
|
||||
let flags = &Self::FLAGS
|
||||
.iter()
|
||||
@ -56,7 +62,13 @@ pub trait CLI {
|
||||
.about(s.1)
|
||||
.args(
|
||||
&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>>>(),
|
||||
)
|
||||
.args(
|
||||
|
@ -24,9 +24,11 @@ pub type DescriptionType = &'static str;
|
||||
|
||||
pub type RequiredType = bool;
|
||||
|
||||
pub type PossibleValuesType = &'static [&'static str];
|
||||
|
||||
pub type IndexType = u64;
|
||||
|
||||
pub type ArgumentType = (NameType, DescriptionType, RequiredType, IndexType);
|
||||
pub type ArgumentType = (NameType, DescriptionType, PossibleValuesType, RequiredType, IndexType);
|
||||
|
||||
// Format
|
||||
// "[flag] -f --flag 'Add flag description here'"
|
||||
|
@ -51,6 +51,7 @@ impl CLI for AddCommand {
|
||||
(
|
||||
"REMOTE",
|
||||
"Install a package from the Aleo Package Manager with the given remote",
|
||||
&[],
|
||||
false,
|
||||
1u64,
|
||||
),
|
||||
|
@ -46,6 +46,7 @@ impl CLI for LoginCommand {
|
||||
(
|
||||
"NAME",
|
||||
"Sets the authentication token for login to the package manager",
|
||||
&[],
|
||||
false,
|
||||
1u64,
|
||||
),
|
||||
|
@ -37,6 +37,7 @@ impl CLI for NewCommand {
|
||||
(
|
||||
"NAME",
|
||||
"Sets the resulting package name, defaults to the directory name",
|
||||
&[],
|
||||
true,
|
||||
1u64,
|
||||
),
|
||||
|
@ -30,7 +30,13 @@ impl CLI for RemoveCommand {
|
||||
const ABOUT: AboutType = "Uninstall a package from the current package";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[
|
||||
// (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 NAME: NameType = "remove";
|
||||
|
@ -133,12 +133,13 @@ impl CLI for UpdateAutomatic {
|
||||
// (name, description, required, index)
|
||||
(
|
||||
"automatic",
|
||||
"Enable or disable automatic updates [possible values: true, false]",
|
||||
"Enable or disable automatic updates",
|
||||
&["true", "false"],
|
||||
false,
|
||||
1u64,
|
||||
),
|
||||
];
|
||||
const FLAGS: &'static [FlagType] = &[("--quiet")];
|
||||
const FLAGS: &'static [FlagType] = &["[quiet] -q --quiet 'Suppress outputs to terminal'"];
|
||||
const NAME: NameType = "automatic";
|
||||
const OPTIONS: &'static [OptionType] = &[];
|
||||
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
||||
@ -152,11 +153,7 @@ impl CLI for UpdateAutomatic {
|
||||
let automatic = match automatic {
|
||||
"true" => Some(true),
|
||||
"false" => Some(false),
|
||||
_ => {
|
||||
// TODO (raychu86) fix this log output
|
||||
tracing::info!("Possible values for this flag are `true` or `false`.");
|
||||
None
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
Ok((automatic, quiet))
|
||||
|
Loading…
Reference in New Issue
Block a user