Example #1
0
        public void AllTest()
        {
            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Option("-h", "--help").Description("Show help.").Configure()
            .Option("-i", "--input").Description("Input file.").HasValue().Configure()
            .Command("help").Description("Show help.").Configure()
            .Command("input").Description("Input file.").HasValue().Configure()
            .Argument("input");
            var usage = argumentHelper.GetUsage();

            var expected = new StringBuilder();

            expected.AppendLine("Usage: [options] [commands] [input]");
            expected.AppendLine();
            expected.AppendLine("options:");
            expected.AppendLine("  -h|--help     Show help.");
            expected.AppendLine("  -i|--input    Input file.");
            expected.AppendLine();
            expected.AppendLine("commands:");
            expected.AppendLine("  help  Show help.");
            expected.AppendLine("  input Input file.");

            Assert.AreEqual(expected.ToString(), usage);
        }
Example #2
0
        public void CommandExistsTest()
        {
            var args = new[] { "help" };

            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Command("help");
            var arguments = argumentHelper.Parse(args);

            Assert.IsTrue(arguments.Commands.Contains("help"));
        }
Example #3
0
        public void ConfigureSingleOptionTest()
        {
            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Option("-h");

            var option = argumentHelper.Configuration.Options.Single(o => o.Options.Contains("-h"));

            Assert.AreEqual(1, option.Options.Count);
            Assert.AreEqual("-h", option.Options[0]);
        }
Example #4
0
        public void MultipleOptionsValueCanBeFoundTest()
        {
            var args = new[] { "-i", "foo.bar" };

            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Option("-i", "--input").HasValue();
            var arguments = argumentHelper.Parse(args);

            Assert.AreEqual("foo.bar", arguments.Options["-i"]);
            Assert.AreEqual("foo.bar", arguments.Options["--input"]);
        }
Example #5
0
        public void MultipleOptionsCanBeFoundTest()
        {
            var args = new[] { "-h" };

            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Option("-h", "--help");
            var arguments = argumentHelper.Parse(args);

            Assert.IsTrue(arguments.Options.Contains("-h"));
            Assert.IsTrue(arguments.Options.Contains("--help"));
        }
Example #6
0
        public void CommandArgumentValueTest()
        {
            var args = new[] { "foo.bar", "bar.foo" };

            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Argument("input").Configure()
            .Argument("output");
            var arguments = argumentHelper.Parse(args);

            Assert.AreEqual("foo.bar", arguments.Arguments[0]);
            Assert.AreEqual("bar.foo", arguments.Arguments[1]);
        }
Example #7
0
        public void CommandArgumentTest()
        {
            var args = new[] { "input", "foo.bar", "output", "bar.foo" };

            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Command("input").HasValue().Configure()
            .Command("output").HasValue();
            var arguments = argumentHelper.Parse(args);

            Assert.AreEqual("foo.bar", arguments.Commands["input"]);
            Assert.AreEqual("bar.foo", arguments.Commands["output"]);
        }
Example #8
0
        public void ArgumentsTest()
        {
            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Argument("arg1");
            var usage = argumentHelper.GetUsage();

            var expected = new StringBuilder();

            expected.AppendLine("Usage: [arg1]");

            Assert.AreEqual(expected.ToString(), usage);
        }
Example #9
0
        public void CommandDoesNotTouchDescriptionWhenCharsAreAtTabEndTest()
        {
            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Command("345678").Description("description");
            var usage = argumentHelper.GetUsage();

            var expected = new StringBuilder();

            expected.AppendLine("Usage: [commands]");
            expected.AppendLine();
            expected.AppendLine("commands:");
            expected.AppendLine("  345678        description");

            Assert.AreEqual(expected.ToString(), usage);
        }
Example #10
0
        public void OptionDoesNotTouchDescriptionWhenCharsAreAtTabEndTest()
        {
            var argumentHelper = new ArgumentHelper();

            argumentHelper.Configure()
            .Option("-a", "--abcdefghi").Description("description");
            var usage = argumentHelper.GetUsage();

            var expected = new StringBuilder();

            expected.AppendLine("Usage: [options]");
            expected.AppendLine();
            expected.AppendLine("options:");
            expected.AppendLine("  -a|--abcdefghi        description");

            Assert.AreEqual(expected.ToString(), usage);
        }
Example #11
0
        public void ConfigureNullOptionTest()
        {
            var argumentHelper = new ArgumentHelper();

            Assert.ThrowsException <ArgumentNullException>(() => argumentHelper.Configure().Option(null));
        }