Skip to main content

mobius_cli/
command.rs

1//! Command-line interface shared by the `mobius` binary and documentation tooling.
2
3use std::path::PathBuf;
4
5use clap::{Parser, Subcommand};
6use mobius_gateway::client::Endpoint;
7
8/// Parsed `mobius` command line.
9#[derive(Debug, Parser)]
10#[command(
11    name = "mobius",
12    version,
13    propagate_version = true,
14    about = "Terminal client for a möbius gateway"
15)]
16pub struct Cli {
17    /// Command to run; omit it to open the terminal interface.
18    #[command(subcommand)]
19    pub command: Option<Command>,
20}
21
22/// Commands supported by the `mobius` terminal client.
23#[derive(Debug, Subcommand)]
24pub enum Command {
25    /// Run one task without opening the terminal interface.
26    Run {
27        /// Bot handle or stable identifier.
28        bot: String,
29
30        /// UTF-8 file containing the task prompt.
31        task_file: PathBuf,
32    },
33
34    /// Pair this client with a gateway.
35    Pair {
36        /// Gateway endpoint, such as `wss://gateway.example.com`.
37        endpoint: Endpoint,
38
39        /// Single-use pairing code issued by the gateway.
40        one_time_code: String,
41    },
42
43    /// Open the extension manager.
44    Extensions,
45}
46
47#[cfg(test)]
48mod tests {
49    use clap::CommandFactory as _;
50
51    use super::*;
52
53    #[test]
54    fn command_definition_is_valid() {
55        Cli::command().debug_assert();
56    }
57
58    #[test]
59    fn run_parses_a_bot_and_task_file() {
60        let cli = Cli::try_parse_from(["mobius", "run", "@builder", "task.md"])
61            .expect("parse run command");
62
63        assert!(matches!(
64            cli.command,
65            Some(Command::Run { bot, task_file })
66                if bot == "@builder" && task_file == std::path::Path::new("task.md")
67        ));
68    }
69}