コード例 #1
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void EffectivelyEmptyArgumentsParse()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { null, "" });
     parser.Target.Should().BeNull("effectively empty argument set should have null target");
     parser.Targets.Should().NotBeNull("effectively empty argument set should not have null targets");
     parser.Targets.Should().HaveCount(0, "effectively empty argument set should have no targets");
 }
コード例 #2
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void EmptyParse()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[0]);
     parser.Target.Should().BeNull("empty argument set should have null target");
     parser.Targets.Should().NotBeNull("empty argument set should not have null targets");
     parser.Targets.Should().HaveCount(0, "empty argument set should have no targets");
 }
コード例 #3
0
ファイル: ArgumentParserTests.cs プロジェクト: ramarag/XTask
 public void MultipartArgument()
 {
     CommandLineParser parser = new CommandLineParser(null);
     parser.Parse(new string[] { @"/foo:bar", @"/foo:foo" });
     parser.Target.Should().BeNull("only switch arguments should have null target");
     parser.Targets.Should().NotBeNull("only switch arguments should not have null targets");
     parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets");
     parser.GetOption<string>("foo").Should().Be("bar;foo", "foo's value was specified via two switches");
 }
コード例 #4
0
ファイル: ArgumentParserTests.cs プロジェクト: ramarag/XTask
        public void NullParse()
        {
            CommandLineParser parser = new CommandLineParser(null);
            parser.Parse(null);

            parser.Target.Should().BeNull("null argument set should have null target");
            parser.Targets.Should().NotBeNull("null argument set should not have null targets");
            parser.Targets.Should().HaveCount(0, "null argument set should have no targets");
        }
コード例 #5
0
        public void FileArgument()
        {
            string path;
            IFileService fileService = TestFileServices.CreateSubstituteForFile(out path, "a\nb\nc\n@ @ @");
            CommandLineParser parser = new CommandLineParser(fileService);

            parser.Parse(new string[] { "Command", @"/foo:@" + path });
            parser.GetOption<string>("foo").Should().Be("a;b;c", "specified in file as a, b, c");
        }
コード例 #6
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void BasicSwitchArguments()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { @"/ foo", @"-BAR" });
     parser.Target.Should().BeNull("only switch arguments should have null target");
     parser.Targets.Should().NotBeNull("only switch arguments should not have null targets");
     parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets");
     parser.GetOption<bool>("foo").Should().BeTrue("foo switch should be true, even though it has a space");
     parser.GetOption<bool>("bar").Should().BeTrue("bar switch was set");
     parser.GetOption<bool>("Bar").Should().BeTrue("foo switch should be true, irrespective of case");
 }
