Skip to main content

nu_config/
config_file.rs

1/// Metadata about the two kinds of Nushell configuration files.
2///
3/// Each variant knows its file name, its embedded default content, and
4/// its scaffold template.
5///
6/// This was moved here from `nu-utils` because it is config infrastructure,
7/// not a general utility.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, derive_more::Display)]
9#[display("{}", self.name())]
10pub enum ConfigFileKind {
11    Config,
12    Env,
13}
14
15impl ConfigFileKind {
16    /// The compiled-in default content (evaluated before the user's file).
17    pub const fn default(self) -> &'static str {
18        match self {
19            Self::Config => include_str!("../default_files/default_config.nu"),
20            Self::Env => include_str!("../default_files/default_env.nu"),
21        }
22    }
23
24    /// The scaffold content written when the file does not exist on first
25    /// startup.
26    pub const fn scaffold(self) -> &'static str {
27        match self {
28            Self::Config => include_str!("../default_files/scaffold_config.nu"),
29            Self::Env => include_str!("../default_files/scaffold_env.nu"),
30        }
31    }
32
33    /// The full doc-commented template written by `config nu` / `config env`.
34    pub const fn doc(self) -> &'static str {
35        match self {
36            Self::Config => include_str!("../default_files/doc_config.nu"),
37            Self::Env => include_str!("../default_files/doc_env.nu"),
38        }
39    }
40
41    /// Human-readable name: `"Config"` or `"Environment config"`.
42    pub const fn name(self) -> &'static str {
43        match self {
44            Self::Config => "Config",
45            Self::Env => "Environment config",
46        }
47    }
48
49    /// File name: `"config.nu"` or `"env.nu"`.
50    pub const fn path(self) -> &'static str {
51        match self {
52            Self::Config => "config.nu",
53            Self::Env => "env.nu",
54        }
55    }
56
57    /// Compiled-in default file name: `"default_config.nu"` or
58    /// `"default_env.nu"`.
59    pub const fn default_path(self) -> &'static str {
60        match self {
61            Self::Config => "default_config.nu",
62            Self::Env => "default_env.nu",
63        }
64    }
65}