我想使用
store_blocklist::insert_blocklist()
来调用函数
clap
pub fn args() -> Command {
Command::new("admin-cli")
.about("CLI to manage admin tasks")
.subcommand_required(true)
.arg_required_else_help(true)
.allow_external_subcommands(false)
.subcommand(
Command::new("blocklist")
.about("Storing the blocklists of SteveBlack in the database")
//call store_blocklist::insert_blocklist() here
)
}
我该怎么做?
这不是 Clap 的工作。 Clap 是一个命令行参数解析器,仅此而已。
Clap 处理完用户的参数后,您可以对它们执行任何您想要的操作,包括调用您的函数:
use clap::{Arg, ArgAction, Command};
pub fn args() -> Command {
Command::new("admin-cli")
.about("CLI to manage admin tasks")
.arg_required_else_help(true)
.allow_external_subcommands(false)
.arg(
Arg::new("blocklist")
.long("blocklist")
.help("Storing the blocklists of SteveBlack in the database")
.action(ArgAction::SetTrue),
)
}
fn main() {
let cmd = args();
let args = cmd.get_matches();
if args.get_flag("blocklist") {
// Call your function here.
println!("Hi from blocklist!");
}
}