Skip to main content

mittens_engine/engine/
cli.rs

1//! Command-line interface for mittens-engine.
2
3use crate::engine::graphics::MsaaMode;
4use std::env;
5
6#[derive(Debug, Clone, PartialEq)]
7pub enum CliCommand {
8    /// Save the scene to a file.
9    Save { filename: String },
10    /// Load a scene from a file.
11    Load { filename: String },
12    /// Run normally (no special command).
13    Run,
14}
15
16pub struct CLI {
17    pub command: CliCommand,
18    pub msaa_mode: Option<MsaaMode>,
19}
20
21impl CLI {
22    /// Parse command-line arguments.
23    ///
24    /// Supported commands:
25    /// - `./mittens-engine save <filename>` - Save the current scene
26    /// - `./mittens-engine load <filename>` - Load a scene from file
27    /// - `./mittens-engine` (no args) - Run normally
28    pub fn parse() -> Self {
29        let args: Vec<String> = env::args().skip(1).collect();
30
31        let mut msaa_mode: Option<MsaaMode> = None;
32        let mut positional: Vec<String> = Vec::new();
33
34        for arg in args {
35            match arg.as_str() {
36                "--no-msaa" | "--msaa=off" => msaa_mode = Some(MsaaMode::Off),
37                "--msaa4x" | "--msaa=4x" => msaa_mode = Some(MsaaMode::Msaa4x),
38                _ if arg.starts_with("--") => {
39                    eprintln!("Unknown flag: {arg}");
40                }
41                _ => positional.push(arg),
42            }
43        }
44
45        let command = match positional.as_slice() {
46            [cmd, filename] if cmd == "save" => CliCommand::Save {
47                filename: filename.to_string(),
48            },
49            [cmd, filename] if cmd == "load" => CliCommand::Load {
50                filename: filename.to_string(),
51            },
52            [] => CliCommand::Run,
53            [unknown, ..] => {
54                eprintln!("Unknown command: {unknown}. Running normally.");
55                CliCommand::Run
56            }
57        };
58
59        CLI { command, msaa_mode }
60    }
61}