예제 #1
0
        public void CaseFolding_ParseShortArgWithWrongCaseWhenCaseInsensitive_CorrectlyParsesArgs()
        {
            var parser = new CliParser <CaseFoldingOptions>(
                new CaseFoldingOptions(), ParserOptions.CaseInsensitive);

            parser.Parse("-N timothy".Split());
        }
        public CliprConfigurationSource(string[] args)
        {
            Config = new T();
            var parser = new CliParser <T>(Config);

            parser.Parse(args);
        }
예제 #3
0
        public static CoverallsOptions Parse(string[] args)
        {
            var res    = new CoverallsOptions();
            var parser = new CliParser <CoverallsOptions>(res);

            try
            {
                parser.Parse(args);

                if (!(res.OpenCover.SafeAny() ||
                      res.MonoCov.SafeAny() ||
                      res.Chutzpah.SafeAny() ||
                      res.DynamicCodeCoverage.SafeAny() ||
                      res.Lcov.SafeAny() ||
                      res.VsCoverage.SafeAny()))
                {
                    throw new Exception(Usage);
                }

                return(res);
            }
            catch (ParseException ex)
            {
                throw new Exception($"{ex.Message}{Environment.NewLine}{Environment.NewLine}{Usage}");
            }
        }
예제 #4
0
        public void TryParse_WithOutAndInvalidArgs_SetsOutValueToNull()
        {
            CaseFoldingOptions obj;

            CliParser.TryParse("--ame tim".Split(), out obj);
            Assert.AreEqual(null, obj);
        }
