forked from extern/nushell
Removes export env
command (#6468)
* remove export_env command * remove several export env usage in test code * adjust hiding relative test case * fix clippy * adjust tests * update tests * unignore these tests to expose ut failed * using `use` instead of `overlay use` in some tests * Revert "using `use` instead of `overlay use` in some tests" This reverts commit2ae24b24c3
. * Revert "adjust hiding relative test case" This reverts commit4369af6d05
. * Bring back module example * Revert "update tests" This reverts commit6ae94ef513
. * Fix tests * "Fix" a test * Remove remaining deprecated env functionality * Re-enable environment hiding for `hide` To not break virtualenv since the overlay update is not merged yet * Fix hiding env in `hide` and ignore some tests Co-authored-by: kubouch <kubouch@gmail.com>
This commit is contained in:
@ -178,39 +178,6 @@ impl Stack {
|
||||
result
|
||||
}
|
||||
|
||||
/// Flatten the env var scope frames into one frame, only from one overlay
|
||||
pub fn get_overlay_env_vars(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
overlay_name: &str,
|
||||
) -> HashMap<String, Value> {
|
||||
let mut result = HashMap::new();
|
||||
|
||||
// for active_overlay in self.active_overlays.iter() {
|
||||
if let Some(active_overlay) = self.active_overlays.iter().find(|n| n == &overlay_name) {
|
||||
if let Some(env_vars) = engine_state.env_vars.get(active_overlay) {
|
||||
result.extend(
|
||||
env_vars
|
||||
.iter()
|
||||
.filter(|(k, _)| {
|
||||
if let Some(env_hidden) = self.env_hidden.get(active_overlay) {
|
||||
!env_hidden.contains(*k)
|
||||
} else {
|
||||
// nothing has been hidden in this overlay
|
||||
true
|
||||
}
|
||||
})
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect::<HashMap<String, Value>>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
result.extend(self.get_stack_overlay_env_vars(overlay_name));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Get flattened environment variables only from the stack
|
||||
pub fn get_stack_env_vars(&self) -> HashMap<String, Value> {
|
||||
let mut result = HashMap::new();
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::{AliasId, BlockId, DeclId};
|
||||
use crate::{AliasId, DeclId};
|
||||
|
||||
pub enum Exportable {
|
||||
Decl { name: Vec<u8>, id: DeclId },
|
||||
Alias { name: Vec<u8>, id: AliasId },
|
||||
EnvVar { name: Vec<u8>, id: BlockId },
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use indexmap::IndexMap;
|
||||
pub struct Module {
|
||||
pub decls: IndexMap<Vec<u8>, DeclId>,
|
||||
pub aliases: IndexMap<Vec<u8>, AliasId>,
|
||||
pub env_vars: IndexMap<Vec<u8>, BlockId>,
|
||||
pub env_block: Option<BlockId>,
|
||||
pub span: Option<Span>,
|
||||
}
|
||||
@ -20,7 +19,6 @@ impl Module {
|
||||
Module {
|
||||
decls: IndexMap::new(),
|
||||
aliases: IndexMap::new(),
|
||||
env_vars: IndexMap::new(),
|
||||
env_block: None,
|
||||
span: None,
|
||||
}
|
||||
@ -30,7 +28,6 @@ impl Module {
|
||||
Module {
|
||||
decls: IndexMap::new(),
|
||||
aliases: IndexMap::new(),
|
||||
env_vars: IndexMap::new(),
|
||||
env_block: None,
|
||||
span: Some(span),
|
||||
}
|
||||
@ -44,21 +41,17 @@ impl Module {
|
||||
self.aliases.insert(name, alias_id)
|
||||
}
|
||||
|
||||
pub fn add_env_var(&mut self, name: Vec<u8>, block_id: BlockId) -> Option<BlockId> {
|
||||
self.env_vars.insert(name, block_id)
|
||||
}
|
||||
|
||||
pub fn add_env_block(&mut self, block_id: BlockId) {
|
||||
self.env_block = Some(block_id);
|
||||
}
|
||||
|
||||
pub fn extend(&mut self, other: &Module) {
|
||||
self.decls.extend(other.decls.clone());
|
||||
self.env_vars.extend(other.env_vars.clone());
|
||||
self.aliases.extend(other.aliases.clone());
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.decls.is_empty() && self.env_vars.is_empty()
|
||||
self.decls.is_empty() && self.aliases.is_empty()
|
||||
}
|
||||
|
||||
pub fn get_decl_id(&self, name: &[u8]) -> Option<DeclId> {
|
||||
@ -168,44 +161,6 @@ impl Module {
|
||||
.map(|(name, id)| (name.clone(), *id))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_env_var_id(&self, name: &[u8]) -> Option<BlockId> {
|
||||
self.env_vars.get(name).copied()
|
||||
}
|
||||
|
||||
pub fn has_env_var(&self, name: &[u8]) -> bool {
|
||||
self.env_vars.contains_key(name)
|
||||
}
|
||||
|
||||
pub fn env_var_with_head(&self, name: &[u8], head: &[u8]) -> Option<(Vec<u8>, BlockId)> {
|
||||
if let Some(id) = self.get_env_var_id(name) {
|
||||
let mut new_name = head.to_vec();
|
||||
new_name.push(b' ');
|
||||
new_name.extend(name);
|
||||
Some((new_name, id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn env_vars_with_head(&self, head: &[u8]) -> Vec<(Vec<u8>, BlockId)> {
|
||||
self.env_vars
|
||||
.iter()
|
||||
.map(|(name, id)| {
|
||||
let mut new_name = head.to_vec();
|
||||
new_name.push(b' ');
|
||||
new_name.extend(name);
|
||||
(new_name, *id)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn env_vars(&self) -> Vec<(Vec<u8>, BlockId)> {
|
||||
self.env_vars
|
||||
.iter()
|
||||
.map(|(name, id)| (name.clone(), *id))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Module {
|
||||
|
Reference in New Issue
Block a user