mirror of
https://github.com/nushell/nushell.git
synced 2025-04-22 20:28:22 +02:00
Enable syntax/completions for source (#3589)
This commit is contained in:
parent
383e874166
commit
e8dfd4ba39
@ -21,7 +21,7 @@ impl WholeStreamCommand for Source {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("source").required(
|
Signature::build("source").required(
|
||||||
"filename",
|
"filename",
|
||||||
SyntaxShape::String,
|
SyntaxShape::FilePath,
|
||||||
"the filepath to the script file to source",
|
"the filepath to the script file to source",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,8 @@ pub enum ArgumentError {
|
|||||||
/// A sequence of characters was found that was not syntactically valid (but would have
|
/// A sequence of characters was found that was not syntactically valid (but would have
|
||||||
/// been valid if the command was an external command)
|
/// been valid if the command was an external command)
|
||||||
InvalidExternalWord,
|
InvalidExternalWord,
|
||||||
|
/// A bad value in this location
|
||||||
|
BadValue(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrettyDebug for ArgumentError {
|
impl PrettyDebug for ArgumentError {
|
||||||
@ -186,6 +188,11 @@ impl PrettyDebug for ArgumentError {
|
|||||||
+ DbgDocBldr::description("`")
|
+ DbgDocBldr::description("`")
|
||||||
}
|
}
|
||||||
ArgumentError::InvalidExternalWord => DbgDocBldr::description("invalid word"),
|
ArgumentError::InvalidExternalWord => DbgDocBldr::description("invalid word"),
|
||||||
|
ArgumentError::BadValue(msg) => {
|
||||||
|
DbgDocBldr::description("bad value `")
|
||||||
|
+ DbgDocBldr::description(msg)
|
||||||
|
+ DbgDocBldr::description("`")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,6 +529,7 @@ impl ShellError {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.with_labels(vec![Label::primary(0, command.span)]),
|
.with_labels(vec![Label::primary(0, command.span)]),
|
||||||
|
ArgumentError::BadValue(msg) => Diagnostic::error().with_message(msg.clone()).with_labels(vec![Label::primary(0, command.span).with_message(msg)])
|
||||||
}),
|
}),
|
||||||
ProximateShellError::TypeError {
|
ProximateShellError::TypeError {
|
||||||
expected,
|
expected,
|
||||||
|
@ -1836,38 +1836,6 @@ 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(expand_path(&lite_cmd.parts[1].item).into_owned())
|
|
||||||
{
|
|
||||||
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!(
|
||||||
@ -1899,6 +1867,40 @@ fn parse_call(
|
|||||||
}
|
}
|
||||||
let (mut internal_command, err) = parse_internal_command(&lite_cmd, scope, &signature, 0);
|
let (mut internal_command, err) = parse_internal_command(&lite_cmd, scope, &signature, 0);
|
||||||
|
|
||||||
|
if internal_command.name == "source" {
|
||||||
|
if lite_cmd.parts.len() != 2 {
|
||||||
|
return (
|
||||||
|
Some(ClassifiedCommand::Internal(internal_command)),
|
||||||
|
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 (
|
||||||
|
Some(ClassifiedCommand::Internal(internal_command)),
|
||||||
|
Some(ParseError::mismatch(
|
||||||
|
"a filepath constant",
|
||||||
|
lite_cmd.parts[1].clone(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Ok(contents) =
|
||||||
|
std::fs::read_to_string(expand_path(&lite_cmd.parts[1].item).into_owned())
|
||||||
|
{
|
||||||
|
let _ = parse(&contents, 0, scope);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
Some(ClassifiedCommand::Internal(internal_command)),
|
||||||
|
Some(ParseError::argument_error(
|
||||||
|
lite_cmd.parts[1].clone(),
|
||||||
|
ArgumentError::BadValue("can't load source file".into()),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
internal_command.args.external_redirection = if end_of_pipeline {
|
internal_command.args.external_redirection = if end_of_pipeline {
|
||||||
ExternalRedirection::None
|
ExternalRedirection::None
|
||||||
|
Loading…
Reference in New Issue
Block a user