예제 #5
0
        public void ShowHelp_WithAmericanLocale_ShowsEnglishHelpText()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("en-US")))
            {
                // Arrange
                var expected = @"Usage: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD
Positional Arguments:
 FileToAdd         File to add to the thing.

Optional Arguments:
 --turnonthepower  Set power level to 9001.
 -c                A cool counter.
 -h, --help        Display this help document.
 -s                Start date.
 --version         Displays the version of the current executable.";

                var opt    = new LocalizationOptions();
                var parser = new CliParser <LocalizationOptions>(opt);
                var help   = new AutomaticHelpGenerator <LocalizationOptions>(); // TODO simplify work required to get help info

                // Act
                var actual = help.GetHelp(parser.Config);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
예제 #6
0
        public void ParseArguments_WithPositionalBeforeNamed_ParsesBothArguments()
        {
            var opt = CliParser.Parse <MixedNamedAndPositional>("pos -n name".Split());

            Assert.AreEqual("name", opt.Named);
            Assert.AreEqual("pos", opt.Positional);
        }
예제 #7
0
        public void Parse_WithPositionalAgumentFollowingNamedWithNoLimit_LeavesLastArgumentForPositional()
        {
            var obj = CliParser.Parse <InfiniteNamedWithPositional>(
                "-n one two three -- positional".Split());

            Assert.AreEqual("positional", obj.Positional);
        }
예제 #8
0
파일: Program.cs 프로젝트: arthurward/clipr
        static void CustomDateTime(string[] args)
        {
            var opt = CliParser.Parse <CustomDateTimeOptions>(args);

            Console.WriteLine(opt.CurrentDate[1]);
            // >>>
        }
예제 #9
0
        public void TryParse_WithOutAndValidArgs_ParsesArgs()
        {
            CaseFoldingOptions obj;

            CliParser.TryParse("--name tim".Split(), out obj);
            Assert.AreEqual("tim", obj.Name);
        }
예제 #10
0
        public void ParseExample_WithMultipleArgumentsAndAttributeConfig_ParsesOutputFile()
        {
            var opt = CliParser.Parse <Options>(
                "-vvv output.txt 1 2 -1 7".Split());

            Assert.AreEqual("output.txt", opt.OutputFile);
        }
예제 #11
0
        public void Parse_WithStaticEnumerationSubclassDefinedOnClass_ParsesIntoValue()
        {
            var obj = CliParser.Parse <StaticEnumerationOptions>(
                "-e second".Split());

            Assert.AreSame(SomeEnum.Second, obj.Value);
        }
예제 #12
0
        public void Parse_WithStaticEnumeration_ParsesValue()
        {
            var obj = CliParser.Parse <StaticEnumerationOptions>(
                "-e first".Split());

            Assert.AreSame(SomeEnum.First, obj.Value);
        }
예제 #13
0
        public void ParseExample_WithMultipleArgumentsAndAttributeConfig_ParsesVerbosity()
        {
            var opt = CliParser.Parse <Options>(
                "-vvv output.txt 1 2 -1 7".Split());

            Assert.AreEqual(3, opt.Verbosity);
        }
예제 #14
0
        public void Parse_WithStaticEnumerationDefinedOnProperty_ParsesIntoValue()
        {
            var obj = CliParser.Parse <StaticEnumerationOptionsExplicit>(
                "-e first".Split());

            Assert.AreSame(SomeEnumNonStatic.First, obj.Value);
        }
예제 #15
0
        public void Help_WithNestedHelpOfVerbCalled_GeneratedHelpOutputForVerb()
        {
            const string expected = @"Usage: clipr verb1 verb2 [ -a|--age A ] [ -h|--help ]
Optional Arguments:
 -a, --age
 -h, --help  Display this help document.
";

            var sw     = new StringWriter();
            var opt    = new OptionsWithNestedVerbs();
            var parser = new CliParser <OptionsWithNestedVerbs>(opt, new ParserOptions {
                OutputWriter = sw
            });

            try
            {
                parser.Parse("verb1 verb2 --help".Split());
            }
            catch (ParserExit e)
            {
            }
            var actual = sw.ToString();

            Assert.AreEqual(expected, actual);
        }
예제 #16
0
        public void Help_WithNestedHelpOfVerbCalledOnBaseVerb_GeneratedHelpOutputForVerbWithCommands()
        {
            const string expected = @"Usage: clipr verb1 [ -n|--name N ] [ -h|--help ] <command>
Optional Arguments:
 -h, --help  Display this help document.
 -n, --name

Commands:
 verb2       A verb for ages
";

            var sw     = new StringWriter();
            var opt    = new OptionsWithNestedVerbs();
            var parser = new CliParser <OptionsWithNestedVerbs>(opt, new ParserOptions {
                OutputWriter = sw
            });

            try
            {
                parser.Parse("verb1 --help".Split());
            }
            catch (ParserExit e)
            {
            }
            var actual = sw.ToString();

            Assert.AreEqual(expected, actual);
        }
예제 #17
0
파일: truncate.cs 프로젝트: Nippius/utils
        static void Main(string[] args)
        {
            try
            {
                Options opt = CliParser.Parse <Options>(args);

                FileMode fileMode = (opt.NoCreate) ? FileMode.Open : FileMode.OpenOrCreate;

                LibTruncate.Truncate.TruncateFiles(new TruncateOptions
                {
                    FileMode = fileMode,
                    Quiet    = opt.Quiet,
                    Size     = opt.Size
                }, opt.FileNames);
            }
            catch (ParseException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ParserExit)
            {
                // This is thrown when the --help or --version parameters are passed
                // to the parser so we can safely ignore.
                return;
            }
        }
예제 #18
0
        public void Parse_WithStaticEnumerationSubclassCovariantDefinedOnClass_ParsesIntoValue()
        {
            var obj = CliParser.Parse <StaticEnumerationOptions>(
                "-e first".Split());

            Assert.AreSame(SomeEnum.First, obj.Value);
        }
예제 #19
0
        public void CaseFolding_ParseLongArgPrefixWithWrongCaseWhenCaseInsensitiveAndPartialMatch_CorrectlyParsesArgs()
        {
            var parser = new CliParser <CaseFoldingOptions>(
                new CaseFoldingOptions(), ParserOptions.CaseInsensitive | ParserOptions.NamedPartialMatch);

            parser.Parse("--Na timothy".Split());
        }
예제 #20
0
        public void Parse_WithIEnumerableNamedArgument_ParsesIntoIEnumerable()
        {
            var obj = CliParser.Parse <EnumerableArguments>(
                "-n 1 4 6 8".Split());

            Assert.AreEqual(4, obj.Numbers.Count());
        }
예제 #21
0
파일: Program.cs 프로젝트: arthurward/clipr
        static void ParseRequiredNamedArgument(string[] args)
        {
            var opt = CliParser.Parse <RequiredNamedArgument>(args);

            Console.WriteLine(opt.CurrentDate);
            // >>>
        }
예제 #22
0
        public void Parse_WithShortNamedAgumentFollowingNamedWithNoLimit_StopsParsingAtFirstDash()
        {
            var obj = CliParser.Parse <InfiniteNamedWithOtherNamedFollowing>(
                "-n one two three -o final".Split());

            Assert.AreEqual("final", obj.Other);
        }
예제 #23
0
        public void TryParse_WithInstanceAndValidArgs_ParsesArgs()
        {
            var obj = new CaseFoldingOptions();

            CliParser.TryParse("--name tim".Split(), obj);
            Assert.AreEqual("tim", obj.Name);
        }
예제 #24
0
        public void ShowHelp_WithMexicanLocale_ShowsSpanishHelpText()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX")))
            {
                // Arrange
                var expected = @"Forma de uso: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD
Argumentos dependientes de la posición:
 FileToAdd         Archivo para añadir a la cosa.

Argumentos opcionales:
 --turnonthepower  Establecer el nivel de potencia de 9001.
 -c                Un contador fresco.
 -h, --help        Muestra esta ayuda
 -s                Fecha de inicio.
 --version         Muestra la versión del ejecutable";

                var opt    = new LocalizationOptions();
                var parser = new CliParser <LocalizationOptions>(opt);
                var help   = new AutomaticHelpGenerator <LocalizationOptions>();

                // Act
                var actual = help.GetHelp(parser.Config);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
예제 #25
0
        public void ParseArgument_WithDuplicateArguments_ThrowsException()
        {
            var parser = new CliParser <DuplicateArguments>(new DuplicateArguments());

            AssertEx.Throws <DuplicateArgumentException>(
                () => parser.Parse("-n orange".Split()));
        }
예제 #26
0
 public void Argument_WithLongOptionAndPromptNoMasking_GetsValueFromStdin()
 {
     // TODO inject pw into stdin
     //const string password = "******";
     var opt = CliParser.Parse<NamedArgumentWithOption>("--password".Split());
     Assert.AreEqual("tim", opt.Name);
 }
예제 #27
0
파일: Program.cs 프로젝트: 602p/nbfc
        private static void ParseArgs(string[] args)
        {
            var opt     = new Verbs();
            var helpGen = new HelpGenerator <Verbs>();

            helpGen.DescriptionDistance = 25;
            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, helpGen);

            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService(opt.Start.ReadOnly);
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
            else
            {
                Console.WriteLine(helpGen.GetHelp(parser.Config));
            }
        }
예제 #28
0
        private static void ParseArgs(string[] args)
        {
            var opt    = new Verbs();
            var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator());

            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService();
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
        }
