Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions argv/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ pub struct SpecView<'a> {
name: Option<&'a str>,
bin: Option<&'a str>,
version: Option<&'a str>,
omit_version: bool,
commands: Vec<CommandOverlay<'a>>,
}

Expand All @@ -382,6 +383,7 @@ impl<'a> SpecView<'a> {
name: None,
bin: None,
version: None,
omit_version: false,
commands: Vec::new(),
}
}
Expand All @@ -395,6 +397,7 @@ impl<'a> SpecView<'a> {
name: self.name,
bin: self.bin,
version: self.version,
omit_version: self.omit_version,
commands: self.commands,
}
}
Expand Down Expand Up @@ -426,9 +429,20 @@ impl<'a> SpecView<'a> {
{
let mut view = self.reborrow();
view.version = Some(version);
view.omit_version = false;
view
}

/// Leave the runtime version out of emitted specs and other metadata consumers.
///
/// The parser's built-in version response is unchanged because parsing reads the base spec.
/// This is for checked-in generated artifacts whose version is managed independently.
pub fn omit_version(mut self) -> Self {
self.version = None;
self.omit_version = true;
self
}

pub fn overlay<'b, 'c>(self, commands: &'b [CommandOverlay<'b>]) -> SpecView<'c>
where
'a: 'c,
Expand All @@ -450,9 +464,13 @@ impl<'a> SpecView<'a> {
Some(bin) => Some(bin),
None => self.base.bin,
},
version: match self.version {
Some(version) => Some(version),
None => self.base.version,
version: if self.omit_version {
None
} else {
match self.version {
Some(version) => Some(version),
None => self.base.version,
}
},
min_usage_version: self.base.min_usage_version,
about: self.base.about,
Expand Down Expand Up @@ -2426,6 +2444,7 @@ mod tests {
static SPEC: Spec = Spec {
name: "ex",
bin: Some("ex"),
version: Some("1.0.0"),
root: &ROOT_META,
..Spec::EMPTY
};
Expand All @@ -2452,8 +2471,17 @@ mod tests {

let base = SPEC.to_kdl();
assert!(base.contains("name \"ex\""), "{base}");
assert!(base.contains("version \"1.0.0\""), "{base}");
assert!(!base.contains("effect="), "{base}");

let without_version = SPEC.view().version("2.0.0").omit_version();
assert_eq!(without_version.spec().version, None);
assert!(!without_version.to_kdl().contains("version "));
assert_eq!(
SPEC.view().omit_version().version("3.0.0").spec().version,
Some("3.0.0")
);

let runtime_name = String::from("runtime");
let runtime_path = String::from("list");
let runtime_overlays = vec![CommandOverlay::effect(&runtime_path, Effect::Write)];
Expand Down
Loading