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 of a packages `etc` directory.
8 /// If unset (the default), the root is the package root.
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 pub(crate) etc_root: Option<PathBuf>,
12 /// The `etc` directory for non-optional packages
13 /// Default: `etc` With the `--nvim` preset, this is `start`
14 /// Note: If `etc_root` is set, the package ID is appended.
15 pub(crate) etc: PathBuf,
16 /// The `etc` directory for optional packages
17 /// Default: `etc`
18 /// With the `--nvim` preset, this is `opt`
19 /// Note: If `etc_root` is set, the package ID is appended.
20 pub(crate) opt_etc: PathBuf,
21 /// The `conf` directory name
22 /// Default: `conf`
23 pub(crate) conf: PathBuf,
24 /// The `doc` directory name
25 /// Default: `doc`
26 pub(crate) doc: PathBuf,
27}
28
29impl RockLayoutConfig {
30 /// Creates a `RockLayoutConfig` for use with Neovim
31 /// - `etc_root`: `site/pack/lux`
32 /// - `etc`: `start`
33 /// - `opt_etc`: `opt`
34 pub fn new_nvim_layout() -> Self {
35 Self {
36 etc_root: Some("site/pack/lux".into()),
37 etc: "start".into(),
38 opt_etc: "opt".into(),
39 conf: "conf".into(),
40 doc: "doc".into(),
41 }
42 }
43
44 pub(crate) fn is_default(&self) -> bool {
45 &Self::default() == self
46 }
47}
48
49impl Default for RockLayoutConfig {
50 fn default() -> Self {
51 Self {
52 etc_root: None,
53 etc: "etc".into(),
54 opt_etc: "etc".into(),
55 conf: "conf".into(),
56 doc: "doc".into(),
57 }
58 }
59}