Exemple #1
0
        public void UnexpectedOptionExceptionTests(params string[] args)
        {
            GetOptBase <Opt2> getOpt = new GetOptBase <Opt2>();

            getOpt.AddOpt(o => o.a)
            .HasShortName("a");
            getOpt.AddOpt(o => o.b)
            .HasShortName("b");
            getOpt.AddOpt(o => o.c)
            .HasShortName("c");

            Xunit.Assert.Throws <UnexpectedOptionException>(() => getOpt.GetOpts(args));
        }
Exemple #2
0
        public void RequiredAndOptionalArg()
        {
            GetOptBase <Opts> getOpt = new GetOptBase <Opts>();

            getOpt.AddOpt(o => o.isA)
            .HasShortName("a")
            .IsRequired();
            getOpt.AddOpt(o => o.isA)
            .HasShortName("b");
            _testOutputHelper.WriteLine(getOpt.GenerateUsage());

            getOpt.GenerateUsage().Should().Contain("Usage: Application -a [OPTIONS]...");
        }
Exemple #3
0
        public void _Sandbox()
        {
            GetOptBase <Opts> getOpt = new GetOptBase <Opts>();

            getOpt.ApplicationName = "TestApp.exe";
            getOpt.TopDescription  =
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget sodales nibh. Sed a justo id velit tristique iaculis. Aenean mauris ante, luctus eget elit eget, accumsan aliquet erat.";
            getOpt.BottomDescription =
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget sodales nibh. Sed a justo id velit tristique iaculis. Aenean mauris ante, luctus eget elit eget, accumsan aliquet erat. Quisque posuere sagittis ex, sed porttitor ex elementum vitae. Nulla viverra velit vel sapien dictum ultrices. Sed neque nibh, gravida nec mattis ut, bibendum quis lectus. Ut euismod tempor turpis. Nullam ac luctus libero, in vestibulum enim. Nullam maximus posuere metus sed tincidunt. Curabitur eget est quam. Aliquam ac ligula consectetur, pharetra elit at, viverra lectus. Nunc venenatis iaculis risus, id molestie mi malesuada id. Maecenas placerat blandit lacus, ut fermentum mi maximus nec. Nulla vehicula dapibus quam.";


            getOpt.AddOpt(o => o.isA)
            .HasShortName("a")
            .HasLongName("long")
            .IsRequired()
            .IsIncompatibleWith("--longc")
            .Requires("-b")
            .WithOptionalArgument(o => o.aArg)
            .HasDescription("I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. ");

            getOpt.AddOpt(o => o.isA)
            .HasShortName("b")
            .HasLongName("Some really f****d up name of long opt. Really f****d up ")
            .IsRequired()
            .Requires("-a")
            .IsIncompatibleWith("--longc")
            .WithOptionalArgument(o => o.aArg).WithName("Some really f****d up na of argument")
            .HasDescription("I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. ");

            getOpt.AddOpt(o => o.isA)
            .HasLongName("--longc")
            .IsRequired()
            .WithOptionalArgument(o => o.aArg)
            .HasDescription(
                "I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. I am some a longed option. ")
            .IsIncompatibleWith("-a", "-b");

            getOpt.AddArg(o => o.arg, s => s)
            .IsRequired()
            .HasDescription("prcat")
            .HasHelpText("prcat help")
            .IsVariadic();


            _testOutputHelper.WriteLine(getOpt.GenerateUsage());
        }
Exemple #4
0
        public void LongOptTests(string[] args, bool aExp, bool bExp, bool cExp)
        {
            GetOptBase <Opt2> getOpt = new GetOptBase <Opt2>();

            getOpt.AddOpt(o => o.a)
            .HasLongName("A");
            getOpt.AddOpt(o => o.b)
            .HasLongName("B");
            getOpt.AddOpt(o => o.c)
            .HasLongName("C");


            Opt2 opts = getOpt.GetOpts(args);

            opts.a.Should().Be(aExp);
            opts.b.Should().Be(bExp);
            opts.c.Should().Be(cExp);
        }
Exemple #5
0
        public void BasicOptTests(string[] args, bool aExp, bool bExp, bool cExp)
        {
            GetOptBase <Opt2> getOpt = new GetOptBase <Opt2>();

            getOpt.AddOpt(o => o.a)
            .HasShortName("a");
            getOpt.AddOpt(o => o.b)
            .HasShortName("b");
            getOpt.AddOpt(o => o.c)
            .HasShortName("c");


            Opt2 opts = getOpt.GetOpts(args);

            opts.a.Should().Be(aExp);
            opts.b.Should().Be(bExp);
            opts.c.Should().Be(cExp);
        }
Exemple #6
0
        public void OptionalArgumentShort(OptDefinitionArgumentFormat format, string excepted)
        {
            GetOptBase <Opt2> getOpt = new GetOptBase <Opt2>();

            getOpt.AddOpt(o => o.b)
            .HasShortName("b")
            .WithOptionalArgument(o => o.b_file).FormattedAs(format).WithName("tmp")
            .HasDescription("file TMP is optional and will be passed via b option")
            .IsRequired();

            var res = getOpt.GenerateUsage();

            _testOutputHelper.WriteLine(res);
            res.Should().Contain(excepted);
        }
Exemple #7
0
        public void BasicArgOptTests(OptDefinitionArgumentFormat format, params string[] args)
        {
            GetOptBase <Opt2> getOpt = new GetOptBase <Opt2>();

            getOpt.AddOpt(o => o.b)
            .HasShortName("b")
            .HasLongName("big-file")
            .WithRequiredArgument(o => o.b_file)
            .FormattedAs(format);

            var res = getOpt.GetOpts(args);

            res.b.Should().Be(true);
            res.b_file.Should().Be("argument");
        }