1use std::fmt;
2
3use super::IdParseError;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct SpecId(String);
8
9impl SpecId {
10 pub fn as_str(&self) -> &str {
12 &self.0
13 }
14}
15
16impl fmt::Display for SpecId {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 f.write_str(&self.0)
19 }
20}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct ParsedSpecId {
25 pub spec_id: SpecId,
27}
28
29pub fn parse_spec_id(input: &str) -> Result<ParsedSpecId, IdParseError> {
34 let trimmed = input.trim();
35 if trimmed.is_empty() {
36 return Err(IdParseError::new(
37 "Spec ID cannot be empty",
38 Some("Provide a spec ID like \"cli-init\""),
39 ));
40 }
41
42 Ok(ParsedSpecId {
45 spec_id: SpecId(trimmed.to_string()),
46 })
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn parse_spec_id_preserves_value() {
55 let parsed = parse_spec_id("cli-init").unwrap();
56 assert_eq!(parsed.spec_id.as_str(), "cli-init");
57 }
58}