Removing vals not working, strangely

This commit is contained in:
Sam Hedin 2020-06-04 04:37:02 +02:00
parent c67d93dae1
commit de0c252e27
2 changed files with 21 additions and 4 deletions

View File

@ -1,11 +1,13 @@
use crate::data::config::Conf;
use indexmap::{indexmap, IndexSet};
use nu_protocol::{UntaggedValue, Value};
use std::collections::HashMap;
use std::collections::{HashMap};
use indexmap::IndexMap;
use std::ffi::OsString;
use std::fmt::Debug;
use std::fs::File;
use std::io::prelude::*;
use std::io::Write;
use std::path::PathBuf;
pub trait Env: Debug + Send {
@ -68,8 +70,12 @@ impl Environment {
//TODO: handle errors
pub fn maintain_nurc_environment_vars(&mut self) {
self.clear_vars_from_unvisited_dirs();
self.add_nurc();
match self.clear_vars_from_unvisited_dirs() {
_ => {}
};
match self.add_nurc() {
_ => {}
};
}
pub fn add_nurc(&mut self) -> std::io::Result<()> {
@ -125,13 +131,20 @@ impl Environment {
}
// environment_vars: Option<Value>,
//
pub fn remove_env(&mut self, key: &str) {
if let Some(Value {
value: UntaggedValue::Row(envs),
tag: _,
}) = &mut self.environment_vars
{
envs.entries.remove(key);
let mut file = File::create("env.txt").unwrap();
write!(&mut file, "env: {:?}", envs.entries).unwrap();
let mut file = File::create("removenv.txt").unwrap();
let removed = envs.remove_key(key);
write!(&mut file, "removed {:?}", (key, removed)).unwrap();
}
}

View File

@ -159,6 +159,10 @@ impl Dictionary {
self.entries.contains_key(key)
}
pub fn remove_key(&mut self, key: &str) -> Option<Value> {
self.entries.remove(key)
}
/// Find the matching Value for a key, if possible
pub fn get_data_by_key(&self, name: Spanned<&str>) -> Option<Value> {
let result = self