Add param descriptions

This commit is contained in:
JT 2021-07-17 10:31:36 +12:00
parent 6f1a5c8e02
commit 4249c5b3e0
2 changed files with 31 additions and 11 deletions

View File

@ -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);

View File

@ -1008,16 +1008,10 @@ impl ParserWorkingSet {
let syntax_shape = self.parse_shape_name(contents);
//TODO check if we're replacing one already
match last {
Arg::Positional(PositionalArg { name, desc, shape }) => {
Arg::Positional(PositionalArg { shape, .. }) => {
*shape = syntax_shape;
}
Arg::Flag(Flag {
long,
short,
arg,
required,
desc,
}) => *arg = Some(syntax_shape),
Arg::Flag(Flag { arg, .. }) => *arg = Some(syntax_shape),
}
}
parse_mode = ParseMode::ArgMode;
@ -1025,6 +1019,32 @@ impl ParserWorkingSet {
}
}
}
Token {
contents: crate::TokenContents::Comment,
span,
} => {
let contents = &self.file_contents[span.start + 1..span.end];
let mut contents = String::from_utf8_lossy(contents).to_string();
contents = contents.trim().into();
if let Some(last) = args.last_mut() {
match last {
Arg::Flag(flag) => {
if !flag.desc.is_empty() {
flag.desc.push_str("\n");
}
flag.desc.push_str(&contents);
}
Arg::Positional(positional) => {
if !positional.desc.is_empty() {
positional.desc.push_str("\n");
}
positional.desc.push_str(&contents);
}
}
}
}
_ => {}
}
}