This commit is contained in:
Jonathan Turner 2020-06-29 09:06:05 +12:00 committed by GitHub
parent 3f170c7fb8
commit bcddeb3c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 37 deletions

View File

@ -9,7 +9,7 @@ use crate::path::canonicalize;
use crate::prelude::*; use crate::prelude::*;
use crate::EnvironmentSyncer; use crate::EnvironmentSyncer;
use futures_codec::FramedRead; use futures_codec::FramedRead;
use nu_errors::ShellError; use nu_errors::{ProximateShellError, ShellDiagnostic, ShellError};
use nu_protocol::hir::{ClassifiedCommand, Expression, InternalCommand, Literal, NamedArguments}; use nu_protocol::hir::{ClassifiedCommand, Expression, InternalCommand, Literal, NamedArguments};
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
@ -591,7 +591,20 @@ pub async fn cli(
rl.set_helper(Some(crate::shell::Helper::new(context.clone()))); rl.set_helper(Some(crate::shell::Helper::new(context.clone())));
let config = config::config(Tag::unknown())?; let config = match config::config(Tag::unknown()) {
Ok(config) => config,
Err(e) => {
eprintln!("Config could not be loaded.");
if let ShellError {
error: ProximateShellError::Diagnostic(ShellDiagnostic { diagnostic }),
..
} = e
{
eprintln!("{}", diagnostic.message);
}
IndexMap::new()
}
};
let use_starship = match config.get("use_starship") { let use_starship = match config.get("use_starship") {
Some(b) => match b.as_bool() { Some(b) => match b.as_bool() {
@ -657,9 +670,10 @@ pub async fn cli(
} else if let Some(prompt) = config.get("prompt") { } else if let Some(prompt) = config.get("prompt") {
let prompt_line = prompt.as_string()?; let prompt_line = prompt.as_string()?;
if let Ok(result) = nu_parser::lite_parse(&prompt_line, 0).map_err(ShellError::from) match nu_parser::lite_parse(&prompt_line, 0).map_err(ShellError::from) {
{ Ok(result) => {
let mut prompt_block = nu_parser::classify_block(&result, context.registry()); let mut prompt_block =
nu_parser::classify_block(&result, context.registry());
let env = context.get_env(); let env = context.get_env();
@ -675,28 +689,39 @@ pub async fn cli(
) )
.await .await
{ {
Ok(result) => { Ok(result) => match result.collect_string(Tag::unknown()).await {
context.clear_errors(); Ok(string_result) => {
let errors = context.get_errors();
match result.collect_string(Tag::unknown()).await {
Ok(string_result) => string_result.item,
Err(_) => {
context.maybe_print_errors(Text::from(prompt_line)); context.maybe_print_errors(Text::from(prompt_line));
context.clear_errors(); context.clear_errors();
"Error running prompt> ".to_string() if !errors.is_empty() {
} "> ".to_string()
}
}
Err(_) => {
context.maybe_print_errors(Text::from(prompt_line));
context.clear_errors();
"Error running prompt> ".to_string()
}
}
} else { } else {
"Error parsing prompt> ".to_string() string_result.item
}
}
Err(e) => {
crate::cli::print_err(e, &Text::from(prompt_line));
context.clear_errors();
"> ".to_string()
}
},
Err(e) => {
crate::cli::print_err(e, &Text::from(prompt_line));
context.clear_errors();
"> ".to_string()
}
}
}
Err(e) => {
crate::cli::print_err(e, &Text::from(prompt_line));
context.clear_errors();
"> ".to_string()
}
} }
} else { } else {
format!( format!(

View File

@ -72,7 +72,7 @@ async fn do_(
}, },
input, input,
) = raw_args.process(&registry).await?; ) = raw_args.process(&registry).await?;
block.set_is_last(!is_last); block.set_is_last(is_last);
let result = run_block( let result = run_block(
&block, &block,

View File

@ -41,7 +41,7 @@ impl WholeStreamCommand for AliasCommand {
let call_info = args.call_info.clone(); let call_info = args.call_info.clone();
let registry = registry.clone(); let registry = registry.clone();
let mut block = self.block.clone(); let mut block = self.block.clone();
block.set_is_last(!call_info.args.is_last); block.set_is_last(call_info.args.is_last);
let alias_command = self.clone(); let alias_command = self.clone();
let mut context = Context::from_args(&args, &registry); let mut context = Context::from_args(&args, &registry);

View File

@ -74,6 +74,12 @@ impl InputStream {
value_tag = value_t; value_tag = value_t;
bytes.extend_from_slice(&b); bytes.extend_from_slice(&b);
} }
Some(Value {
value: UntaggedValue::Primitive(Primitive::Nothing),
tag: value_t,
}) => {
value_tag = value_t;
}
Some(Value { Some(Value {
tag: value_tag, tag: value_tag,
value, value,

View File

@ -177,8 +177,8 @@ impl PrettyDebug for ArgumentError {
/// creating a cause chain. /// creating a cause chain.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize, Hash)] #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize, Hash)]
pub struct ShellError { pub struct ShellError {
error: ProximateShellError, pub error: ProximateShellError,
cause: Option<Box<ShellError>>, pub cause: Option<Box<ShellError>>,
} }
/// `PrettyDebug` is for internal debugging. For user-facing debugging, [into_diagnostic](ShellError::into_diagnostic) /// `PrettyDebug` is for internal debugging. For user-facing debugging, [into_diagnostic](ShellError::into_diagnostic)
@ -773,7 +773,7 @@ impl HasFallibleSpan for ProximateShellError {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShellDiagnostic { pub struct ShellDiagnostic {
pub(crate) diagnostic: Diagnostic<usize>, pub diagnostic: Diagnostic<usize>,
} }
impl std::hash::Hash for ShellDiagnostic { impl std::hash::Hash for ShellDiagnostic {