Skip to main content

lux_lib/config/
tree.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4/// Template configuration for a rock's tree layout
5#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
6pub struct RockLayoutConfig {
7    /// The root for relocated directories (etc, src).
8    /// If unset (the default), directories are placed in the package directory.
9    /// If set, it is a directory relative to the given Lua version's install tree root.
10    /// With the `--nvim` preset, this is `site/pack/lux`.
11    #[serde(alias = "etc_root")]
12    pub root: Option<PathBuf>,
13    /// The `etc` directory for non-optional packages
14    /// Default: `etc` With the `--nvim` preset, this is `start`
15    /// Note: If `root` is set, the package ID is appended.
16    pub etc: PathBuf,
17    /// The `etc` directory for optional packages
18    /// Default: `etc`
19    /// With the `--nvim` preset, this is `opt`
20    /// Note: If `root` is set, the package ID is appended.
21    pub opt_etc: PathBuf,
22    /// The `src` directory name
23    /// Default: `src`
24    /// With the `--nvim` preset, this is `lua`
25    pub src: PathBuf,
26    /// The `lib` directory name
27    /// Default: `lib`
28    pub lib: PathBuf,
29    /// The `conf` directory name
30    /// Default: `conf`
31    pub conf: PathBuf,
32    /// The `doc` directory name
33    /// Default: `doc`
34    pub doc: PathBuf,
35}
36
37impl RockLayoutConfig {
38    /// Creates a `RockLayoutConfig` for use with Neovim
39    /// - `root`: `site/pack/lux`
40    /// - `etc`: `start`
41    /// - `opt_etc`: `opt`
42    /// - `src`: `lua`
43    /// - `lib`: `lib`
44    pub fn new_nvim_layout() -> Self {
45        Self {
46            root: Some("site/pack/lux".into()),
47            etc: "start".into(),
48            opt_etc: "opt".into(),
49            src: "lua".into(),
50            lib: "lib".into(),
51            conf: "conf".into(),
52            doc: "doc".into(),
53        }
54    }
55
56    pub(crate) fn is_default(&self) -> bool {
57        &Self::default() == self
58    }
59}
60
61impl Default for RockLayoutConfig {
62    fn default() -> Self {
63        Self {
64            root: None,
65            etc: "etc".into(),
66            opt_etc: "etc".into(),
67            src: "src".into(),
68            lib: "lib".into(),
69            conf: "conf".into(),
70            doc: "doc".into(),
71        }
72    }
73}