예제 #29
0
파일: Program.cs 프로젝트: qzcw/nbfc
        private static void ParseArgs(string[] args)
        {
            var opt = new Verbs();
            var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator());
            parser.StrictParse(args);

            if (opt.Start != null)
            {
                StartService();
            }
            else if (opt.Stop != null)
            {
                StopService();
            }
            else if (opt.Set != null)
            {
                SetFanSpeed(opt.Set);
            }
            else if (opt.Config != null)
            {
                ConfigureService(opt.Config);
            }
            else if (opt.Status != null)
            {
                PrintStatus(opt.Status);
            }
        }
예제 #30
0
        static void Main(string[] args)
        {
            //dynamic load:
            //load config file from args=>LoadConfig
            //Loader.LoadLog(LoadConfig.Log);
            //Loader.LoadCommunication(LoadConfig.Communication,host);
            //Loader.LoadThing(LoadConfig.Things,host);

            //very first thing to do is congfig logger
            //初始化 LogManager
            NlogProvider.Config();
            Cfet2LogManager.SetLogProvider(new NlogProvider());

            //inject and init the host app module
            var host = new Cfet2Program();

            HubMaster.InjectHubToModule(host);

            //add communication module

            //var comm= new NancyCM("http://localhost:13345");

            //var comm = new AspNetCoreCommunicatonModule();
            //host.MyHub.TryAddCommunicationModule(comm);
            //todo lock comminication so no more communication can be added

            //add things
            host.AddThings(); //this is defined in a partial file of this class f12 to modify

            //start communication modules
            host.MyHub.StartCommunication();

            //start all thins
            host.MyHub.StartThings();


            //start cli loop
            var cli = new CliParser(host);

            cli.Host = host;
            Console.WriteLine("Cfet2 host Cli started");
            while (true)
            {
                Console.Write("Cfet2> ");
                var command = Console.ReadLine();
                try
                {
                    cli.Execute(command);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                if (cli.MySesstion.ShouldExit)
                {
                    //quit the app
                    break;
                }
            }
        }
예제 #31
0
        public void Parse_WithNestedPostParseMethods_ExecutesMethodsFromInnerToOuterClass()
        {
            PostParseBuilder = new StringBuilder();

            CliParser.Parse <PostParseOuter>("-u frank counter -c 5".Split());

            Assert.AreEqual("5frank", PostParseBuilder.ToString());
        }
예제 #32
0
파일: VerbUnitTest.cs 프로젝트: nemec/clipr
        public void Parse_WithFactoryAndGitVerbsCommitAndNoMessage_ParsesCommitVerb()
        {
            const string expected = "My default message";
            var opt = new OptionsWithGitVerbs();
            var factory = new SimpleVerbfactory
            {
                { () => new GitAdd() },
                { typeof(GitCommit), () => new GitCommit("My default message") }
            };
            var parser = new CliParser<OptionsWithGitVerbs>(
                opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithGitVerbs>(), factory);

            parser.Parse("commit".Split());
            var actual = opt.Commit.CommitMessage;

            Assert.AreEqual(expected, actual);
        }
예제 #33
0
파일: VerbUnitTest.cs 프로젝트: nemec/clipr
        public void Parse_WithFactoryAndGitVerbsAdd_ParsesAddVerb()
        {
            string[] expected = { "myfile.txt", "otherfile.txt" };
            var opt = new OptionsWithGitVerbs();
            var factory = new SimpleVerbfactory
            {
                { () => new GitAdd() },
                { typeof(GitCommit), () => new GitCommit("My default message") }
            };
            var parser = new CliParser<OptionsWithGitVerbs>(
                opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithGitVerbs>(), factory);

            parser.Parse("add myfile.txt otherfile.txt".Split());
            var actual = opt.Add.Files.ToList();

            CollectionAssert.AreEqual(expected, actual);
        }
예제 #34
0
        public void ParseDate_WithSpanishLocaleAndSpanishDateFormat_ParsesDateCorrectly()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-ES")))
            {
                // Arrange
                var expected = new DateTime(2016, 3, 12);

                var opt = new LocalizationOptions();
                var parser = new CliParser<LocalizationOptions>(opt);
                var help = new AutomaticHelpGenerator<LocalizationOptions>();

                // Act
                parser.Parse("-s 12/3/2016 file.txt".Split());

                // Assert
                Assert.AreEqual(expected, opt.StartDate);
            }
        }
