public void ReturnsTheValues() { string[] args = new[] { "--cache" , "one.txt" , "--name" , "Azure" , "Image" , "Optimizer" , "--color" , "Green" , "--force" }; IDictionary <string, string> result = new CommandArgsParser().ParseArgs(args); Assert.AreEqual(4, result.Count); Assert.IsTrue(result.Keys.Contains("--cache")); Assert.IsTrue(result.Keys.Contains("--name")); Assert.IsTrue(result.Keys.Contains("--color")); Assert.AreEqual("one.txt", result["--cache"]); Assert.AreEqual("Azure Image Optimizer", result["--name"]); Assert.AreEqual("Green", result["--color"]); Assert.IsTrue(result.Keys.Contains("--force")); }
public LinkFromCommandTestFixture SetupInvalidArgs() { CommandArgsParser .Setup(x => x.IsValid(It.IsAny <string[]>())) .Returns((false, "Test says no")); return(this); }
public void HandlesHelpAsShortName() { string[] args = new string[1]; args[0] = "/?"; IDictionary <string, string> result = new CommandArgsParser().ParseArgs(args); Assert.IsTrue(result.Keys.Contains("--help")); Assert.AreEqual(true.ToString(), result["--help"]); }
public async Task DispatchCommand <T>(string[] args) where T : AbstractFeature { var options = CommandArgsParser.Parse <T>(args, GetHelpText("")); if (Dispatcher.TryGetValue(options.Command.ToLowerInvariant(), out var handler)) { await handler.Handle(args); } else { Console.WriteLine(GetHelpText("")); Environment.Exit(-1); } }
private static void StartAsConsole(string[] args) { System.Diagnostics.Trace.TraceInformation("TextMin:StartAsConsole"); CommandLineOptions cmdLineOptions = new CommandArgsParser().BuildCommandLineOptions(args); cmdLineOptions.FileExtensionsToCompress = _fileExtentionsToCompress; if (cmdLineOptions.DisplayHelp || string.IsNullOrEmpty(cmdLineOptions.ItemsToProcessDirectory)) { CompressorBase.ShowUsage(); Console.ReadLine(); return; } RunMinifier(cmdLineOptions); }
public async Task Handle(string[] args) { var options = CommandArgsParser.Parse <T>(args, ""); options.FillOctopusParams(); if (string.IsNullOrWhiteSpace(options.ApiKey)) { Console.Error.WriteLine("Octopus Api Key is required, you can provide it via command line: --api-key API-XXXXX or environment variable: OCTOPUS_APIKEY"); return; } if (string.IsNullOrWhiteSpace(options.ServerUrl)) { Console.Error.WriteLine("Octopus server URL is required, you can provide it via command line: --server-url http://xxx.com or environment variable: OCTOPUS_SERVERURL"); return; } await Execute(options); }
public void BuildsTheCommandLineOptions() { string[] args = new[] { "--cache", "one.txt", "--name", "Azure", "Image", "Optimizer", "--color", "Green", "--force" }; var options = new CommandArgsParser().BuildCommandLineOptions(args); Assert.AreEqual("one.txt", options.OptimizerCacheFile); Assert.AreEqual("Azure Image Optimizer", options.Name); Assert.AreEqual("Green", options.Color); Assert.IsTrue(options.ShouldForceOptimize); }
public async Task DispatchToFeature(string[] args) { if (!args.Any()) { Console.WriteLine(GetHelpText()); return; } var options = CommandArgsParser.Parse <AllFeatures>(args, ""); if (Dispatcher.TryGetValue(options.Feature.ToLowerInvariant(), out var handler)) { await handler.Handle(args); } else { Console.WriteLine(GetHelpText()); Environment.Exit(-1); } }
internal void Run(string[] args) { do { CommandParser commandParser = new CommandParser(); ICommand command = commandParser.ParseCommand(args); command.Execute(controller); if (controller.IsInteractive) { string line = Console.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { break; } else { args = CommandArgsParser.TokenizeCommandLineToStringArray(line); } } } while (controller.IsInteractive); }
public void CommandLineArgs(string line) { string[] args = CommandArgsParser.TokenizeCommandLineToStringArray(line); Assert.NotEmpty(args); Assert.Equal("ls", args[0]); }
void Update() { if (Input.GetKeyDown(KeyCode.Return)) { string cmd = CommandInputField.text; if (cmd.Trim() != "") { if (CommandBuffer.Count == 0 || CommandBuffer.Last.Value != cmd.Trim()) { CommandBuffer.AddLast(cmd); if (CommandBuffer.Count > 50) { CommandBuffer.RemoveFirst(); } } } IGConsole.Instance.printWarnln(">" + cmd); var ParsedCmd = CommandArgsParser.ParseArgs(cmd); CommandDelegate Command; if (CommandDelegates.TryGetValue(ParsedCmd.Item1.ToUpper(), out Command)) { Command(cmd, ParsedCmd.Item2); } else { IGConsole.Instance.println("\"" + ParsedCmd.Item1 + "\" is not exist command"); } CommandInputField.text = ""; CommandInputField.Select(); CommandInputField.ActivateInputField(); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { if (CommandBuffer.Count == 0) { return; } if (CommandBufferSearchIndex == null) { CommandBufferSearchIndex = CommandBuffer.Last; } else if (CommandInputField.text.Trim() == "") { } else if (CommandBufferSearchIndex.Previous != null) { CommandBufferSearchIndex = CommandBufferSearchIndex.Previous; } CommandInputField.text = CommandBufferSearchIndex.Value; } else if (Input.GetKeyDown(KeyCode.DownArrow)) { if (CommandBuffer.Count == 0) { return; } if (CommandBufferSearchIndex == null) { CommandBufferSearchIndex = CommandBuffer.Last; } else if (CommandInputField.text.Trim() == "") { } else if (CommandBufferSearchIndex.Next != null) { CommandBufferSearchIndex = CommandBufferSearchIndex.Next; } CommandInputField.text = CommandBufferSearchIndex.Value; } }