コード例 #7
0
ファイル: ArgumentParserTests.cs プロジェクト: ramarag/XTask
 public void StringArgument()
 {
     CommandLineParser parser = new CommandLineParser(null);
     parser.Parse(new string[] { @"/foo:bar" });
     parser.Target.Should().BeNull("only switch arguments should have null target");
     parser.Targets.Should().NotBeNull("only switch arguments should not have null targets");
     parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets");
     parser.GetOption<string>("foo").Should().Be("bar", "foo's value was specified as bar");
     parser.GetOption<bool>("foo").Should().BeFalse("foo switch doesn't translate to bool");
     parser.GetOption<bool?>("foo").Should().NotHaveValue("foo switch doesn't translate to bool");
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: Priya91/XTask
        static int Main(string[] args)
        {
            ExitCode result = ExitCode.GeneralFailure;

            CommandLineParser parser = new CommandLineParser();
            parser.Parse(args);

            IArgumentProvider argumentProvider = ArgumentSettingsProvider.Create(parser);

            using (ITaskService taskService = XFileTaskService.Create())
            {
                ConsoleTaskExecution execution = new ConsoleTaskExecution(argumentProvider, taskService.TaskRegistry);
                result = execution.ExecuteTask();
            }

            return (int)result;
        }
コード例 #9
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
        public void BooleanSwitches()
        {
            CommandLineParser parser = new CommandLineParser();
            parser.Parse(new string[] { @"/foo", @"/bar:1", @"/foofoo:0", @"/barbar:false", @"/foobar:true" });
            parser.Target.Should().BeNull("only switch arguments should have null target");
            parser.Targets.Should().NotBeNull("only switch arguments should not have null targets");
            parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets");
            parser.GetOption<bool>("foo").Should().BeTrue("foo switch should be true");
            parser.GetOption<int>("foo").Should().Be(1, "foo switch should be also be 1");
            parser.GetOption<bool>("bar").Should().BeTrue("far switch should be true");
            parser.GetOption<int>("bar").Should().Be(1, "bar switch should be also be 1");
            parser.GetOption<bool>("foofoo").Should().BeFalse("foofoo switch should be false");
            parser.GetOption<int>("foofoo").Should().Be(0, "foofoo switch should be also be 0");
            parser.GetOption<bool>("barbar").Should().BeFalse("barbar switch should be false");
            parser.GetOption<int>("barbar").Should().Be(0, "barbar switch should be also be 0");
            parser.GetOption<bool>("foobar").Should().BeTrue("explicit foobar switch should be true");

            // TODO: Need to handle the float/double case
            // parser.GetOption<double>("foobar").Should().Be(1.0, "explicit foobar switch should be 1.0");
        }
コード例 #10
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void UnspecifiedHelp()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { "HeLp" });
     parser.Command.Should().Be("help", "no command should come back as help");
     parser.HelpRequested.Should().BeTrue("requested help");
     parser.Target.Should().BeNull("no targets specified");
     parser.Targets.Should().HaveCount(0, "no targets specified");
 }
コード例 #11
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void TargetedHelp()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { "Help", "command" });
     parser.Command.Should().Be("command", "command for help was specified as command");
     parser.HelpRequested.Should().BeTrue("requested help");
     parser.Target.Should().BeNull("no targets specified");
     parser.Targets.Should().HaveCount(0, "no targets specified");
 }
コード例 #12
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void SingleTarget()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { "command", "target" });
     parser.Command.Should().Be("command", "command was specified first");
     parser.Target.Should().Be("target", "single target should be target");
     parser.HelpRequested.Should().BeFalse("did not request help");
     parser.Targets.Should().HaveCount(1, "only specified one target");
 }
コード例 #13
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void SimpleCommand()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { "command" });
     parser.Command.Should().Be("command", "command was specified");
     parser.Target.Should().BeNull("no targets specified");
     parser.Targets.Should().HaveCount(0, "no targets specified");
 }
コード例 #14
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void NoCommand()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(null);
     parser.Command.Should().Be("help", "no command should come back as help");
     parser.Target.Should().BeNull("no targets specified");
     parser.Targets.Should().HaveCount(0, "no targets specified");
 }
コード例 #15
0
ファイル: ArgumentParserTests.cs プロジェクト: Priya91/XTask
 public void MultipleTarget()
 {
     CommandLineParser parser = new CommandLineParser();
     parser.Parse(new string[] { "command", "targetone", "targettwo" });
     parser.Command.Should().Be("command", "command was specified first");
     parser.Target.Should().Be("targetone", "first target should be target");
     parser.Targets.Should().HaveCount(2, "should have two targets");
 }
コード例 #16
0
ファイル: ArgumentParserTests.cs プロジェクト: ramarag/XTask
        public void FileTarget()
        {
            string path;
            IFileService fileService = TestFileServices.CreateSubstituteForFile(out path, "a\nb\nc\n@ @ @");
            CommandLineParser parser = new CommandLineParser(fileService);

            parser.Parse(new string[] { "Command", @"@" + path });
            parser.Targets.Should().ContainInOrder("a", "b", "c");
        }