예제 #35
0
파일: Program.cs 프로젝트: Edge330/nbfc
        private static void ParseArgs(string[] args)
        {
            var opt = new Verbs();
            var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new CustomHelpGenerator());
            parser.StrictParse(args);

            if (opt.ECDump != null)
            {
                ECDump();
            }
            else if (opt.ECRead != null)
            {
                ECRead(opt.ECRead.Register);
            }
            else if (opt.ECWrite != null)
            {
                ECWrite(opt.ECWrite.Register, opt.ECWrite.Value, opt.ECWrite.Verbose);
            }
            else
            {
                Console.WriteLine((new CustomHelpGenerator()).GetHelp(null));
            }
        }
예제 #36
0
        public void PositionalArgument_WithLowerBoundCountEqualsZero_ParsesNoArguments()
        {
            var opts = new PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero();
            var arguments = new string[0];
            var parser = new CliParser<PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero>(opts);

            parser.Parse(arguments);

            Assert.AreEqual(0, opts.Args.Count);
        }
예제 #37
0
 public void CaseFolding_ParseLongArgPrefixWithWrongCaseWhenCaseInsensitiveAndPartialMatch_CorrectlyParsesArgs()
 {
     var parser = new CliParser<CaseFoldingOptions>(
         new CaseFoldingOptions(), ParserOptions.CaseInsensitive | ParserOptions.NamedPartialMatch);
     parser.Parse("--Na timothy".Split());
 }
예제 #38
0
 public void CaseFolding_ParseShortArgWithWrongCaseWhenCaseInsensitive_CorrectlyParsesArgs()
 {
     var parser = new CliParser<CaseFoldingOptions>(
         new CaseFoldingOptions(), ParserOptions.CaseInsensitive);
     parser.Parse("-N timothy".Split());
 }
