summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: a669d8b3813134dfac7beff2d749456f7ff5974f (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
mod config;
mod errors;
mod functions;
mod help;
mod jumplist;
mod layout;
mod magic_image;
mod magic_packed;
mod nums;
mod op;
mod run;
mod session;
mod shell;
mod state;
mod term;

use std::path::PathBuf;

fn main() -> Result<(), errors::FxError> {
    let args: Vec<String> = std::env::args().collect();
    let len = args.len();
    match len {
        1 => {
            if let Err(e) = run::run(
                std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
                false,
            ) {
                eprintln!("{}", e);
            }
        }

        2 => match args[1].as_str() {
            "-h" | "--help" => {
                print!("{}", help::HELP);
            }
            "-l" | "--log" => {
                if let Err(e) = run::run(
                    std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
                    true,
                ) {
                    eprintln!("{}", e);
                }
            }
            "--init" => {
                print!("{}", shell::INTEGRATION_CODE);
            }
            _ => {
                if let Err(e) = run::run(PathBuf::from(&args[1]), false) {
                    eprintln!("{}", e);
                }
            }
        },
        3 => {
            if args[1] == "-l" || args[1] == "--log" {
                if let Err(e) = run::run(PathBuf::from(&args[2]), true) {
                    eprintln!("{}", e);
                }
            } else {
                print!("{}", help::HELP);
            }
        }
        _ => print!("{}", help::HELP),
    }
    Ok(())
}