Visual Basic (Declaration) | |
---|---|
Public Enum DefaultCommands Inherits System.Enum |
C# | |
---|---|
public enum DefaultCommands : System.Enum |
Member | Description |
---|---|
All | Not a command, indicates to use all default commands |
Default | Not a command, indicates the default commands added if not specified |
Echo | A command to echo back to std::out the arguments provided. |
ErrorLevel | An option to set and get the environment error-level |
Find | A command to search for a text string in a file or the standard input stream. |
Get | A command to get the value of an option |
Help | A command to display help about the commands and their options |
HostHTTP | A command that allows the console application to be hosted as a restful HTTP server. |
IORedirect | A command filter that allows redirect of std in/out to files. |
More | A command to read the input stream and show one screen at a time to standard output. |
None | Not a command, indicates no default commands |
PipeCommands | A command filter that allows piping the output of one command into the input of another. |
Prompt | An option that provides customization of the command prompt for interactive mode |
Set | A command to set the value of an option |
Library/Library.Test/TestCmdInterpreter.cs
C# | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.Get | DefaultCommands.Set | DefaultCommands.Help, DefaultCommands.Default); //defaults the DefaultCommands to Get/Set/Help via the enum value of DefaultCommands.Default CommandInterpreter ci = new CommandInterpreter(new TestCommands()); Assert.AreEqual(2, ci.Options.Length); Assert.AreEqual("Other", ci.Options[0].DisplayName); Assert.AreEqual(typeof(int), ci.Options[0].Type); Assert.AreEqual("SomeData", ci.Options[1].DisplayName); Assert.AreEqual(typeof(String), ci.Options[1].Type); TextWriter stdout = Console.Out; try { Console.SetOut(new StringWriter());// <= Get will also write to console Assert.AreEqual(-1, ci.Get("other"));//default was applied ci.Set("other", 1); Assert.AreEqual(1, ci.Get("other")); Assert.AreNotEqual("abc", ci.Get("somedata")); ci.Set("somedata", "abc"); Assert.AreEqual("abc", ci.Get("somedata")); } finally { Console.SetOut(stdout); } string result; result = Capture(ci, "GET Somedata"); Assert.AreEqual("abc", result); //Set without args lists options result = Capture(ci, "SET"); Assert.IsTrue(result.ToUpper().Contains("somedata".ToUpper())); //Set without value returns the current value result = Capture(ci, "SET somedata"); Assert.AreEqual("abc", result); result = Capture(ci, "SET somedata 123"); Assert.AreEqual("", result); result = Capture(ci, "GET somedata"); Assert.AreEqual("123", result); |
VB.NET | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.[Get] Or DefaultCommands.[Set] Or DefaultCommands.Help, DefaultCommands.[Default]) 'defaults the DefaultCommands to Get/Set/Help via the enum value of DefaultCommands.Default Dim ci As New CommandInterpreter(New TestCommands()) Assert.AreEqual(2, ci.Options.Length) Assert.AreEqual("Other", ci.Options(0).DisplayName) Assert.AreEqual(GetType(Integer), ci.Options(0).Type) Assert.AreEqual("SomeData", ci.Options(1).DisplayName) Assert.AreEqual(GetType([String]), ci.Options(1).Type) Dim stdout As TextWriter = Console.Out Try Console.SetOut(New StringWriter()) ' <= Get will also write to console Assert.AreEqual(-1, ci.[Get]("other")) 'default was applied ci.[Set]("other", 1) Assert.AreEqual(1, ci.[Get]("other")) Assert.AreNotEqual("abc", ci.[Get]("somedata")) ci.[Set]("somedata", "abc") Assert.AreEqual("abc", ci.[Get]("somedata")) Finally Console.SetOut(stdout) End Try Dim result As String result = Capture(ci, "GET Somedata") Assert.AreEqual("abc", result) 'Set without args lists options result = Capture(ci, "SET") Assert.IsTrue(result.ToUpper().Contains("somedata".ToUpper())) 'Set without value returns the current value result = Capture(ci, "SET somedata") Assert.AreEqual("abc", result) result = Capture(ci, "SET somedata 123") Assert.AreEqual("", result) result = Capture(ci, "GET somedata") Assert.AreEqual("123", result) |
System.Object
System.ValueType
System.Enum
CSharpTest.Net.Commands.DefaultCommands
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7