summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: a4f89637e19c87217fbc1f49e60cd9eee366aa33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
mod device;
mod config;

use std::{env, process, str};

const PROGRAM: &str = "z2m-utils";

fn main() {
    let config = config::get();

    let mut args = env::args_os();
    // Can't fail (it's a bug for sure)
    let argv0 = args.next().unwrap();
    let argv0 = argv0.to_str().unwrap_or(PROGRAM);
    let Some(command) = args.next() else {
        eprintln!("Usage: {argv0} <command> [args...]");
        process::exit(1);
    };

    match command.to_str() {
        Some("device") => device::main(argv0, config, args),
        _ => {
            eprintln!("{argv0}: error: Unknown command: {command:?}");
            process::exit(1);
        }
    }
}