Skip to main content

serenade_console/
input.rs

1//! Parsed console input.
2
3use std::sync::Arc;
4
5use serenade_di::Container;
6use serenade_kernel::Environment;
7
8/// Context and trailing arguments for a command run.
9#[derive(Clone)]
10pub struct Input {
11    environment: Environment,
12    debug: bool,
13    args: Vec<String>,
14    container: Option<Arc<Container>>,
15}
16
17impl Input {
18    /// Builds input for a command invocation.
19    #[must_use]
20    pub const fn new(
21        environment: Environment,
22        debug: bool,
23        args: Vec<String>,
24        container: Option<Arc<Container>>,
25    ) -> Self {
26        Self {
27            environment,
28            debug,
29            args,
30            container,
31        }
32    }
33
34    /// Active environment (`--env` / `APP_ENV`).
35    #[must_use]
36    pub const fn environment(&self) -> &Environment {
37        &self.environment
38    }
39
40    /// Whether debug is enabled (false when `--no-debug`).
41    #[must_use]
42    pub const fn debug(&self) -> bool {
43        self.debug
44    }
45
46    /// Trailing arguments after the command name.
47    #[must_use]
48    pub fn args(&self) -> &[String] {
49        &self.args
50    }
51
52    /// Optional DI container for kernel-aware commands.
53    #[must_use]
54    pub const fn container(&self) -> Option<&Arc<Container>> {
55        self.container.as_ref()
56    }
57}