mirror of
https://github.com/nushell/nushell.git
synced 2024-11-29 20:03:54 +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 crate::prelude::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -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> {
|
||||||
|
@ -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> {
|
||||||
|
@ -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>(
|
||||||
|
@ -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> {
|
||||||
|
@ -45,7 +45,8 @@ 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(
|
||||||
|
move |a| match serde_json::to_string(&value_to_json_value(&a)) {
|
||||||
Ok(x) => {
|
Ok(x) => {
|
||||||
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
|
ReturnSuccess::value(Value::Primitive(Primitive::String(x)).spanned(name_span))
|
||||||
}
|
}
|
||||||
@ -54,6 +55,7 @@ pub fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
"can not convert piped data to JSON string",
|
"can not convert piped data to JSON string",
|
||||||
name_span,
|
name_span,
|
||||||
)),
|
)),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.to_output_stream())
|
.to_output_stream())
|
||||||
}
|
}
|
||||||
|
@ -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),
|
||||||
|
@ -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)]
|
||||||
|
@ -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(
|
||||||
|
@ -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};
|
||||||
|
Loading…
Reference in New Issue
Block a user