Skip to main content

batman_robin/cli/
app.rs

1use super::aggregation::cmd_aggregation;
2use super::ap_isolation::cmd_ap_isolation;
3use super::bridge_loop_avoidance::cmd_bridge_loop_avoidance;
4use super::gateways::cmd_gateways;
5use super::gw_mode::cmd_gw_mode;
6use super::interface::cmd_interfaces;
7use super::neighbors::cmd_neighbors;
8use super::originators::cmd_originators;
9use super::routing_algo::cmd_routing_algo;
10use super::transglobal::cmd_transglobal;
11use super::translocal::cmd_translocal;
12use clap::{Arg, Command};
13
14/// Builds the command-line interface (CLI) for `robctl`.
15///
16/// This function sets up the main CLI structure using `clap`, including global options
17/// and all subcommands.
18///
19/// # Global Options
20/// - `--meshif`, `-m` : Specify the batman-adv mesh interface to operate on (default: `bat0`).
21/// - `--version`, `-v` : Print the `robctl` version and the batman-adv kernel module version (if loaded).
22///
23/// # Subcommands
24/// - `neighbors` (`n`) : Display the neighbor table.
25/// - `gateways` (`gwl`) : Display the list of gateways.
26/// - `gw_mode` (`gw`) : Display or modify the gateway mode.
27/// - `originators` (`o`) : Display the originator table.
28/// - `translocal` (`tl`) : Display local translation table.
29/// - `transglobal` (`tg`) : Display global translation table.
30/// - `interface` (`if`) : Display or modify batman-adv interface settings.
31/// - `ap_isolation` (`ap`) : Display or modify AP isolation setting.
32/// - `aggregation` (`ag`) : Display or modify aggregation setting.
33/// - `bridge_loop_avoidance` (`bl`) : Display or modify bridge loop avoidance setting.
34/// - `routing_algo` (`ra`) : Display or modify the routing algorithm.
35///
36/// # Returns
37/// A `clap::Command` ready to parse command-line arguments.
38///
39/// # Example
40/// ```no_run
41/// use batman_robin::cli::app::build_cli;
42///
43/// let cli = build_cli();
44/// let matches = cli.get_matches();
45/// ```
46pub fn build_cli() -> Command {
47    Command::new("robctl")
48        //.subcommand_required(true)
49        .arg_required_else_help(true)
50        .about("Rust implementation of batctl, B.A.T.M.A.N. advanced control tool")
51        .arg(
52            Arg::new("meshif")
53                .long("meshif")
54                .short('m')
55                .value_name("IFACE")
56                .help("Batman-adv mesh interface to operate on (default: bat0)"),
57        )
58        .arg(
59            Arg::new("version")
60                .short('v')
61                .long("version")
62                .help("Print robctl version and batman-adv module version (if loaded)")
63                .action(clap::ArgAction::SetTrue),
64        )
65        .subcommand(cmd_neighbors())
66        .subcommand(cmd_gateways())
67        .subcommand(cmd_gw_mode())
68        .subcommand(cmd_originators())
69        .subcommand(cmd_translocal())
70        .subcommand(cmd_transglobal())
71        .subcommand(cmd_interfaces())
72        .subcommand(cmd_ap_isolation())
73        .subcommand(cmd_aggregation())
74        .subcommand(cmd_bridge_loop_avoidance())
75        .subcommand(cmd_routing_algo())
76}