Skip to content

Commit

Permalink
feat: added Spec::parse_script fn
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Sep 25, 2024
1 parent b1f6617 commit 124a705
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/parse/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ impl Spec {
}
Ok((schema, body))
}
pub fn parse_script(file: &Path) -> Result<Spec, UsageErr> {
let raw = extract_usage_from_comments(&file::read_to_string(file)?);
let ctx = ParsingContext::new(file, &raw);
let mut spec = Self::parse(&ctx, &raw)?;
if spec.bin.is_empty() {
spec.bin = file.file_name().unwrap().to_str().unwrap().to_string();
}
if spec.name.is_empty() {
spec.name.clone_from(&spec.bin);
}
Ok(spec)
}
pub fn parse_spec(input: &str) -> Result<Spec, UsageErr> {
Self::parse(&Default::default(), input)
}
Expand Down

0 comments on commit 124a705

Please sign in to comment.