forked from extern/nushell
improve subcommand parse
This commit is contained in:
parent
92f72b4103
commit
4deed7c836
@ -7,8 +7,8 @@ fn main() -> std::io::Result<()> {
|
||||
let mut parser_state = Arc::new(ParserState::new());
|
||||
let mut working_set = ParserWorkingSet::new(Some(parser_state.clone()));
|
||||
|
||||
// let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
||||
// working_set.add_decl(sig.into());
|
||||
let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
||||
working_set.add_decl(sig.into());
|
||||
|
||||
// let sig = Signature::build("bar")
|
||||
// .named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'))
|
||||
|
@ -643,17 +643,16 @@ impl ParserWorkingSet {
|
||||
// assume spans.len() > 0?
|
||||
let name = self.get_span_contents(spans[0]);
|
||||
|
||||
if self.contains_decl_partial_match(name) {
|
||||
// potentially subcommand
|
||||
if let Some(mut decl_id) = self.find_decl(name) {
|
||||
let mut name = name.to_vec();
|
||||
let mut pos = 1;
|
||||
let mut decl_id = None;
|
||||
while pos < spans.len() {
|
||||
// look to see if it's a subcommand
|
||||
let mut new_name = name.to_vec();
|
||||
new_name.push(b' ');
|
||||
new_name.extend(self.get_span_contents(spans[pos]));
|
||||
if let Some(did) = self.find_decl(&new_name) {
|
||||
decl_id = Some(did);
|
||||
decl_id = did;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -661,18 +660,14 @@ impl ParserWorkingSet {
|
||||
pos += 1;
|
||||
}
|
||||
// parse internal command
|
||||
if let Some(decl_id) = decl_id {
|
||||
let (call, span, err) = self.parse_internal_call(&spans[(pos - 1)..], decl_id);
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
span,
|
||||
},
|
||||
err,
|
||||
)
|
||||
} else {
|
||||
self.parse_external_call(spans)
|
||||
}
|
||||
let (call, span, err) = self.parse_internal_call(&spans[(pos - 1)..], decl_id);
|
||||
(
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
span,
|
||||
},
|
||||
err,
|
||||
)
|
||||
} else {
|
||||
self.parse_external_call(spans)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user