diff --git a/src/main.rs b/src/main.rs index aa8befb2cb..197448902c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,9 +60,9 @@ fn main() -> std::io::Result<()> { .required("block", SyntaxShape::Block, "body of the definition"); working_set.add_decl(sig.into()); - let file = std::fs::read(&path)?; - let (output, err) = working_set.parse_file(&path, file); - //let (output, err) = working_set.parse_source(path.as_bytes()); + // let file = std::fs::read(&path)?; + // let (output, err) = working_set.parse_file(&path, file); + let (output, err) = working_set.parse_source(path.as_bytes()); println!("{:#?}", output); println!("error: {:?}", err); diff --git a/src/parser.rs b/src/parser.rs index 87dfb6d701..6647a75923 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -994,6 +994,43 @@ impl ParserWorkingSet { short: None, required: false, })); + } else if contents.starts_with(b"-") { + // Short flag + + let short_flag = &contents[1..]; + let short_flag = + String::from_utf8_lossy(short_flag).to_string(); + let chars: Vec = short_flag.chars().collect(); + + if chars.len() > 1 { + error = error.or(Some(ParseError::Mismatch( + "short flag".into(), + *span, + ))); + + args.push(Arg::Flag(Flag { + arg: None, + desc: String::new(), + long: String::new(), + short: None, + required: false, + })); + } else if chars.is_empty() { + // Positional arg + args.push(Arg::Positional(PositionalArg { + desc: String::new(), + name: String::from_utf8_lossy(contents).to_string(), + shape: SyntaxShape::Any, + })) + } else { + args.push(Arg::Flag(Flag { + arg: None, + desc: String::new(), + long: String::new(), + short: Some(chars[0]), + required: false, + })); + } } else { // Positional arg args.push(Arg::Positional(PositionalArg {