Пример #1
0
        public void HelpForCommandWithSlashQuestionMark()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <Groups1>("Command1 /?", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Green, "Command1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "p1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "p1  "),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "256"),
                     new TextAndColor(ConsoleColor.Black, ")")
                     );
        }
Пример #2
0
        public void TryParseObjectThatHasListAsFirstArgument()
        {
            var commandLine = $"element1 element2 element3";

            TestWriter _printer = new TestWriter();
            IColors    color    = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);

            bool value = Parser.TryParse(commandLine, out ComplexType5 options);

            Assert.False(value);

            Validate(_printer, new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, $": The required collection argument needs to be on the last position of the required arguments. {Environment.NewLine}"),
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "list1"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "nonList"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, "testhost --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
Пример #3
0
        public void HelpTest4()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <Options3NoRequired>("/?", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "For detailed information run '"),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name} --help"),
                     new TextAndColor(ConsoleColor.Black, "'.")
                     );
        }
Пример #4
0
        public void HelpTest1_WithResponseFile()
        {
            string responseFile = Path.Combine(Helpers.GetTestLocation(), Path.Combine("SampleRspFiles", "response4.rsp"));

            TestWriter _printer = new TestWriter();
            var        options  = Helpers.Parse <Options3NoRequired>($"@{responseFile}", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "For detailed information run '"),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name} --help"),
                     new TextAndColor(ConsoleColor.Black, "'.")
                     );
        }
Пример #5
0
        public void TryParseObjectThatDefinesTwoRequiredLists()
        {
            var commandLine = $"element1 element2 element3";

            TestWriter _printer = new TestWriter();
            IColors    color    = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);

            bool value = Parser.TryParse(commandLine, out ComplexType2 options);

            Assert.False(value);

            Validate(_printer,
                     new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, $": Cannot declare two required collection arguments. Please convert one of them to an optional collection one. {Environment.NewLine}"),
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, "testhost --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
        public void HelpTest1_WithResponseFile(IColors color)
        {
            string responseFile = Path.Combine(Helpers.GetTestLocation(), Path.Combine("SampleRspFiles", "response4.rsp"));

            TestWriter _printer = new TestWriter();
            var        options  = Assert.Throws <HelpRequestedException>(() => Helpers.Parse <Options3NoRequired>($"@{responseFile}", _printer, color));

            Validate(_printer,
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt1"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt2"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt3"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, $"{Assembly.GetEntryAssembly()?.GetName()?.Name} --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
Пример #7
0
        private void Validate(TestWriter _printer, params TextAndColor[] values)
        {
            Assert.True(values.Length == _printer.Segments.Count, _printer.ToTestCode());

            for (int i = 0; i < values.Length; i++)
            {
                Assert.True(values[i].Equals(_printer.Segments[i]),
                            string.Format("Expected Text={0}, Color={1}, Got {2}", values[i].Text, values[i].Color, _printer.Segments[i]));
            }
        }
Пример #8
0
        public void TryParseWithoutLoggingToConsole()
        {
            TestWriter    _printer      = new TestWriter();
            ParserOptions parserOptions = new ParserOptions()
            {
                LogParseErrorToConsole = false
            };
            IColors color = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);
            bool value = Parser.TryParse("foo", out Options1 options, parserOptions);

            Assert.False(value);

            Validate(_printer);
        }
Пример #9
0
        public void TryParseWithLoggingToConsole()
        {
            TestWriter    _printer      = new TestWriter();
            ParserOptions parserOptions = new ParserOptions()
            {
                LogParseErrorToConsole = true
            };
            IColors color = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);
            bool value = Parser.TryParse("foo", out Options1 options, parserOptions);

            Assert.False(value);

            Validate(_printer,
                     new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, $": Not all required arguments have been specified {Environment.NewLine}"),
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "p1"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "p2"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt1"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt2"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt3"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "opt4"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, "testhost --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
Пример #10
0
        public void HelpTest3()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <OptionsNegative1>("-?", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "p1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "p2"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "For detailed information run '"),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name} --help"),
                     new TextAndColor(ConsoleColor.Black, "'.")
                     );
        }
Пример #11
0
        public void DetailedHelp2()
        {
            TestWriter _printer = new TestWriter();
            var        options  = Helpers.Parse <Options3NoRequired>("--help", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, "testhost.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "256"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "list"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 3 (one of "),
                     new TextAndColor(ConsoleColor.Green, "A,B"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "B"),
                     new TextAndColor(ConsoleColor.Black, ")")
                     );
        }
Пример #12
0
        public void HelpWhenPassMoreParametersThanExpected()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <MorePassedInThanRequired>("this expects 2 args", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Red, "Error"),
                     new TextAndColor(ConsoleColor.Black, $": Optional parameter name should start with '-' {Environment.NewLine}"),
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, "testhost.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "a"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "b"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "For detailed information run '"),
                     new TextAndColor(ConsoleColor.White, "testhost --help"),
                     new TextAndColor(ConsoleColor.Black, "'.")
                     );
        }
