예제 #1
0
        public object Parse(string commandLine)
        {
            ICommandLineParser parser = new MonadicCommandLineParser();
            var args = parser.Parse(commandLine);
            var ap   = from a in args
                       select a;

            return(null);
        }
예제 #2
0
        static ValueProvider CreateDictionaryProvider(string commandLine)
        {
            IEnumerable<ICommandLineElement> elements = new MonadicCommandLineParser().Parse(commandLine);

            Dictionary<string, object> dictionary = elements.Where(x => x is IDefinitionElement)
                .Cast<IDefinitionElement>()
                .Select(x => new Tuple<string, object>(x.Key, x.Value))
                .Union(elements.Where(x => x is ISwitchElement)
                       	.Cast<ISwitchElement>()
                       	.Select(x => new Tuple<string, object>(x.Key, x.Value)))
                .ToDictionary(x => x.First, x => x.Second, StringComparer.InvariantCultureIgnoreCase);

            var provider = new DictionaryValueProvider(dictionary);

            return provider;
        }
예제 #3
0
        public void dru()
        {
            string commandLine = "cmd -file";

            ICommandLineParser parser = new MonadicCommandLineParser();

            Trace.WriteLine("Command Line: " + commandLine);

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(2);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <DefinitionElement>();
            ((DefinitionElement)elements[1]).Value.ShouldEqual("");
        }
예제 #4
0
        public void A_simple_path_specification_should_be_allowed()
        {
            string commandLine = "add --all .";

            Trace.WriteLine("Command Line: " + commandLine);

            ICommandLineParser parser = new MonadicCommandLineParser();

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(3);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <SwitchElement>();
            elements[2].ShouldBeAnInstanceOf <ArgumentElement>();
        }
예제 #5
0
        public void Should_handle_a_nested_set_of_commands_and_flags()
        {
            string commandLine = "config --global net.framework net-3.5";

            Trace.WriteLine("Command Line: " + commandLine);

            ICommandLineParser parser = new MonadicCommandLineParser();

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(4);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <SwitchElement>();
            elements[2].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[3].ShouldBeAnInstanceOf <ArgumentElement>();
        }
예제 #6
0
        public void Should_handle_escape_characters_in_the_line()
        {
            string commandLine = "cmd -file \"\\\"c:\\\\system\\\\something\\'s cooking.txt\\\"\"";

            ICommandLineParser parser = new MonadicCommandLineParser();

            Trace.WriteLine("Command Line: " + commandLine);

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(2);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <DefinitionElement>();

            ((DefinitionElement)elements[1]).Value.ShouldEqual("\"" + @"c:\system\something's cooking.txt" + "\"");
        }
예제 #7
0
        public void A_git_style_command_should_be_supported()
        {
            string commandLine = "remote add dru git://github.com/drusellers/nu.git";

            Trace.WriteLine("Command Line: " + commandLine);

            ICommandLineParser parser = new MonadicCommandLineParser();

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(4);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[2].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[3].ShouldBeAnInstanceOf <ArgumentElement>();
        }
예제 #8
0
        public void A_path_with_spaces_in_double_quotes_should_be_kept_together()
        {
            string commandLine = "\"c:\\Folder With Spaces\\run.exe\" "
                                 + "-f \"c:\\Folder With Spaces\\file.txt\" "
                                 + "-l:\"c:\\Folder With Spaces\\file.txt\" ";

            Trace.WriteLine("Command Line: " + commandLine);

            ICommandLineParser parser = new MonadicCommandLineParser();

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(3);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <DefinitionElement>();
            elements[2].ShouldBeAnInstanceOf <DefinitionElement>();
        }
예제 #9
0
        public void Should_return_an_enumeration_of_elements()
        {
            string commandLine = "update -a -b -d:true -e \"frank\" -f \"go hornets\" [filename]";

            ICommandLineParser parser = new MonadicCommandLineParser();

            Trace.WriteLine("Command Line: " + commandLine);

            var elements = parser.Parse(commandLine).ToArray();

            Trace.WriteLine(string.Join(Environment.NewLine, elements.Select(x => x.ToString()).ToArray()));

            elements.Count().ShouldEqual(7);
            elements[0].ShouldBeAnInstanceOf <ArgumentElement>();
            elements[1].ShouldBeAnInstanceOf <SwitchElement>();
            elements[2].ShouldBeAnInstanceOf <SwitchElement>();
            elements[3].ShouldBeAnInstanceOf <DefinitionElement>();
            elements[4].ShouldBeAnInstanceOf <DefinitionElement>();
            elements[5].ShouldBeAnInstanceOf <DefinitionElement>();
            elements[6].ShouldBeAnInstanceOf <TokenElement>();
        }
        static IEnumerable <ICommandLineElement> P(string commandLine)
        {
            var parser = new MonadicCommandLineParser();

            return(parser.Parse(commandLine));
        }