예제 #1
0
        public void ArgumentParserGetArgumentCatagoryIsSameTypeAs_TOptions()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser.CreateArgumentCatagory <NoOptions>();
            Assert.IsType <NoOptions>(parser.GetArgumentCatagory <NoOptions>());
        }
예제 #2
0
        public void ArgumentParserGetArgumentCatagoryNotNull()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser.CreateArgumentCatagory <NoOptions>();
            Assert.NotNull(parser.GetArgumentCatagory <NoOptions>());
        }
예제 #3
0
        public void ParserShouldBeCaseInsensitiveOnNames(string argumentName)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser.CreateArgumentCatagory <BasicOptions>().WithArgument(x => x.Boolean);

            parser.Parse(argumentName);

            Assert.True(parser.GetArgumentCatagory <BasicOptions>().Boolean);
        }
예제 #4
0
        public void CommandArgumentsAreSparateFromBaseArgumentParser()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser.CreateArgumentCatagory <BasicOptions>().WithArgument(x => x.String).Name("basename");
            parser.CreateCommandCatagory <Commands>().WithCommand(x => x.CommandWithArguments, (cp) => cp.CreateArgumentCatagory <BasicOptions>().WithArgument(x => x.String).Name("basename"));

            Assert.NotSame(parser.GetCommandCatagory <Commands>().CommandWithArguments, parser);
            Assert.NotSame(parser.GetArgumentCatagory <BasicOptions>(), parser.GetCommandCatagory <Commands>().CommandWithArguments.GetCommandCatagory <BasicOptions>());
        }
예제 #5
0
        public void ParserCanHandleNames()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Boolean);

            parser.Parse("--boolean");

            Assert.True(parser.GetArgumentCatagory <BasicOptions>().Boolean);
        }
예제 #6
0
        public void ParserShouldBeCaseInsensitiveOnEnumNames(string argument, string value, SciFiShows enumValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Enum);

            parser.Parse(argument, value);

            Assert.Equal(enumValue, parser.GetArgumentCatagory <BasicOptions>().Enum);
        }
예제 #7
0
        public void ParserCanParseCharacterType(string argument, string character, char expectedValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Character)
            .Flag('c');

            parser.Parse(argument, character);

            Assert.Equal(expectedValue, parser.GetArgumentCatagory <BasicOptions>().Character);
        }
예제 #8
0
        public void ParserCanParseEnumType(string argument, SciFiShows enumValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Enum)
            .Flag('e');

            parser.Parse(argument, Enum.GetName(typeof(SciFiShows), enumValue));

            Assert.Equal(enumValue, parser.GetArgumentCatagory <BasicOptions>().Enum);
        }
예제 #9
0
        public void ParserCanParseFlaggableEnumType(string argument, FlaggableEnum enumValue, FlaggableEnum secondEnumValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.FlaggableEnum)
            .Flag('f');

            parser.Parse(argument, Enum.GetName(typeof(FlaggableEnum), enumValue), argument, Enum.GetName(typeof(FlaggableEnum), secondEnumValue));

            Assert.Equal(enumValue | secondEnumValue, parser.GetArgumentCatagory <BasicOptions>().FlaggableEnum);
        }
예제 #10
0
        public void ParserCanHandleStandardPrefix(string argumentWithStandardPrefix)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Boolean)
            .Flag('b');

            parser.Parse(argumentWithStandardPrefix);

            Assert.True(parser.GetArgumentCatagory <BasicOptions>().Boolean);
        }
예제 #11
0
        public void ParserCanParseSByte(string argument, string value, sbyte expectedValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.SignedByte)
            .Flag('s');

            parser.Parse(argument, value);

            Assert.Equal(expectedValue, parser.GetArgumentCatagory <BasicOptions>().SignedByte);
        }
예제 #12
0
        public void ParserCanParseInt(string argument, string value, int expectedValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Integer)
            .Flag('i');

            parser.Parse(argument, value);

            Assert.Equal(expectedValue, parser.GetArgumentCatagory <BasicOptions>().Integer);
        }
예제 #13
0
        public void ParserCanHandleEqualsDelimiter(string argumentUsingEqualsDelimiterWithValue, string value)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.String)
            .Flag('s');

            parser.Parse(argumentUsingEqualsDelimiterWithValue);

            Assert.Equal(value, parser.GetArgumentCatagory <BasicOptions>().String);
        }
예제 #14
0
        public void ParserCanParseBooleanType(string argument)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Boolean)
            .Flag('b');

            parser.Parse(argument);

            Assert.True(parser.GetArgumentCatagory <BasicOptions>().Boolean);
        }
예제 #15
0
        public void ParserCanParseStringType(string argument, string value)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.String)
            .Flag('s');

            parser.Parse(argument, value);

            Assert.Equal(value, parser.GetArgumentCatagory <BasicOptions>().String);
        }
예제 #16
0
        public void ParserCanParseDouble(string argument, string value, double expectedValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Double)
            .Flag('d');

            parser.Parse(argument, value);

            Assert.Equal(expectedValue, parser.GetArgumentCatagory <BasicOptions>().Double);
        }
