Skip to content

Add UNSET command. Passing ALL removes all user-defined vars, can also u... #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CommandBasicIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ public override void Evaluate()
}
}

[CommandAttribute("UNSET %")]
public class CommandUnset : Command
{
public CommandUnset(Match regexMatch, ExecutionContext context) : base(regexMatch, context) { }

public override void Evaluate()
{
String varname = RegexMatch.Groups[1].Value;

if (varname.ToUpper() == "ALL")
{
ParentContext.UnsetAll();
}
else
{
ParentContext.Unset(varname);
}

State = ExecutionState.DONE;
}
}
[CommandAttribute("TOGGLE %")]
public class CommandToggle : Command
{
Expand Down
26 changes: 26 additions & 0 deletions ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,32 @@ public virtual void UnlockAll()
if (ParentContext != null) ParentContext.UnlockAll();
}

public virtual void Unset(String name)
{
if (Variables.ContainsKey(name.ToLower()))
{
Variables.Remove(name.ToLower());
}
else if (ParentContext != null)
{
ParentContext.Unset(name.ToLower());
}
}

public virtual void UnsetAll()
{
for( int i = 0; i < Variables.Count; i++)
{
var currvar = Variables.ElementAt(i);

if(!(currvar.Value is BoundVariable))
{
Variables.Remove(currvar.Key);
}
}
if (ParentContext != null) ParentContext.UnsetAll();
}

public bool parseNext(ref string buffer, out string cmd, ref int lineCount, out int lineStart)
{
lineStart = -1;
Expand Down