intelli_shell/model/
variable.rs

1/// Type to represent a variable value
2#[derive(Clone)]
3#[cfg_attr(debug_assertions, derive(Debug))]
4pub struct VariableValue {
5    /// The unique identifier for the value (if stored)
6    pub id: Option<i32>,
7    /// The flattened root command (i.e., the first word)
8    pub flat_root_cmd: String,
9    /// The flattened variable name (or multiple, e.g., "var1|var2")
10    pub flat_variable: String,
11    /// The variable value
12    pub value: String,
13}
14
15impl VariableValue {
16    /// Creates a new variable value
17    pub fn new(
18        flat_root_cmd: impl Into<String>,
19        flat_variable_name: impl Into<String>,
20        value: impl Into<String>,
21    ) -> Self {
22        Self {
23            id: None,
24            flat_root_cmd: flat_root_cmd.into(),
25            flat_variable: flat_variable_name.into(),
26            value: value.into(),
27        }
28    }
29}
30
31/// Suggestion for a variable value
32#[cfg_attr(debug_assertions, derive(Debug))]
33pub enum VariableSuggestion {
34    /// A new secret value, the user must input it and it won't be stored
35    Secret,
36    /// A new value, if the user enters it, it must be then stored
37    New,
38    /// Suggestion from the environment variables
39    Environment {
40        env_var_name: String,
41        value: Option<String>,
42    },
43    /// Suggestion for an already-stored value
44    Existing(VariableValue),
45    /// Suggestion from a variable completion
46    Completion(String),
47    /// Literal suggestion, derived from the variable name itself
48    Derived(String),
49}