forked from extern/nushell
Aliases (#1589)
* WIP getting scopes right * finish adding initial support * Finish with alias and add startup commands
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use crate::hir::Commands;
|
||||
use crate::value::Value;
|
||||
use nu_errors::ShellError;
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug};
|
||||
@ -20,6 +21,8 @@ pub enum CommandAction {
|
||||
EnterValueShell(Value),
|
||||
/// Enter the help shell, which allows exploring the help system
|
||||
EnterHelpShell(Value),
|
||||
/// Enter the help shell, which allows exploring the help system
|
||||
AddAlias(String, Vec<String>, Commands),
|
||||
/// Go to the previous shell in the shell ring buffer
|
||||
PreviousShell,
|
||||
/// Go to the next shell in the shell ring buffer
|
||||
@ -41,6 +44,7 @@ impl PrettyDebug for CommandAction {
|
||||
CommandAction::EnterShell(s) => b::typed("enter shell", b::description(s)),
|
||||
CommandAction::EnterValueShell(v) => b::typed("enter value shell", v.pretty()),
|
||||
CommandAction::EnterHelpShell(v) => b::typed("enter help shell", v.pretty()),
|
||||
CommandAction::AddAlias(..) => b::description("add alias"),
|
||||
CommandAction::PreviousShell => b::description("previous shell"),
|
||||
CommandAction::NextShell => b::description("next shell"),
|
||||
CommandAction::LeaveShell => b::description("leave shell"),
|
||||
|
@ -1,11 +1,12 @@
|
||||
use crate::value::{Primitive, UntaggedValue, Value};
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// An evaluation scope. Scopes map variable names to Values and aid in evaluating blocks and expressions.
|
||||
/// Additionally, holds the value for the special $it variable, a variable used to refer to the value passing
|
||||
/// through the pipeline at that moment
|
||||
#[derive(Debug)]
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
pub struct Scope {
|
||||
pub it: Value,
|
||||
pub vars: IndexMap<String, Value>,
|
||||
@ -37,4 +38,20 @@ impl Scope {
|
||||
vars: IndexMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_it(self, value: Value) -> Scope {
|
||||
Scope {
|
||||
it: value,
|
||||
vars: self.vars,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_var(self, name: String, value: Value) -> Scope {
|
||||
let mut new_vars = self.vars.clone();
|
||||
new_vars.insert(name, value);
|
||||
Scope {
|
||||
it: self.it,
|
||||
vars: new_vars,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user