예제 #39
0
        public void ShowHelp_WithAmericanLocale_ShowsEnglishHelpText()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("en-US")))
            {
                // Arrange
                var expected = @"Usage: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD
            Positional Arguments:
             FileToAdd         File to add to the thing.

            Optional Arguments:
             --turnonthepower  Set power level to 9001.
             -c                A cool counter.
             -h, --help        Display this help document.
             -s                Start date.
             --version         Displays the version of the current executable.";

                var opt = new LocalizationOptions();
                var parser = new CliParser<LocalizationOptions>(opt);
                var help = new AutomaticHelpGenerator<LocalizationOptions>();  // TODO simplify work required to get help info

                // Act
                var actual = help.GetHelp(parser.Config);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
예제 #40
0
        public void ShowHelp_WithMexicanLocale_ShowsSpanishHelpText()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX")))
            {
                // Arrange
                var expected = @"Uso: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD
            Los Argumentos Posicionales:
             FileToAdd         Archivo para añadir a la cosa.

            Los Argumentos Opcionales:
             --turnonthepower  Establecer el nivel de potencia de 9001.
             -c                Un contador fresco.
             -h, --help        Mostrar este documento de ayuda.
             -s                Fecha de inicio.
             --version         Muestra la versión del ejecutable actual.";

                var opt = new LocalizationOptions();
                var parser = new CliParser<LocalizationOptions>(opt);
                var help = new AutomaticHelpGenerator<LocalizationOptions>();

                // Act
                var actual = help.GetHelp(parser.Config);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
예제 #41
0
파일: VerbUnitTest.cs 프로젝트: nemec/clipr
        public void Parse_WithVerbHavingDefaultConstructor_ParsesVerb()
        {
            const string expected = "myfile.txt";
            var opt = new OptionsWithVerbDefaultConstructor();
            var parser = new CliParser<OptionsWithVerbDefaultConstructor>(opt);

            parser.Parse("add myfile.txt".Split());

            Assert.AreEqual(expected, opt.AddInfo.Filename);
        }
예제 #42
0
        public void ParseNumber_WithMexicanLocaleAndMexicanNumberFormat_ParsesNumberCorrectly()
        {
            using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX")))
            {
                // Arrange
                var expected = 2.3;

                var opt = new LocalizationOptions();
                var parser = new CliParser<LocalizationOptions>(opt);
                var help = new AutomaticHelpGenerator<LocalizationOptions>();

                // Act
                parser.Parse("-c 2.3 file.txt".Split());

                // Assert
                Assert.AreEqual(expected, opt.MyCounter);
            }
        }
예제 #43
0
        public void PositionalArgument_WithLowerBoundCountEqualsZero_ParsesAllArguments()
        {
            var opts = new PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero();
            var arguments = new[] { "first", "second" };
            var parser = new CliParser<PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero>(opts);

            parser.Parse(arguments);

            Assert.AreEqual(2, opts.Args.Count);
        }
예제 #44
0
        public void PositionalArgument_WithMultiplePositionalArgumentsAndLowerBoundCountEqualsZero_ParsesOtherArguments()
        {
            var opts = new PositionalArgumentUnitTest.MultiplePositionalArgumentLowerBoundCountEqualsZero();
            var arguments = new[] { "fixed" };
            var parser = new CliParser<PositionalArgumentUnitTest.MultiplePositionalArgumentLowerBoundCountEqualsZero>(opts);

            parser.Parse(arguments);

            Assert.AreEqual(0, opts.Args.Count);
        }
예제 #45
0
파일: VerbUnitTest.cs 프로젝트: nemec/clipr
        public void Parse_WithFactoryAndVerbHavingNoDefaultConstructor_ParsesVerb()
        {
            const string expected = "myfile.txt";
            var opt = new OptionsWithNoDefaultConstructor();
            var factory = new SimpleVerbfactory
            {
                { typeof(VerbWithNoDefaultConstructor), () => new VerbWithNoDefaultConstructor("default.txt") }
            };
            var parser = new CliParser<OptionsWithNoDefaultConstructor>(
                opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithNoDefaultConstructor>(), factory);

            parser.Parse("add myfile.txt".Split());

            Assert.AreEqual(expected, opt.AddInfo.Filename);
        }
예제 #46
0
        public void NamedArgument_WithLowerBoundCountEqualsZero_ParsesAllArguments()
        {
            var opts = new NamedArgumentLowerBoundCountEqualsZero();
            var arguments = new[] { "-s", "first", "second" };
            var parser = new CliParser<NamedArgumentLowerBoundCountEqualsZero>(opts);

            parser.Parse(arguments);

            Assert.AreEqual(2, opts.Args.Count);
        }
예제 #47
0
        public void NamedArgument_WithLowerBoundCountEqualsZero_ParsesNoArguments()
        {
            var opts = new NamedArgumentLowerBoundCountEqualsZero();
            var arguments = new string[0];
            var parser = new CliParser<NamedArgumentLowerBoundCountEqualsZero>(opts);

            parser.Parse(arguments);

            Assert.AreEqual(0, opts.Args.Count);
        }