예제 #17
0
        public void ParserCanParseULong(string argument, string value, ulong expectedValue)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.UnsignedLong)
            .Flag('u');

            parser.Parse(argument, value);

            Assert.Equal(expectedValue, parser.GetArgumentCatagory <BasicOptions>().UnsignedLong);
        }
예제 #18
0
        public void ParserCanHandleCommaSeperatedValuesOnFlaggableEnums(string[] argumentWithCommaSeperatedValues, FlaggableEnum value)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.FlaggableEnum)
            .Flag('f');

            parser.Parse(argumentWithCommaSeperatedValues);

            Assert.Equal(value, parser.GetArgumentCatagory <BasicOptions>().FlaggableEnum);
        }
예제 #19
0
        public void ParserShouldHaveNoOutputUponSuccess()
        {
            ArgumentParser parser = CreateArgumentParser(new ArgumentParserOptions {
                ApplicationName = "app"
            });

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Boolean);

            parser.Parse("--boolean");

            Assert.Equal(string.Empty, _consoleOutputHook.RawString.ToString());
        }
예제 #20
0
        public void ParserShouldCountArgumentsOnArgumentsSetToBeCountable(string[] argument, int expectedCount)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Integer)
            .Flag('i')
            .Countable();

            parser.Parse(argument);

            Assert.Equal(expectedCount, parser.GetArgumentCatagory <BasicOptions>().Integer);
        }
예제 #21
0
        public void ParserCanParseDateTimeTicksType(string argument, string value, long ticks)
        {
            DateTime expectedDateTime = new DateTime(ticks);

            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.DateTime)
            .Flag('d');

            parser.Parse(argument, value);

            Assert.Equal(expectedDateTime, parser.GetArgumentCatagory <BasicOptions>().DateTime);
        }
예제 #22
0
        public void RequiredArgumentShouldThrowErrorOnScreen()
        {
            ArgumentParser parser = CreateArgumentParser(new ArgumentParserOptions {
                ApplicationName = "app"
            });

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.String)
            .Required();

            parser.Parse();

            Assert.Equal($"app: error: argument '--string' is required{nl}{nl}Usage: app [OPTIONS]{nl}", _consoleOutputHook.RawString.ToString());
        }
예제 #23
0
        public void ParserShouldBeCaseSensitiveOnFlags()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Boolean)
            .Flag('b')
            .WithArgument(x => x.Byte)
            .Flag('B');

            parser.Parse("-B", "10");

            Assert.Equal(10, parser.GetArgumentCatagory <BasicOptions>().Byte);
            Assert.False(parser.GetArgumentCatagory <BasicOptions>().Boolean);
        }
