fix: parse bash args with same-line comments (#1907)

This commit is contained in:
HugoCasa
2023-07-19 15:26:21 +02:00
committed by GitHub
parent 778ac92411
commit 0f7ed8798b

View File

@@ -18,7 +18,7 @@ pub fn parse_bash_sig(code: &str) -> anyhow::Result<MainArgSignature> {
}
lazy_static::lazy_static! {
static ref RE: Regex = Regex::new(r#"(?m)^(\w+)="\$(?:(\d+)|\{(\d+):-(.*)\})"$"#).unwrap();
static ref RE: Regex = Regex::new(r#"(?m)^(\w+)="\$(?:(\d+)|\{(\d+):-(.*)\})"(?:([\t ]*#.*)?)$"#).unwrap();
}
fn parse_file(code: &str) -> anyhow::Result<Option<Vec<Arg>>> {
@@ -66,6 +66,7 @@ mod tests {
token="$1"
image="$2"
digest="${3:-latest with spaces}"
text="$4" # with comment
"#;
//println!("{}", serde_json::to_string()?);
@@ -95,6 +96,13 @@ digest="${3:-latest with spaces}"
typ: Typ::Str(None),
default: Some(json!("latest with spaces")),
has_default: false
},
Arg {
otyp: None,
name: "text".to_string(),
typ: Typ::Str(None),
default: None,
has_default: false
}
]
}