mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
Remove more dead code and clean up JSON
This commit is contained in:
parent
7c2a1c619e
commit
6bf55c0f1e
@ -1,4 +1,4 @@
|
||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||
use crate::object::{Primitive, SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::object::base::OF64;
|
||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||
use crate::object::{Primitive, SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
fn convert_json_value_to_nu_value(v: &serde_hjson::Value, span: impl Into<Span>) -> Spanned<Value> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::object::base::OF64;
|
||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||
use crate::object::{Primitive, SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
fn convert_toml_value_to_nu_value(v: &toml::Value, span: impl Into<Span>) -> Spanned<Value> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||
use crate::object::{Primitive, SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
fn from_node_to_value<'a, 'd>(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::object::base::OF64;
|
||||
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value};
|
||||
use crate::object::{Primitive, SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, span: impl Into<Span>) -> Spanned<Value> {
|
||||
|
@ -45,15 +45,17 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name_span = args.name_span;
|
||||
Ok(out
|
||||
.values
|
||||
.map(move |a| match serde_json::to_string(&a) {
|
||||
Ok(x) => {
|
||||
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
|
||||
}
|
||||
Err(_) => Err(ShellError::maybe_labeled_error(
|
||||
"Can not convert to JSON string",
|
||||
"can not convert piped data to JSON string",
|
||||
name_span,
|
||||
)),
|
||||
})
|
||||
.map(
|
||||
move |a| match serde_json::to_string(&value_to_json_value(&a)) {
|
||||
Ok(x) => {
|
||||
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
|
||||
}
|
||||
Err(_) => Err(ShellError::maybe_labeled_error(
|
||||
"Can not convert to JSON string",
|
||||
"can not convert piped data to JSON string",
|
||||
name_span,
|
||||
)),
|
||||
},
|
||||
)
|
||||
.to_output_stream())
|
||||
}
|
||||
|
@ -72,20 +72,6 @@ impl PartialEq<Value> for Dictionary {
|
||||
}
|
||||
|
||||
impl Dictionary {
|
||||
crate fn add(&mut self, name: impl Into<String>, value: impl Into<Spanned<Value>>) {
|
||||
self.entries.insert(name.into(), value.into());
|
||||
}
|
||||
|
||||
crate fn copy_dict(&self) -> Dictionary {
|
||||
let mut out = Dictionary::default();
|
||||
|
||||
for (key, value) in self.entries.iter() {
|
||||
out.add(key.clone(), value.clone());
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> {
|
||||
match self.entries.get(desc) {
|
||||
Some(v) => MaybeOwned::Borrowed(v),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::{Dictionary, SpannedDictBuilder, Value};
|
||||
use crate::object::{SpannedDictBuilder, Value};
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::Text;
|
||||
use derive_new::new;
|
||||
use getset::Getters;
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::Serialize;
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(
|
||||
|
@ -40,7 +40,7 @@ crate use crate::context::Context;
|
||||
crate use crate::env::host::handle_unexpected;
|
||||
crate use crate::env::{Environment, Host};
|
||||
crate use crate::errors::ShellError;
|
||||
crate use crate::object::types::{ExtractType, Type};
|
||||
crate use crate::object::types::ExtractType;
|
||||
crate use crate::object::{Primitive, Value};
|
||||
crate use crate::parser::{Span, Spanned, SpannedItem};
|
||||
crate use crate::stream::{InputStream, OutputStream};
|
||||
|
Loading…
Reference in New Issue
Block a user