コード例 #1
0
        private static ICommand GetCommand(params string[] args)
        {
            var parser = ArgumentParserFactory.CreateArgumentParser();

            parser.Parse(args.ToList());
            return(parser.GetContext().Command);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public void Parse_InvalidOptionsArgument_ShouldThrowArgumentException()
        {
            var args = new List <string> {
                "--invalid"
            };

            var parser = ArgumentParserFactory.CreateArgumentParser();

            Assert.Throws <ArgumentException>(() =>
            {
                parser.Parse(args);
            });
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <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);
            }
        }
コード例 #14
0
 public void TestItAddsCliArguments(Type type)
 {
     Assert.True(ArgumentParserFactory.Make().HasCliArgument(type));
 }
コード例 #15
0
 public void Setup()
 {
     _parserFactory = new ArgumentParserFactory();
 }
コード例 #16
0
 public ArgumentParserTest()
 {
     parser            = ArgumentParserFactory.Make();
     compilerArguments = CompilerArgumentsFactory.Make();
     cliArguments      = CliArgumentsFactory.Make();
 }