mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
toml
This commit is contained in:
parent
992522af66
commit
500192a642
40
Cargo.lock
generated
40
Cargo.lock
generated
@ -81,12 +81,6 @@ version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
|
||||
[[package]]
|
||||
name = "ascii"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
|
||||
|
||||
[[package]]
|
||||
name = "async-attributes"
|
||||
version = "1.1.1"
|
||||
@ -495,19 +489,6 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "3.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
|
||||
dependencies = [
|
||||
"ascii",
|
||||
"byteorder",
|
||||
"either",
|
||||
"memchr",
|
||||
"unreachable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "config"
|
||||
version = "0.9.3"
|
||||
@ -2301,7 +2282,6 @@ dependencies = [
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"toml 0.5.6",
|
||||
"toml_edit",
|
||||
"trash",
|
||||
"typetag",
|
||||
"umask",
|
||||
@ -3984,17 +3964,6 @@ dependencies = [
|
||||
"serde 1.0.110",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09391a441b373597cf0888d2b052dcf82c5be4fee05da3636ae30fb57aad8484"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"combine",
|
||||
"linked-hash-map 0.5.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trash"
|
||||
version = "1.0.1"
|
||||
@ -4097,15 +4066,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
dependencies = [
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uom"
|
||||
version = "0.26.0"
|
||||
|
@ -82,7 +82,6 @@ term = "0.5.2"
|
||||
termcolor = "1.1.0"
|
||||
textwrap = {version = "0.11.0", features = ["term_size"]}
|
||||
toml = "0.5.6"
|
||||
toml_edit = "0.2.0"
|
||||
typetag = "0.1.4"
|
||||
umask = "1.0.0"
|
||||
unicode-xid = "0.2.0"
|
||||
|
@ -1,20 +1,11 @@
|
||||
use crate::commands::WholeStreamCommand;
|
||||
use crate::data::value::format_leaf;
|
||||
use crate::prelude::*;
|
||||
use directories::ProjectDirs;
|
||||
use futures::StreamExt;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value};
|
||||
use nu_source::AnchorLocation;
|
||||
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io::Write;
|
||||
use toml_edit::{Document, value};
|
||||
use std::io::Read;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
fs::{self, OpenOptions},
|
||||
path::PathBuf,
|
||||
};
|
||||
use std::io::{Read, Write};
|
||||
use std::{collections::hash_map::DefaultHasher, fs, path::PathBuf};
|
||||
use serde_derive::Serialize;
|
||||
|
||||
pub struct AutoenvTrust;
|
||||
|
||||
@ -44,42 +35,28 @@ impl WholeStreamCommand for AutoenvTrust {
|
||||
|
||||
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(config_path.clone())?;
|
||||
.write(true)
|
||||
.open(config_path.clone())
|
||||
.unwrap();
|
||||
let mut doc = String::new();
|
||||
file.read_to_string(&mut doc)?;
|
||||
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
let mut toml_doc = doc.parse::<toml::Value>().unwrap();
|
||||
let mut empty = toml::value::Value::Table(toml::value::Table::new());
|
||||
toml_doc
|
||||
.get_mut("allowed-files")
|
||||
.unwrap_or_else(|| &mut empty)
|
||||
.as_table_mut()
|
||||
.unwrap()
|
||||
.insert(
|
||||
current_dir.to_string_lossy().to_string(),
|
||||
toml::Value::try_from(hasher.finish().to_string())?,
|
||||
);
|
||||
|
||||
let mut toml_table =
|
||||
match std::fs::read_to_string(config_path.clone())?.parse::<toml::Value>() {
|
||||
Ok(toml_doc) => {
|
||||
let table = match toml_doc.get("allowed-files") {
|
||||
Some(v) => v.clone(),
|
||||
None => r#"[allowed-files]"#.parse::<toml::Value>().unwrap(),
|
||||
};
|
||||
|
||||
table.as_table().unwrap().clone()
|
||||
}
|
||||
Err(_) => {
|
||||
let mut table = toml::value::Table::new();
|
||||
table.insert("allowed-files".to_string(), toml::Value::from(""));
|
||||
table
|
||||
|
||||
// let table = "[allowed-files]".parse::<toml::Value>().unwrap();
|
||||
// table.as_table().unwrap().clone()
|
||||
}
|
||||
};
|
||||
|
||||
toml_table.insert(
|
||||
current_dir.to_string_lossy().to_string(),
|
||||
toml::Value::try_from(hasher.finish().to_string())?,
|
||||
);
|
||||
let toml_string: String = toml::to_string(&toml_table).expect(";");
|
||||
|
||||
fs::write(config_path, toml_string).expect("Couldn't write to toml file");
|
||||
fs::write(config_path, toml_doc.as_str().unwrap()).expect("Couldn't write to toml file");
|
||||
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
Ok(OutputStream::one(ReturnSuccess::value(
|
||||
|
Loading…
Reference in New Issue
Block a user