mirror of
https://github.com/nushell/nushell
synced 2024-12-26 21:13:19 +00:00
Add lines and improve split
This commit is contained in:
parent
35ef78df67
commit
54301fe3be
5 changed files with 55 additions and 30 deletions
63
src/cli.rs
63
src/cli.rs
|
@ -64,6 +64,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||
command("open", open::open),
|
||||
command("enter", enter::enter),
|
||||
command("exit", exit::exit),
|
||||
command("lines", lines::lines),
|
||||
command("pick", pick::pick),
|
||||
command("split-column", split_column::split_column),
|
||||
command("split-row", split_row::split_row),
|
||||
|
@ -75,6 +76,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||
command("to-toml", to_toml::to_toml),
|
||||
Arc::new(Where),
|
||||
Arc::new(Config),
|
||||
Arc::new(SkipWhile),
|
||||
command("sort-by", sort_by::sort_by),
|
||||
]);
|
||||
|
||||
|
@ -147,36 +149,41 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
}
|
||||
|
||||
LineResult::Error(mut line, err) => match err {
|
||||
ShellError::Diagnostic(diag) => {
|
||||
let host = context.host.lock().unwrap();
|
||||
let writer = host.err_termcolor();
|
||||
line.push_str(" ");
|
||||
let files = crate::parser::span::Files::new(line);
|
||||
LineResult::Error(mut line, err) => {
|
||||
rl.add_history_entry(line.clone());
|
||||
match err {
|
||||
ShellError::Diagnostic(diag) => {
|
||||
let host = context.host.lock().unwrap();
|
||||
let writer = host.err_termcolor();
|
||||
line.push_str(" ");
|
||||
let files = crate::parser::span::Files::new(line);
|
||||
|
||||
language_reporting::emit(
|
||||
&mut writer.lock(),
|
||||
&files,
|
||||
&diag.diagnostic,
|
||||
&language_reporting::DefaultConfig,
|
||||
)
|
||||
.unwrap();
|
||||
language_reporting::emit(
|
||||
&mut writer.lock(),
|
||||
&files,
|
||||
&diag.diagnostic,
|
||||
&language_reporting::DefaultConfig,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
ShellError::TypeError(desc) => context
|
||||
.host
|
||||
.lock()
|
||||
.unwrap()
|
||||
.stdout(&format!("TypeError: {}", desc)),
|
||||
|
||||
ShellError::MissingProperty { subpath, .. } => context
|
||||
.host
|
||||
.lock()
|
||||
.unwrap()
|
||||
.stdout(&format!("Missing property {}", subpath)),
|
||||
|
||||
ShellError::String(_) => {
|
||||
context.host.lock().unwrap().stdout(&format!("{}", err))
|
||||
}
|
||||
}
|
||||
|
||||
ShellError::TypeError(desc) => context
|
||||
.host
|
||||
.lock()
|
||||
.unwrap()
|
||||
.stdout(&format!("TypeError: {}", desc)),
|
||||
|
||||
ShellError::MissingProperty { subpath, .. } => context
|
||||
.host
|
||||
.lock()
|
||||
.unwrap()
|
||||
.stdout(&format!("Missing property {}", subpath)),
|
||||
|
||||
ShellError::String(_) => context.host.lock().unwrap().stdout(&format!("{}", err)),
|
||||
},
|
||||
}
|
||||
|
||||
LineResult::Break => {
|
||||
break;
|
||||
|
|
|
@ -14,6 +14,7 @@ crate mod from_toml;
|
|||
crate mod from_xml;
|
||||
crate mod from_yaml;
|
||||
crate mod get;
|
||||
crate mod lines;
|
||||
crate mod ls;
|
||||
crate mod open;
|
||||
crate mod pick;
|
||||
|
@ -22,6 +23,7 @@ crate mod reject;
|
|||
crate mod save;
|
||||
crate mod size;
|
||||
crate mod skip;
|
||||
crate mod skip_while;
|
||||
crate mod sort_by;
|
||||
crate mod split_column;
|
||||
crate mod split_row;
|
||||
|
@ -38,3 +40,4 @@ crate use command::command;
|
|||
crate use config::Config;
|
||||
|
||||
crate use where_::Where;
|
||||
crate use skip_while::SkipWhile;
|
||||
|
|
|
@ -71,8 +71,8 @@ pub fn open(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
),
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"File cound not be opened",
|
||||
"file not found",
|
||||
"File could not be opened",
|
||||
"could not be opened",
|
||||
args.positional[0].span,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,13 @@ use log::trace;
|
|||
// TODO: "Amount remaining" wrapper
|
||||
|
||||
pub fn split_column(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
if args.positional.len() == 0 {
|
||||
return Err(ShellError::maybe_labeled_error(
|
||||
"Split-column needs more information",
|
||||
"needs parameter (eg split-column \",\")",
|
||||
args.name_span,
|
||||
));
|
||||
}
|
||||
let input = args.input;
|
||||
let span = args.name_span;
|
||||
let args = args.positional;
|
||||
|
|
|
@ -6,6 +6,14 @@ use log::trace;
|
|||
// TODO: "Amount remaining" wrapper
|
||||
|
||||
pub fn split_row(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
if args.positional.len() == 0 {
|
||||
return Err(ShellError::maybe_labeled_error(
|
||||
"Split-row needs more information",
|
||||
"needs parameter (eg split-row \"\\n\")",
|
||||
args.name_span,
|
||||
));
|
||||
}
|
||||
|
||||
let input = args.input;
|
||||
let span = args.name_span;
|
||||
let args = args.positional;
|
||||
|
|
Loading…
Reference in a new issue