forked from extern/nushell
A couple more (#1149)
This commit is contained in:
parent
0f626dd076
commit
5e31851070
@ -48,8 +48,8 @@ impl ColumnPath {
|
||||
self.members.iter()
|
||||
}
|
||||
|
||||
pub fn split_last(&self) -> (&PathMember, &[PathMember]) {
|
||||
self.members.split_last().unwrap()
|
||||
pub fn split_last(&self) -> Option<(&PathMember, &[PathMember])> {
|
||||
self.members.split_last()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,8 +414,7 @@ pub trait PrettyDebug {
|
||||
let doc = self.pretty_doc();
|
||||
let mut buffer = termcolor::Buffer::no_color();
|
||||
|
||||
doc.render_raw(width, &mut TermColored::new(&mut buffer))
|
||||
.unwrap();
|
||||
let _ = doc.render_raw(width, &mut TermColored::new(&mut buffer));
|
||||
|
||||
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
||||
}
|
||||
@ -424,8 +423,7 @@ pub trait PrettyDebug {
|
||||
let doc = self.pretty_doc();
|
||||
let mut buffer = termcolor::Buffer::ansi();
|
||||
|
||||
doc.render_raw(width, &mut TermColored::new(&mut buffer))
|
||||
.unwrap();
|
||||
let _ = doc.render_raw(width, &mut TermColored::new(&mut buffer));
|
||||
|
||||
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
||||
}
|
||||
|
@ -291,25 +291,30 @@ pub fn insert_data_at_column_path(
|
||||
split_path: &ColumnPath,
|
||||
new_value: Value,
|
||||
) -> Result<Value, ShellError> {
|
||||
let (last, front) = split_path.split_last();
|
||||
let mut original = value.clone();
|
||||
if let Some((last, front)) = split_path.split_last() {
|
||||
let mut original = value.clone();
|
||||
|
||||
let mut current: &mut Value = &mut original;
|
||||
let mut current: &mut Value = &mut original;
|
||||
|
||||
for member in front {
|
||||
let type_name = current.spanned_type_name();
|
||||
for member in front {
|
||||
let type_name = current.spanned_type_name();
|
||||
|
||||
current = get_mut_data_by_member(current, &member).ok_or_else(|| {
|
||||
ShellError::missing_property(
|
||||
member.plain_string(std::usize::MAX).spanned(member.span),
|
||||
type_name,
|
||||
)
|
||||
})?
|
||||
current = get_mut_data_by_member(current, &member).ok_or_else(|| {
|
||||
ShellError::missing_property(
|
||||
member.plain_string(std::usize::MAX).spanned(member.span),
|
||||
type_name,
|
||||
)
|
||||
})?
|
||||
}
|
||||
|
||||
insert_data_at_member(current, &last, new_value)?;
|
||||
|
||||
Ok(original)
|
||||
} else {
|
||||
Err(ShellError::untagged_runtime_error(
|
||||
"Internal error: could not split column-path correctly",
|
||||
))
|
||||
}
|
||||
|
||||
insert_data_at_member(current, &last, new_value)?;
|
||||
|
||||
Ok(original)
|
||||
}
|
||||
|
||||
pub fn replace_data_at_column_path(
|
||||
|
@ -148,10 +148,10 @@ pub(crate) async fn run_internal_command(
|
||||
let doc = PrettyDebug::pretty_doc(&v);
|
||||
let mut buffer = termcolor::Buffer::ansi();
|
||||
|
||||
doc.render_raw(
|
||||
let _ = doc.render_raw(
|
||||
context.with_host(|host| host.width() - 5),
|
||||
&mut nu_source::TermColored::new(&mut buffer),
|
||||
).unwrap();
|
||||
);
|
||||
|
||||
let value = String::from_utf8_lossy(buffer.as_slice());
|
||||
|
||||
|
@ -155,7 +155,7 @@ pub fn config(
|
||||
|
||||
if result.contains_key(&key) {
|
||||
result.swap_remove(&key);
|
||||
config::write(&result, &configuration).unwrap();
|
||||
config::write(&result, &configuration)?
|
||||
} else {
|
||||
yield Err(ShellError::labeled_error(
|
||||
"Key does not exist in config",
|
||||
|
@ -38,7 +38,7 @@ impl PerItemCommand for Edit {
|
||||
value: Value,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let value_tag = value.tag();
|
||||
let field = call_info.args.expect_nth(0)?.as_column_path().unwrap();
|
||||
let field = call_info.args.expect_nth(0)?.as_column_path()?;
|
||||
let replacement = call_info.args.expect_nth(1)?.tagged_unknown();
|
||||
|
||||
let stream = match value {
|
||||
|
@ -37,9 +37,17 @@ impl PerItemCommand for Format {
|
||||
value: Value,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
//let value_tag = value.tag();
|
||||
let pattern = call_info.args.expect_nth(0)?.as_string().unwrap();
|
||||
let pattern = call_info.args.expect_nth(0)?;
|
||||
let pattern_tag = pattern.tag.clone();
|
||||
let pattern = pattern.as_string()?;
|
||||
|
||||
let format_pattern = format(&pattern).unwrap();
|
||||
let format_pattern = format(&pattern).map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not create format pattern",
|
||||
"could not create format pattern",
|
||||
pattern_tag,
|
||||
)
|
||||
})?;
|
||||
let commands = format_pattern.1;
|
||||
|
||||
let output = if let Value {
|
||||
|
@ -178,7 +178,7 @@ fn save(
|
||||
let content : Result<Vec<u8>, ShellError> = 'scope: loop {
|
||||
break if !save_raw {
|
||||
if let Some(extension) = full_path.extension() {
|
||||
let command_name = format!("to-{}", extension.to_str().unwrap());
|
||||
let command_name = format!("to-{}", extension.to_string_lossy());
|
||||
if let Some(converter) = registry.get_command(&command_name) {
|
||||
let new_args = RawCommandArgs {
|
||||
host,
|
||||
|
@ -39,7 +39,12 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
||||
let host = args.host.clone();
|
||||
let start_number = match args.get("start_number") {
|
||||
Some(Value { value: UntaggedValue::Primitive(Primitive::Int(i)), .. }) => {
|
||||
i.to_usize().unwrap()
|
||||
if let Some(num) = i.to_usize() {
|
||||
num
|
||||
} else {
|
||||
yield Err(ShellError::labeled_error("Expected a row number", "expected a row number", &args.args.call_info.name_tag));
|
||||
0
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
0
|
||||
|
Loading…
Reference in New Issue
Block a user