Skip to main content

quick_start/
quick_start.rs

1use combu::command::presets::func::help_tablize_with_alias_dedup;
2use combu::{action_result, check_error, check_help, done, preset_root, Command};
3use combu::{Context, Flag};
4use std::env;
5
6fn main() {
7	let _r = preset_root!(act)
8		.usage(env!("CARGO_PKG_NAME").to_string() + " [args]")
9		.common_flag(
10			Flag::new_bool("help")
11				.short_alias('h')
12				.description("show help"),
13		)
14		.local_flag(
15			Flag::new_bool("local")
16				.short_alias('l')
17				//.alias("test")
18				.description("local flag"),
19		)
20		/* If you want to use help subcommand,uncomment this block and add preset_help_command to use.
21		.sub_command(preset_help_command!(help_tablize_with_alias_dedup))
22		*/
23		/* If you want to use subcommand, uncomment this block, then remove this line and the line above sub_act function.
24		.sub_command(
25			Command::with_name("sub")
26				.desctiption("sub description")
27				.action(sub_act)
28				.usage("sub usage")
29				.local_flag(Flag::new_bool("sflag").description("sub local flag")),
30		)*/
31		.run_from_args(env::args().collect());
32}
33
34fn act(cmd: Command, c: Context) -> action_result!() // Or use combu::{ActionResult,ActionError} and Result<ActionResult,ActionError>
35{
36	check_error!(cmd, c);
37	check_help!(cmd, c, help_tablize_with_alias_dedup);
38	println!("Hello, combu - {:?}", c.args);
39
40	done!()
41	// Or use combu::Done and Ok(Done)
42}
43
44#[allow(dead_code)]
45fn sub_act(cmd: Command, c: Context) -> action_result!() {
46	check_error!(cmd, c);
47	check_help!(cmd, c, help_tablize_with_alias_dedup);
48	println!("sub hello, combu - {:?}", c.args);
49	done!()
50}