Пример #13
0
        public void DefineTwoRequiredCollectionsSameGroup()
        {
            string expectedRepo1 = "azure\azure-powershell";
            string expectedRepo2 = "azure\azure-sdk-for-net";
            var    commandLine   = $"Create {expectedRepo1} {expectedRepo2}";

            TestWriter _printer = new TestWriter();
            IColors    color    = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);

            bool value = Parser.TryParse(commandLine, out ComplexType6 options);

            Assert.False(value);

            Validate(_printer, new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, $": Cannot declare two required collection arguments. Please convert one of them to an optional collection one. {Environment.NewLine}"),
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "Create"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos2"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "List"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, "testhost --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
Пример #14
0
        public void HelpForTypeWithRequiredAndOptionalEnumsAndLists()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <HelpGeneratorObject>("--help", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "folders"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "providers"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "provider"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "out"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "open"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "outputWriter"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "folders     "),
                     new TextAndColor(ConsoleColor.Black, " : List of the folders to consider when scanning for duplicates ("),
                     new TextAndColor(ConsoleColor.Green, "list"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "providers   "),
                     new TextAndColor(ConsoleColor.Black, " : Some providers to have (one of "),
                     new TextAndColor(ConsoleColor.Green, "SHA1,FileSize"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "provider    "),
                     new TextAndColor(ConsoleColor.Black, " : The mechanism to use when determining if the files are unique (one of "),
                     new TextAndColor(ConsoleColor.Green, "SHA1,FileSize"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "FileSize"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "out         "),
                     new TextAndColor(ConsoleColor.Black, " : The name of the file where to write the result ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "output"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "open        "),
                     new TextAndColor(ConsoleColor.Black, " : Launch the result once the tool runs ("),
                     new TextAndColor(ConsoleColor.Green, "true or false"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "True"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "outputWriter"),
                     new TextAndColor(ConsoleColor.Black, " : The output format(s) to use (one of "),
                     new TextAndColor(ConsoleColor.Green, "Html,Csv"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "Html, Csv"),
                     new TextAndColor(ConsoleColor.Black, ")")
                     );
        }
Пример #15
0
        public void DetailedHelpForGroups2WithCommonArgs()
        {
            TestWriter _printer = new TestWriter();

            var options = Helpers.Parse <Groups2>("--help", _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Green, "Command1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "common1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "common2"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "common1"),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "common2"),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt1   "),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "256"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Green, "Command2"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "common1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "common2"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "req3"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "common1"),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "common2"),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "req3   "),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 3 (specific to command2) (one of "),
                     new TextAndColor(ConsoleColor.Green, "A,B"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt2   "),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "256"),
                     new TextAndColor(ConsoleColor.Black, ")")
                     );
        }
Пример #16
0
        public void DefineRequiredCollectionWrongPositionGroup()
        {
            string expectedRepo1 = "azure\azure-powershell";
            string expectedRepo2 = "azure\azure-sdk-for-net";
            var    commandLine   = $"Create {expectedRepo1} {expectedRepo2}";

            TestWriter _printer = new TestWriter();
            IColors    color    = Parser.ColorScheme.Get();

            OutputColorizer.Colorizer.SetupWriter(_printer);

            bool value = Parser.TryParse(commandLine, out ComplexType7 options);

            Assert.False(value);

            Validate(_printer, new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, $": The required collection argument for group `Create` needs to be on the last position of the required arguments. {Environment.NewLine}"),
                     new TextAndColor(_printer.ForegroundColor, "Usage: "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "Create"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "objectsFile"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "token"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "CreateOrUpdate"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "objectsFile"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "token"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "List"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, $"{Environment.NewLine}"),
                     new TextAndColor(color.ErrorColor, "Error"),
                     new TextAndColor(_printer.ForegroundColor, ": Required argument expected at position"),
                     new TextAndColor(color.RequiredArgumentColor, "1"),
                     new TextAndColor(_printer.ForegroundColor, ". Type declares arguments at position(s) "),
                     new TextAndColor(color.RequiredArgumentColor, "0,2"),
                     new TextAndColor(_printer.ForegroundColor, ". "),
                     new TextAndColor(color.ErrorColor, "Check type definition"),
                     new TextAndColor(_printer.ForegroundColor, "."),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.AssemblyNameColor, "testhost.exe"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.ArgumentValueColor, "Check"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "repos"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(color.RequiredArgumentColor, "objectsFile"),
                     new TextAndColor(_printer.ForegroundColor, " "),
                     new TextAndColor(_printer.ForegroundColor, "[-"),
                     new TextAndColor(color.OptionalArgumentColor, "token"),
                     new TextAndColor(_printer.ForegroundColor, " value] "),
                     new TextAndColor(_printer.ForegroundColor, "For detailed information run '"),
                     new TextAndColor(color.AssemblyNameColor, "testhost --help"),
                     new TextAndColor(_printer.ForegroundColor, "'.")
                     );
        }
Пример #17
0
        public void DetailedHelpViaApi1()
        {
            TestWriter _printer = new TestWriter();

            Helpers.DisplayHelp <Options1>(HelpFormat.Full, _printer);

            Validate(_printer,
                     new TextAndColor(ConsoleColor.Black, "Usage: "),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.White, $"{Assembly.GetEntryAssembly()?.GetName()?.Name}.exe"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "p1"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Cyan, "p2"),
                     new TextAndColor(ConsoleColor.Black, " "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "[-"),
                     new TextAndColor(ConsoleColor.Yellow, "opt4"),
                     new TextAndColor(ConsoleColor.Black, " value] "),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "p1  "),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Cyan, "p2  "),
                     new TextAndColor(ConsoleColor.Black, " : Required parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", "),
                     new TextAndColor(ConsoleColor.Cyan, "required"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt1"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 1 ("),
                     new TextAndColor(ConsoleColor.Green, "number"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "256"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt2"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "string"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "all"),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt3"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 2 ("),
                     new TextAndColor(ConsoleColor.Green, "list"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Black, ")"),
                     new TextAndColor(ConsoleColor.Black, "  - "),
                     new TextAndColor(ConsoleColor.Yellow, "opt4"),
                     new TextAndColor(ConsoleColor.Black, " : Optional parameter 4 ("),
                     new TextAndColor(ConsoleColor.Green, "char"),
                     new TextAndColor(ConsoleColor.Black, ", default="),
                     new TextAndColor(ConsoleColor.Yellow, "z"),
                     new TextAndColor(ConsoleColor.Black, ")")
                     );
        }