summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: e46a1e6dd53e3ad91952ebc8d7766f54805bdf26 (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
66
67
68
//! Orrery: an ASCII sci-fi-fantasy game.
//!
//! `orrery` plays; `orrery names`, `ship`, `galaxy`, `system` and `town` print
//! what the generators make, without the TUI.

mod app;
mod cli;
mod dungeon;
mod items;
mod names;
mod save;
mod scenes;
mod seed;
mod space;
mod term;
mod town;
mod trade;

use std::process::ExitCode;

fn main() -> ExitCode {
    let args: Vec<String> = std::env::args().skip(1).collect();
    match cli::parse(&args) {
        Ok(cli::Command::Play { seed }) => match app::run(seed) {
            Ok(()) => ExitCode::SUCCESS,
            Err(e) => {
                eprintln!("orrery: {e}");
                ExitCode::FAILURE
            }
        },
        Ok(cli::Command::Names(opts)) => {
            cli::print_names(&opts);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Ship { seed, which }) => {
            cli::print_ship(seed, which);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Weapons { seed, count }) => {
            cli::print_weapons(seed, count);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Armour { seed, count }) => {
            cli::print_armour(seed, count);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Galaxy { seed }) => {
            cli::print_galaxy(seed);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::System { seed, which }) => {
            cli::print_system(seed, which);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Town { seed, which, inside }) => {
            cli::print_town(seed, which, inside);
            ExitCode::SUCCESS
        }
        Ok(cli::Command::Help) => {
            print!("{}", cli::USAGE);
            ExitCode::SUCCESS
        }
        Err(msg) => {
            eprintln!("orrery: {msg}\n\n{}", cli::USAGE);
            ExitCode::from(2)
        }
    }
}