mirror of
https://github.com/nushell/nushell
synced 2025-01-28 04:45:18 +00:00
Allow source during parsing. Hacky but works (#2855)
This commit is contained in:
parent
d05dcdda02
commit
b9bb4692a4
1 changed files with 30 additions and 0 deletions
|
@ -1786,6 +1786,36 @@ fn parse_call(
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else if lite_cmd.parts[0].item == "source" {
|
||||||
|
if lite_cmd.parts.len() != 2 {
|
||||||
|
return (
|
||||||
|
None,
|
||||||
|
Some(ParseError::argument_error(
|
||||||
|
lite_cmd.parts[0].clone(),
|
||||||
|
ArgumentError::MissingMandatoryPositional("a path for sourcing".into()),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if lite_cmd.parts[1].item.starts_with('$') {
|
||||||
|
return (
|
||||||
|
None,
|
||||||
|
Some(ParseError::mismatch(
|
||||||
|
"a filepath constant",
|
||||||
|
lite_cmd.parts[1].clone(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Ok(contents) = std::fs::read_to_string(&lite_cmd.parts[1].item) {
|
||||||
|
let _ = parse(&contents, 0, scope);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
None,
|
||||||
|
Some(ParseError::mismatch(
|
||||||
|
"a filepath to a source file",
|
||||||
|
lite_cmd.parts[1].clone(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if lite_cmd.parts.len() > 1 {
|
} else if lite_cmd.parts.len() > 1 {
|
||||||
// Check if it's a sub-command
|
// Check if it's a sub-command
|
||||||
if let Some(signature) = scope.get_signature(&format!(
|
if let Some(signature) = scope.get_signature(&format!(
|
||||||
|
|
Loading…
Reference in a new issue