Ejemplo n.º 1
0
        public static void SetupCommand(ParserSetup parserSetup)
        {
            var command = parserSetup
                          .Command <DateCommandOptions>()
                          .Name("date")
                          .Help("Displays a date and time and optionally calculates the difference to another date and time.")
                          .ExampleUsage("Toolbox date --utc");

            command
            .Option(a => a.Date)
            .Name("date")
            .DefaultValue(DateTime.Now)
            .Help("The date and time to display. If not specified the current system date and time are used.");

            command
            .Option(a => a.Offset)
            .Name("offset")
            .DefaultValue(TimeSpan.Zero)
            .Help("Offsets the date and time by the specified duration before displaying it. Format is HH:MM:SS.");

            command
            .Option(a => a.DisplayInUtc)
            .Name("utc")
            .Help("Converts the date and time to UTC before displaying it.");

            command
            .Option(a => a.DifferenceToDate)
            .Name("differenceTo")
            .Help("If specified the difference between the first date (option --date) and this date is displayed.");

            command.Validate(Validate);
        }
        public void Banner_ShouldReturnParserSetup()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.Banner("newBanner").Should().Be(setup);
        }
        public void ProgramName_ShouldReturnParserSetup()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.ProgramName("newProgramName").Should().Be(setup);
        }
        public void IgnoreUnknownOptions_ShouldReturnParserSetup()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.IgnoreUnknownOptions().Should().Be(setup);
        }
        public void HelpTextMaxLineLength_ShouldReturnParserSetup()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.HelpTextMaxLineLength(123).Should().Be(setup);
        }
        public void ErrorTextWriter_ShouldReturnParserSetup()
        {
            var parser     = A.Fake <Parser>();
            var textWriter = A.Fake <TextWriter>();

            var setup = new ParserSetup(parser);

            setup.ErrorTextWriter(textWriter).Should().Be(setup);
        }
        public void Banner_ShouldAssignBannerToParser()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.Banner("newBanner");

            A.CallToSet(() => parser.Banner).To("newBanner").MustHaveHappened();
        }
        public void ProgramName_ShouldAssignProgramNameToParser()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.ProgramName("newProgramName");

            A.CallToSet(() => parser.ProgramName).To("newProgramName").MustHaveHappened();
        }
        public void IgnoreUnknownOptions_ShouldSetIgnoreUnkownOptionsFlagOnParser()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.IgnoreUnknownOptions();

            A.CallToSet(() => parser.IgnoreUnknownOptions).To(true).MustHaveHappened();
        }
        public void HelpTextMaxLineLength_ShouldAssignHelpTextMaxLineLengthToParser()
        {
            var parser = A.Fake <Parser>();

            var setup = new ParserSetup(parser);

            setup.HelpTextMaxLineLength(123);

            A.CallToSet(() => parser.HelpTextMaxLineLength).To(123).MustHaveHappened();
        }
        public void ErrorTextWriter_ShouldAssignErrorTextWriterToParser()
        {
            var parser     = A.Fake <Parser>();
            var textWriter = A.Fake <TextWriter>();

            var setup = new ParserSetup(parser);

            setup.ErrorTextWriter(textWriter);

            A.CallToSet(() => parser.ErrorTextWriter).To(textWriter).MustHaveHappened();
        }
        public static void SetupCommand(ParserSetup parserSetup)
        {
            var command = parserSetup
                          .Command <FileReplaceCommandOptions>()
                          .Name("fileReplace")
                          .Help("Reads text from a file, replaces a text with another text and saves the result to a new file.")
                          .ExampleUsage("Toolbox fileReplace --in In.txt --out Out.txt --pattern cat --replaceWith dog");

            command
            .Option(a => a.InFile)
            .Name("in")
            .Help("The file to read the text from.")
            .IsRequired();

            command
            .Option(a => a.OutFile)
            .Name("out")
            .Help("The file to write the result to.")
            .IsRequired();

            command
            .Option(a => a.Pattern)
            .Name("pattern")
            .Help("The text to replace.")
            .IsRequired();

            command
            .Option(a => a.Replacement)
            .Name("replaceWith")
            .Help("The replacement text.")
            .IsRequired();

            command
            .Option(a => a.IgnoreCase)
            .Name("ignoreCase")
            .Help("Ignores casing when searching for the specified text (--pattern).");

            command
            .Option(a => a.OverrideOutFile)
            .Name("override")
            .Help("Overrides the output file if it already exists. If this option is not enabled and the output file already exists an error will be shown.");

            command
            .Option(a => a.UseRegularExpressions)
            .Name("regex")
            .Help("Treats the given pattern (--pattern) as a regular expression.");

            command
            .Option(a => a.DisplayResult)
            .Name("display")
            .Help("Displays the result on the console.");

            command.Validate(Validate);
        }
        public void DefaultCommand_ShouldReturnNewDefaultCommandSetup()
        {
            var parser        = A.Fake <Parser>();
            var commandParser = A.Fake <CommandParser <Command1Options> >();
            var commandSetup  = A.Fake <DefaultCommandSetup <Command1Options> >();

            var setup = new ParserSetup(parser);

            A.CallTo(() => parser.GetOrCreateCommandParser <Command1Options>(null)).Returns(commandParser);
            A.CallTo(() => this.DependencyResolver.Resolve <DefaultCommandSetup <Command1Options> >(parser, commandParser)).Returns(commandSetup);

            setup.DefaultCommand <Command1Options>().Should().Be(commandSetup);
        }
        public static void SetupCommand(ParserSetup parserSetup)
        {
            var command = parserSetup
                          .Command <LongestWordCommandOptions>()
                          .Name("longestWord")
                          .Help("Gets the longest word of a list of words.")
                          .ExampleUsage("Tool longestWord --words cat dog fish crocodile");

            command
            .Option(a => a.Words)
            .Name("words")
            .Help("The list of words.")
            .IsRequired();
        }
Ejemplo n.º 15
0
        public static void SetupCommand(ParserSetup parserSetup)
        {
            var defaultCommand = parserSetup
                                 .DefaultCommand <QueryWebCommandOptions>()
                                 .Help("Downloads and shows a website on the console and performs a search engine search.")
                                 .ExampleUsage("Toolbox --search What is life");

            defaultCommand
            .Option(a => a.WebsiteAddress)
            .Name("website")
            .Help("The HTTP address of a website to download an show.");

            defaultCommand
            .Option(a => a.SearchEngineQuery)
            .Name("search")
            .Help("A search query to ask a search engine.");

            defaultCommand.Validate(Validate);
        }
        public static void SetupCommand(ParserSetup parserSetup)
        {
            var command = parserSetup
                          .Command <ConvertGuidCommandOptions>()
                          .Name("convertGuid")
                          .Help("Converts a guid.")
                          .ExampleUsage("Toolbox convertGuid --guid ac23ddb2-6e34-46a9-80f4-9d6fe6f87558 --to Bytes");

            command
            .Option(a => a.Guid)
            .Name("guid")
            .Help("The Guid to be converted.")
            .IsRequired();

            command
            .Option(a => a.Mode)
            .Name("to")
            .Help("Defines to which the Guid should converted.")
            .EnumValueHelp(ConvertGuidMode.Bytes, "Converts the Guid to a sequence of bytes.")
            .EnumValueHelp(ConvertGuidMode.BigInteger, "Converts the Guid to a big integer.");
        }