Skip to main content

worktree_io/config/
mod.rs

1mod ops;
2
3#[cfg(test)]
4#[path = "ops_tests.rs"]
5mod ops_tests;
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10#[serde(default)]
11pub struct Config {
12    pub editor: EditorConfig,
13    pub open: OpenConfig,
14    pub hooks: HooksConfig,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, Default)]
18pub struct HooksConfig {
19    #[serde(rename = "pre:open", skip_serializing_if = "Option::is_none", default)]
20    pub pre_open: Option<String>,
21    #[serde(rename = "post:open", skip_serializing_if = "Option::is_none", default)]
22    pub post_open: Option<String>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, Default)]
26#[serde(default)]
27pub struct EditorConfig {
28    /// Command to launch the editor, e.g. "code ." or "nvim ."
29    pub command: Option<String>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(default)]
34pub struct OpenConfig {
35    pub editor: bool,
36}
37
38impl Default for OpenConfig {
39    fn default() -> Self {
40        Self { editor: true }
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    #[test]
48    fn test_config_default() {
49        let c = Config::default();
50        assert!(c.editor.command.is_none());
51        assert!(c.open.editor);
52        assert!(c.hooks.pre_open.is_none());
53    }
54    #[test]
55    fn test_editor_config_default() {
56        assert!(EditorConfig::default().command.is_none());
57    }
58    #[test]
59    fn test_open_config_default() {
60        assert!(OpenConfig::default().editor);
61    }
62}