private static ICommand GetCommand(params string[] args) { var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args.ToList()); return(parser.GetContext().Command); }
public void Parse_NoOptions_ShouldReturnEmptyOptions() { var args = new List <string> { "test" }; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var options = parser.GetContext().Options; Assert.IsEmpty(options); }
public void Parse_UppercaseHelp_ShouldReturnHelpOptions() { var args = new List <string> { "--HELP" }; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var option = parser.GetContext().Options.FirstOrDefault()?.GetType(); Assert.AreEqual(typeof(HelpOption), option); }
public void Parse_Help_ShouldReturnEmptyArguments() { var args = new List <string> { "--help" }; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var arguments = parser.GetContext().Arguments; Assert.IsEmpty(arguments); }
public void Parse_Help_ShouldReturnNullCommandName() { var args = new List <string> { "--help" }; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var commandName = parser.GetContext().Command.Name; Assert.Null(commandName); }
public void Parse_InvalidOptionsArgument_ShouldThrowArgumentException() { var args = new List <string> { "--invalid" }; var parser = ArgumentParserFactory.CreateArgumentParser(); Assert.Throws <ArgumentException>(() => { parser.Parse(args); }); }
public void Parse_FooOptions_ShouldReturnNoCommand() { var args = new List <string> { "--foo" }; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var command = parser.GetContext().Command; Assert.IsInstanceOf(typeof(NoCommand), command); }
public void Parse_TestNew_ShouldReturnTestFamilyName() { var args = new List <string> { "test", "new" }; const string expectedFamily = "test"; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var familyName = parser.GetContext().Command.Family; Assert.AreEqual(expectedFamily, familyName); }
public void Parse_TestNew_ShouldReturnNewTestCommandName() { var args = new List <string> { "test", "new" }; const string expectedCommand = "test new"; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var commandName = parser.GetContext().Command.Name; Assert.AreEqual(expectedCommand, commandName); }
public void Parse_TestNewWithFooOptionInTheMiddle_ShouldReturnTestOption() { var args = new List <string> { "test", "--foo", "new" }; const string expectedOption = "foo"; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var optionName = parser.GetContext().Options.First().Name; Assert.AreEqual(expectedOption, optionName); }
public void Parse_Uppercase_ShouldReturnLowerCaseCommandName() { var args = new List <string> { "TEST" }; const string expectedCommand = "test"; var parser = ArgumentParserFactory.CreateArgumentParser(); parser.Parse(args); var commandName = parser.GetContext().Command.Name; Assert.AreEqual(expectedCommand, commandName); }
static int Main(string[] args) { // Setup the console output stream. StreamWriter output = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }; Console.SetOut(output); // Parse the sectorfile CompilerArguments compilerArguments = CompilerArgumentsFactory.Make(); CliArguments cliArguments = CliArgumentsFactory.Make(); try { ArgumentParserFactory.Make().CreateFromCommandLine(compilerArguments, cliArguments, args); } catch (ArgumentException exception) { output.Write(exception.Message); return(1); } int returnCode = SectorFileCompilerFactory.Create( compilerArguments, new List <IEventObserver>() { new ConsoleOutput(output) } ).Compile(); if (cliArguments.PauseOnFinish) { output.Write("Press any key to exit"); Console.ReadKey(); } return(returnCode); }
/// <summary> /// Runs the migrate tool /// </summary> /// <param name = "args" > program arguements</param> public void Run(Queue <string> args) { var executingLocation = Directory.GetCurrentDirectory(); var projectFile = Directory.GetFiles(executingLocation, "*.csproj"); if (projectFile.Length == 0) { throw new FileNotFoundException("Project file not found in current directory."); } var parser = ArgumentParserFactory.GetInstance <MigrationOptions>(); // pull out arg as we pass the remaining arguments down the list var options = parser.Parse(args); var isValid = options.Validate(); if (!isValid) { Console.WriteLine("Run dotnet mongo --help for usage information."); } options.ProjectFile = projectFile[0]; var migrationResult = MigrationRunner.Run(options); if (migrationResult.Operation == MigrationOperation.Status && migrationResult.IsSuccessful) { var table = migrationResult.Result.BuildConsoleTable(); table.Write(Format.Alternative); } else { Console.WriteLine(migrationResult.Result); } }
public void TestItAddsCliArguments(Type type) { Assert.True(ArgumentParserFactory.Make().HasCliArgument(type)); }
public void Setup() { _parserFactory = new ArgumentParserFactory(); }
public ArgumentParserTest() { parser = ArgumentParserFactory.Make(); compilerArguments = CompilerArgumentsFactory.Make(); cliArguments = CliArgumentsFactory.Make(); }