예제 #24
0
        [Fact] // Has to be fact because decimal isn't CLR :(
        public void ParserCanParseDecimal()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <BasicOptions>()
            .WithArgument(x => x.Decimal)
            .Flag('d');

            parser.Parse("--decimal", "-79228162514264337593543950335");
            Assert.Equal(decimal.MinValue, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("--decimal", "-1");
            Assert.Equal(decimal.MinusOne, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("--decimal", "0");
            Assert.Equal(decimal.Zero, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("--decimal", "1");
            Assert.Equal(decimal.One, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("--decimal", "4112.4242");
            Assert.Equal((decimal)4112.4242, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("--decimal", "79228162514264337593543950335");
            Assert.Equal(decimal.MaxValue, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "-79228162514264337593543950335");
            Assert.Equal(decimal.MinValue, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "-1");
            Assert.Equal(decimal.MinusOne, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "0");
            Assert.Equal(decimal.Zero, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "1");
            Assert.Equal(decimal.One, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "4112.4242");
            Assert.Equal((decimal)4112.4242, parser.GetArgumentCatagory <BasicOptions>().Decimal);

            parser.Parse("-d", "79228162514264337593543950335");
            Assert.Equal(decimal.MaxValue, parser.GetArgumentCatagory <BasicOptions>().Decimal);
        }
예제 #25
0
        public void ParserShouldAddMultipleValuesOnMultiArguments()
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <MultiOptions>()
            .WithMultiArgument(x => x.String)
            .Flag('s');

            parser.Parse("--string", "value", "--string", "value2", "-s", "val3");

            ImmutableArray <string> values = parser.GetArgumentCatagory <MultiOptions>().String;

            Assert.Equal(3, values.Length);
            Assert.Equal("value", values[0]);
            Assert.Equal("value2", values[1]);
            Assert.Equal("val3", values[2]);
        }
예제 #26
0
        public void ParserCanHandleCommaSeperatedValuesOnDeliminatedArgument(string argumentWithCommaSeperatedValues, params string[] values)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <MultiOptions>()
            .WithMultiArgument(x => x.String)
            .Flag('s');

            parser.Parse(argumentWithCommaSeperatedValues);

            ImmutableArray <string> parsedValues = parser.GetArgumentCatagory <MultiOptions>().String;

            Assert.Equal(values.Length, parsedValues.Length);

            for (int i = 0; i < values.Length; i++)
            {
                Assert.Equal(values[i], parsedValues[i]);
            }
        }
예제 #27
0
        public void ParserTreatsArgumentsSeperateFromNameWithCommasAsSingleValue(string[] argumentWithCommaSeperatedValues, params string[] values)
        {
            ArgumentParser parser = ArgumentParser.Create("app");

            parser
            .CreateArgumentCatagory <MultiOptions>()
            .WithMultiArgument(x => x.String)
            .Flag('s');

            parser.Parse(argumentWithCommaSeperatedValues);

            ImmutableArray <string> parsedValues = parser.GetArgumentCatagory <MultiOptions>().String;

            Assert.Equal(values.Length, parsedValues.Length);

            for (int i = 0; i < values.Length; i++)
            {
                Assert.Equal(values[i], parsedValues[i]);
            }
        }
예제 #28
0
        //new BasicArgumentParser();
        // No such thing as scoped commands. Cannot have multiple 'multiple' positional arguments.
        // Last positional argument can be the only one with 'multiple' set to true
        // Can mix and match options throughout the command

        // Usage: app [OPTIONS] FILE [FILE...]
        //        app [OPTIONS] SOURCE DESTINATION
        //        app [OPTIONS] SOURCE DESTINATION [DESTINATION...]
        // app [opt] [source ] [ dest  ] [                            opt                      ] [  dest  ]
        // app -f -v file1.txt file3.txt -vvpoD --long-name-argument --argument-with-value value file46.txt

        //new ScopedArgumentParser();
        // Only scoped arguments allowed. First positional must be global scope arguments, second positional must be scope name.
        // After scope name all arguments are arguments for that scope.
        // Cannot mix and match scope-name/global arguments.
        // Can mix and match scope arguments. (After scope name is declared arguments after scope is a BasicArgumentParser)

        // Usage: app [OPTIONS] SCOPE [BasicArgumentParser]
        static void Main(string[] args)
        {
            ArgumentParser parser = ArgumentParser.Create(options =>
            {
                options.ApplicationName        = "simpleargumentsample";
                options.ApplicationDescription = "Simple Argument Sample Application";
            });

            parser.CreateCommandCatagory <SimpleCommands>()
            .WithCommand(c => c.Config);

            parser.CreateArgumentCatagory <GeneralOptions>()
            .WithArgument(x => x.MyEnum);

            //parser
            //    .CreateArgumentCatagory<GeneralOptions>()
            //        .WithArgument(x => x.Flag)
            //            .Required()
            //            .Name("blah")
            //            .DefaultValue(false)
            //        .WithArgument(x => x.MyEnum)
            //            .Help("This is the enum test. Should put the possible values after this.")
            //            .DefaultValue(MyEnum.Option2)
            //        .WithArgument(x => x.CountMe)
            //            .Help("This is a reallllllllly long help content box that will have to wrap around and stuff. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
            //            .DefaultValue(10)
            //            .Countable()
            //    .CreateArgumentCatagory<NetworkOptions>()
            //        .WithArgument(x => x.Integer)
            //            .Name("intplx")
            //            .Flag('i')
            //            .Help("Some help here is good for other things and stuff");

            //parser
            //    .CreateParameterCatagory<PositionalOptions>()
            //        .WithParameter(x => x.Source)
            //            .Required()
            //            .Name("longassparametername")
            //        .WithMultiParameter(x => x.Destination)
            //            .Required()
            //            .Name("dest")
            //            .Help("Parameters can have help too!");

            //parser
            //    .CreateCommandCatagory<Commands>()
            //        .WithCommand(x => x.Config, SetupConfigCommand)
            //            .Help("THis is config")
            //    .CreateCommandCatagory<SimpleCommands>()
            //        .WithCommand(x => x.Config)
            //            .Name("Thisisalongcommandnamehere")
            //            .Help("Some help on this command");

            parser.Parse(args);

            if (parser.HelpCalled)
            {
                return;
            }

            GeneralOptions go = parser.GetArgumentCatagory <GeneralOptions>();

            //NetworkOptions no = parser.GetArgumentCatagory<NetworkOptions>();
            //PositionalOptions po = parser.GetParameterCatagory<PositionalOptions>();


            //Console.WriteLine("general options");
            //Console.WriteLine(JsonConvert.SerializeObject(go));


            //Console.WriteLine("network options");
            //Console.WriteLine(JsonConvert.SerializeObject(no));

            //Console.WriteLine("positional options");
            //Console.WriteLine(JsonConvert.SerializeObject(po));

            //Console.WriteLine(parser.Passthrough);

            //Commands c = parser.GetCommandCatagory<Commands>();
            //SimpleCommands sc = parser.GetCommandCatagory<SimpleCommands>();

            //ConfigCommands cc = c.Config.GetArgumentCatagory<ConfigCommands>();

            //foreach (var item in args)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine();
            //parser.CreateArgumentCatagory<GeneralOptions>().WithArgument(x => x.String);
            //parser.Parse(args);
        }