Add helper functions to get names of arguments/subcommands
This commit is contained in:
parent
1aae2dccf9
commit
36ecafad4d
1 changed files with 24 additions and 4 deletions
|
@ -5,19 +5,19 @@ use tag::Tag;
|
||||||
/// Generates a clap::SubCommand to be integrated in the commandline-ui builder for building a
|
/// Generates a clap::SubCommand to be integrated in the commandline-ui builder for building a
|
||||||
/// "tags --add foo --remove bar" subcommand to do tagging action.
|
/// "tags --add foo --remove bar" subcommand to do tagging action.
|
||||||
pub fn tag_subcommand<'a, 'b>() -> App<'a, 'b> {
|
pub fn tag_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
SubCommand::with_name("tags")
|
SubCommand::with_name(tag_subcommand_name())
|
||||||
.author("Matthias Beyer <mail@beyermatthias.de>")
|
.author("Matthias Beyer <mail@beyermatthias.de>")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
.about("Add or remove tags")
|
.about("Add or remove tags")
|
||||||
|
|
||||||
.arg(Arg::with_name("add-tags")
|
.arg(Arg::with_name(tag_subcommand_add_arg_name())
|
||||||
.short("a")
|
.short("a")
|
||||||
.long("add")
|
.long("add")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
.help("Add tags, seperated by comma or by specifying multiple times"))
|
.help("Add tags, seperated by comma or by specifying multiple times"))
|
||||||
|
|
||||||
.arg(Arg::with_name("remove-tags")
|
.arg(Arg::with_name(tag_subcommand_remove_arg_name())
|
||||||
.short("r")
|
.short("r")
|
||||||
.long("remove")
|
.long("remove")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
@ -25,10 +25,26 @@ pub fn tag_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
.help("Remove tags, seperated by comma or by specifying multiple times"))
|
.help("Remove tags, seperated by comma or by specifying multiple times"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tag_subcommand_name() -> &'static str {
|
||||||
|
"tags"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tag_subcommand_add_arg_name() -> &'static str {
|
||||||
|
"add-tags"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tag_subcommand_remove_arg_name() -> &'static str {
|
||||||
|
"remove-tags"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tag_subcommand_names() -> Vec<&'static str> {
|
||||||
|
vec![tag_subcommand_add_arg_name(), tag_subcommand_remove_arg_name()]
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates a clap::Arg which can be integrated into the commandline-ui builder for building a
|
/// Generates a clap::Arg which can be integrated into the commandline-ui builder for building a
|
||||||
/// "-t" or "--tags" argument which takes values for tagging actions (add, remove)
|
/// "-t" or "--tags" argument which takes values for tagging actions (add, remove)
|
||||||
pub fn tag_argument<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn tag_argument<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
Arg::with_name("specify-tags")
|
Arg::with_name(tag_argument_name())
|
||||||
.short("t")
|
.short("t")
|
||||||
.long("tags")
|
.long("tags")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
@ -36,6 +52,10 @@ pub fn tag_argument<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
.help("Add or remove tags, prefixed by '+' (for adding) or '-' (for removing)")
|
.help("Add or remove tags, prefixed by '+' (for adding) or '-' (for removing)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tag_argument_name() -> &'static str {
|
||||||
|
"specify-tags"
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the tags which should be added from the commandline
|
/// Get the tags which should be added from the commandline
|
||||||
///
|
///
|
||||||
/// Returns none if the argument was not specified
|
/// Returns none if the argument was not specified
|
||||||
|
|
Loading…
Reference in a new issue