aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/console/input/input_argument.rs
blob: 53576ddefa5eb302c2815b80be11546b83cba854 (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
//! ref: composer/src/Composer/Console/Input/InputArgument.php

use anyhow::Result;
use shirabe_external_packages::symfony::console::input::InputArgument as BaseInputArgument;
use shirabe_php_shim::PhpMixed;

#[derive(Debug)]
pub struct InputArgument {
    inner: BaseInputArgument,
}

impl InputArgument {
    pub const REQUIRED: i64 = 1;
    pub const OPTIONAL: i64 = 2;
    pub const IS_ARRAY: i64 = 4;

    pub fn new(
        name: &str,
        mode: Option<i64>,
        description: &str,
        default: Option<PhpMixed>,
        // TODO(cli-completion): suggested_values closure / list dropped along with completion support
    ) -> Result<Self> {
        let inner = BaseInputArgument::new(
            name.to_string(),
            mode,
            description.to_string(),
            default.unwrap_or(PhpMixed::Null),
        )?;
        Ok(Self { inner })
    }

    /// Unwraps to the underlying Symfony `InputArgument` (used when forwarding a Composer-typed
    /// definition to the Symfony command state).
    pub(crate) fn to_base(&self) -> BaseInputArgument {
        self.inner.clone()
    }
}