sara_core/init/
options.rs

1//! Init options for item initialization.
2
3use std::path::PathBuf;
4
5use crate::model::ItemType;
6
7/// Options for initializing a new item or adding frontmatter to an existing file.
8#[derive(Debug, Clone)]
9pub struct InitOptions {
10    /// The file path to create or update.
11    pub file: PathBuf,
12    /// The item type.
13    pub item_type: ItemType,
14    /// Optional ID (will be auto-generated if not provided).
15    pub id: Option<String>,
16    /// Optional name (will be extracted from file or generated if not provided).
17    pub name: Option<String>,
18    /// Optional description.
19    pub description: Option<String>,
20    /// Upstream references (refines) - valid for use_case and scenario.
21    pub refines: Vec<String>,
22    /// Upstream references (derives_from) - valid for requirement types.
23    pub derives_from: Vec<String>,
24    /// Upstream references (satisfies) - valid for architecture and design types.
25    pub satisfies: Vec<String>,
26    /// Specification text - valid for requirement types.
27    pub specification: Option<String>,
28    /// Target platform - valid for system_architecture.
29    pub platform: Option<String>,
30    /// Whether to overwrite existing frontmatter.
31    pub force: bool,
32}
33
34impl InitOptions {
35    /// Creates new init options with required fields.
36    pub fn new(file: PathBuf, item_type: ItemType) -> Self {
37        Self {
38            file,
39            item_type,
40            id: None,
41            name: None,
42            description: None,
43            refines: Vec::new(),
44            derives_from: Vec::new(),
45            satisfies: Vec::new(),
46            specification: None,
47            platform: None,
48            force: false,
49        }
50    }
51
52    /// Sets the ID.
53    pub fn with_id(mut self, id: impl Into<String>) -> Self {
54        self.id = Some(id.into());
55        self
56    }
57
58    /// Sets the name.
59    pub fn with_name(mut self, name: impl Into<String>) -> Self {
60        self.name = Some(name.into());
61        self
62    }
63
64    /// Sets the description.
65    pub fn with_description(mut self, description: impl Into<String>) -> Self {
66        self.description = Some(description.into());
67        self
68    }
69
70    /// Sets the refines references.
71    pub fn with_refines(mut self, refines: Vec<String>) -> Self {
72        self.refines = refines;
73        self
74    }
75
76    /// Sets the derives_from references.
77    pub fn with_derives_from(mut self, derives_from: Vec<String>) -> Self {
78        self.derives_from = derives_from;
79        self
80    }
81
82    /// Sets the satisfies references.
83    pub fn with_satisfies(mut self, satisfies: Vec<String>) -> Self {
84        self.satisfies = satisfies;
85        self
86    }
87
88    /// Sets the specification.
89    pub fn with_specification(mut self, specification: impl Into<String>) -> Self {
90        self.specification = Some(specification.into());
91        self
92    }
93
94    /// Sets the platform.
95    pub fn with_platform(mut self, platform: impl Into<String>) -> Self {
96        self.platform = Some(platform.into());
97        self
98    }
99
100    /// Sets the force flag.
101    pub fn with_force(mut self, force: bool) -> Self {
102        self.force = force;
103        self
104    }
105}