From 124a7050c6b1b5bb502049204556b74b6e8a4b71 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:12:13 -0500 Subject: [PATCH] feat: added Spec::parse_script fn --- lib/src/parse/spec.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/parse/spec.rs b/lib/src/parse/spec.rs index 116cf93..f697049 100644 --- a/lib/src/parse/spec.rs +++ b/lib/src/parse/spec.rs @@ -42,6 +42,18 @@ impl Spec { } Ok((schema, body)) } + pub fn parse_script(file: &Path) -> Result { + 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 { Self::parse(&Default::default(), input) }