Skip to main content

cargo_rullst/
lib.rs

1#![cfg_attr(
2    not(test),
3    deny(
4        clippy::expect_used,
5        clippy::panic,
6        clippy::todo,
7        clippy::unimplemented,
8        clippy::unreachable,
9        clippy::unwrap_used
10    )
11)]
12
13pub mod blueprints;
14pub mod cli;
15pub mod generators;
16pub mod pkg;
17pub mod ui;
18mod update;
19
20#[cfg_attr(mutants, mutants::skip)]
21pub fn run() -> Result<(), Box<dyn std::error::Error>> {
22    let mut args: Vec<String> = std::env::args().collect();
23
24    // Cargo passes the subcommand name ("rullst") as the first argument to the binary.
25    // When invoked directly as `rullst cli ...`, we also accept "cli" gracefully.
26    if args.len() >= 2 && (args[1] == "rullst" || args[1] == "cli") {
27        args.remove(1);
28    }
29
30    if args.len() == 1 {
31        ui::trigger_background_update_check();
32        ui::show_interactive_dashboard()?;
33    } else {
34        // Extend executable commands without adding a variant to the v12 public
35        // Commands enum, which downstream Rust callers may exhaustively match.
36        let matches = <cli::Cli as clap::CommandFactory>::command()
37            .subcommand(update::command())
38            // Extend executable syntax without changing the published v12 enum.
39            .mut_subcommand("omni", |command| {
40                command.arg(
41                    clap::Arg::new("release")
42                        .long("release")
43                        .action(clap::ArgAction::SetTrue)
44                        .help("Build an Android release APK with application-owned signing"),
45                )
46            })
47            .get_matches_from(args);
48        if let Some(update) = matches.subcommand_matches("update") {
49            update::run(update)?;
50        } else if let Some(omni) = matches
51            .subcommand_matches("omni")
52            .filter(|m| m.get_flag("release"))
53        {
54            if omni.get_one::<String>("target").map(String::as_str) != Some("android") {
55                return Err("--release currently requires the android Omni target".into());
56            }
57            generators::desktop::build_android_release()?;
58        } else {
59            let cli = <cli::Cli as clap::FromArgMatches>::from_arg_matches(&matches)?;
60            cli::run_cli_command(&cli.command)?;
61        }
62    }
63    Ok(())
64}