Skip to main content

test/
test.rs

1use combu::command::presets::func::{help, help_tablize_with_alias_dedup};
2use combu::{action_result, check_help, done, preset_root, Command};
3use combu::{def_action_func, define_help_command_action, help_command_action};
4use combu::{Context, Flag};
5use std::env;
6
7fn main() {
8	let _r = preset_root!(act)
9		.usage(env!("CARGO_PKG_NAME").to_string() + " [args]")
10		.common_flag(
11			Flag::new_bool("help")
12				.short_alias('h')
13				.description("show help"),
14		)
15		.local_flag(
16			Flag::new_bool("local")
17				.short_alias('l')
18				//.alias("test")
19				.description("local flag"),
20		)
21		.sub_command(
22			Command::with_name("sub")
23				.description("sub description")
24				.action(sub_act)
25				.usage("sub usage")
26				.local_flag(Flag::new_bool("sflag").description("sub local flag"))
27				.sub_command(Command::with_name("leaf").description("leaf description")),
28		)
29		.sub_command(
30			Command::with_name("help")
31				.description("show help")
32				.action(help_action),
33		)
34		.sub_command(
35			Command::with_name("help2")
36				.description("show help2")
37				.action(help_command_action!(help_tablize_with_alias_dedup)),
38		)
39		.run_from_args(env::args().collect());
40}
41
42def_action_func!(act, cmd, c, [help, error], {
43	println!("Hello, combu - {:?}", c.args);
44	println!("{:?}", c);
45	done!()
46});
47
48/*
49fn act(cmd: Command, c: Context) -> action_result!() // Or use combu::{ActionResult,ActionError} and Result<ActionResult,ActionError>
50{
51	check_help!(cmd, c, help_tablize_with_alias_dedup);
52	println!("Hello, combu - {:?}", c.args);
53	println!("{:?}", c);
54
55	done!()
56}
57*/
58
59#[allow(dead_code)]
60fn sub_act(cmd: Command, c: Context) -> action_result!() {
61	check_help!(cmd, c, help);
62	println!("sub hello, combu - {:?}", c.args);
63	done!()
64}
65
66define_help_command_action!(help_action, help_req, help_tablize_with_alias_dedup);