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()
|
self.members.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_last(&self) -> (&PathMember, &[PathMember]) {
|
pub fn split_last(&self) -> Option<(&PathMember, &[PathMember])> {
|
||||||
self.members.split_last().unwrap()
|
self.members.split_last()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,8 +414,7 @@ pub trait PrettyDebug {
|
|||||||
let doc = self.pretty_doc();
|
let doc = self.pretty_doc();
|
||||||
let mut buffer = termcolor::Buffer::no_color();
|
let mut buffer = termcolor::Buffer::no_color();
|
||||||
|
|
||||||
doc.render_raw(width, &mut TermColored::new(&mut buffer))
|
let _ = doc.render_raw(width, &mut TermColored::new(&mut buffer));
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
||||||
}
|
}
|
||||||
@ -424,8 +423,7 @@ pub trait PrettyDebug {
|
|||||||
let doc = self.pretty_doc();
|
let doc = self.pretty_doc();
|
||||||
let mut buffer = termcolor::Buffer::ansi();
|
let mut buffer = termcolor::Buffer::ansi();
|
||||||
|
|
||||||
doc.render_raw(width, &mut TermColored::new(&mut buffer))
|
let _ = doc.render_raw(width, &mut TermColored::new(&mut buffer));
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
String::from_utf8_lossy(buffer.as_slice()).to_string()
|
||||||
}
|
}
|
||||||
|
@ -291,25 +291,30 @@ pub fn insert_data_at_column_path(
|
|||||||
split_path: &ColumnPath,
|
split_path: &ColumnPath,
|
||||||
new_value: Value,
|
new_value: Value,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let (last, front) = split_path.split_last();
|
if let Some((last, front)) = split_path.split_last() {
|
||||||
let mut original = value.clone();
|
let mut original = value.clone();
|
||||||
|
|
||||||
let mut current: &mut Value = &mut original;
|
let mut current: &mut Value = &mut original;
|
||||||
|
|
||||||
for member in front {
|
for member in front {
|
||||||
let type_name = current.spanned_type_name();
|
let type_name = current.spanned_type_name();
|
||||||
|
|
||||||
current = get_mut_data_by_member(current, &member).ok_or_else(|| {
|
current = get_mut_data_by_member(current, &member).ok_or_else(|| {
|
||||||
ShellError::missing_property(
|
ShellError::missing_property(
|
||||||
member.plain_string(std::usize::MAX).spanned(member.span),
|
member.plain_string(std::usize::MAX).spanned(member.span),
|
||||||
type_name,
|
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(
|
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 doc = PrettyDebug::pretty_doc(&v);
|
||||||
let mut buffer = termcolor::Buffer::ansi();
|
let mut buffer = termcolor::Buffer::ansi();
|
||||||
|
|
||||||
doc.render_raw(
|
let _ = doc.render_raw(
|
||||||
context.with_host(|host| host.width() - 5),
|
context.with_host(|host| host.width() - 5),
|
||||||
&mut nu_source::TermColored::new(&mut buffer),
|
&mut nu_source::TermColored::new(&mut buffer),
|
||||||
).unwrap();
|
);
|
||||||
|
|
||||||
let value = String::from_utf8_lossy(buffer.as_slice());
|
let value = String::from_utf8_lossy(buffer.as_slice());
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ pub fn config(
|
|||||||
|
|
||||||
if result.contains_key(&key) {
|
if result.contains_key(&key) {
|
||||||
result.swap_remove(&key);
|
result.swap_remove(&key);
|
||||||
config::write(&result, &configuration).unwrap();
|
config::write(&result, &configuration)?
|
||||||
} else {
|
} else {
|
||||||
yield Err(ShellError::labeled_error(
|
yield Err(ShellError::labeled_error(
|
||||||
"Key does not exist in config",
|
"Key does not exist in config",
|
||||||
|
@ -38,7 +38,7 @@ impl PerItemCommand for Edit {
|
|||||||
value: Value,
|
value: Value,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let value_tag = value.tag();
|
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 replacement = call_info.args.expect_nth(1)?.tagged_unknown();
|
||||||
|
|
||||||
let stream = match value {
|
let stream = match value {
|
||||||
|
@ -37,9 +37,17 @@ impl PerItemCommand for Format {
|
|||||||
value: Value,
|
value: Value,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
//let value_tag = value.tag();
|
//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 commands = format_pattern.1;
|
||||||
|
|
||||||
let output = if let Value {
|
let output = if let Value {
|
||||||
|
@ -178,7 +178,7 @@ fn save(
|
|||||||
let content : Result<Vec<u8>, ShellError> = 'scope: loop {
|
let content : Result<Vec<u8>, ShellError> = 'scope: loop {
|
||||||
break if !save_raw {
|
break if !save_raw {
|
||||||
if let Some(extension) = full_path.extension() {
|
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) {
|
if let Some(converter) = registry.get_command(&command_name) {
|
||||||
let new_args = RawCommandArgs {
|
let new_args = RawCommandArgs {
|
||||||
host,
|
host,
|
||||||
|
@ -39,7 +39,12 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
|||||||
let host = args.host.clone();
|
let host = args.host.clone();
|
||||||
let start_number = match args.get("start_number") {
|
let start_number = match args.get("start_number") {
|
||||||
Some(Value { value: UntaggedValue::Primitive(Primitive::Int(i)), .. }) => {
|
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
|
0
|
||||||
|
Loading…
Reference in New Issue
Block a user