mirror of
https://github.com/nushell/nushell.git
synced 2025-04-01 03:36:53 +02:00
WIP (#2077)
This commit is contained in:
parent
3f170c7fb8
commit
bcddeb3c1f
@ -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!(
|
||||||
|
@ -72,7 +72,7 @@ async fn do_(
|
|||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
) = raw_args.process(®istry).await?;
|
) = raw_args.process(®istry).await?;
|
||||||
block.set_is_last(!is_last);
|
block.set_is_last(is_last);
|
||||||
|
|
||||||
let result = run_block(
|
let result = run_block(
|
||||||
&block,
|
&block,
|
||||||
|
@ -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, ®istry);
|
let mut context = Context::from_args(&args, ®istry);
|
||||||
|
@ -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,
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user