Remove more dead code and clean up JSON

This commit is contained in:
Yehuda Katz 2019-07-12 19:18:02 -07:00
parent 7c2a1c619e
commit 6bf55c0f1e
10 changed files with 20 additions and 32 deletions

View File

@ -1,4 +1,4 @@
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64; use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
fn convert_json_value_to_nu_value(v: &serde_hjson::Value, span: impl Into<Span>) -> Spanned<Value> { fn convert_json_value_to_nu_value(v: &serde_hjson::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64; use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
fn convert_toml_value_to_nu_value(v: &toml::Value, span: impl Into<Span>) -> Spanned<Value> { fn convert_toml_value_to_nu_value(v: &toml::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -1,4 +1,4 @@
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
fn from_node_to_value<'a, 'd>( fn from_node_to_value<'a, 'd>(

View File

@ -1,5 +1,5 @@
use crate::object::base::OF64; use crate::object::base::OF64;
use crate::object::{Dictionary, Primitive, SpannedDictBuilder, Value}; use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, span: impl Into<Span>) -> Spanned<Value> { fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, span: impl Into<Span>) -> Spanned<Value> {

View File

@ -45,15 +45,17 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
let name_span = args.name_span; let name_span = args.name_span;
Ok(out Ok(out
.values .values
.map(move |a| match serde_json::to_string(&a) { .map(
Ok(x) => { move |a| match serde_json::to_string(&value_to_json_value(&a)) {
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span)) Ok(x) => {
} ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
Err(_) => Err(ShellError::maybe_labeled_error( }
"Can not convert to JSON string", Err(_) => Err(ShellError::maybe_labeled_error(
"can not convert piped data to JSON string", "Can not convert to JSON string",
name_span, "can not convert piped data to JSON string",
)), name_span,
}) )),
},
)
.to_output_stream()) .to_output_stream())
} }

View File

@ -72,20 +72,6 @@ impl PartialEq<Value> for Dictionary {
} }
impl 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> { pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> {
match self.entries.get(desc) { match self.entries.get(desc) {
Some(v) => MaybeOwned::Borrowed(v), Some(v) => MaybeOwned::Borrowed(v),

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::{Dictionary, SpannedDictBuilder, Value}; use crate::object::{SpannedDictBuilder, Value};
use crate::prelude::*; use crate::prelude::*;
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,7 +1,7 @@
use crate::Text; use crate::Text;
use derive_new::new; use derive_new::new;
use getset::Getters; use getset::Getters;
use serde::{Serialize, Serializer}; use serde::Serialize;
use serde_derive::Deserialize; use serde_derive::Deserialize;
#[derive( #[derive(

View File

@ -40,7 +40,7 @@ crate use crate::context::Context;
crate use crate::env::host::handle_unexpected; crate use crate::env::host::handle_unexpected;
crate use crate::env::{Environment, Host}; crate use crate::env::{Environment, Host};
crate use crate::errors::ShellError; 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::object::{Primitive, Value};
crate use crate::parser::{Span, Spanned, SpannedItem}; crate use crate::parser::{Span, Spanned, SpannedItem};
crate use crate::stream::{InputStream, OutputStream}; crate use crate::stream::{InputStream, OutputStream};