Beispiel #1
0
        public static ArgumentParserResult Parse(IEnumerable <string> args)
        {
            var arguments = new Dictionary <string, string>();

            try
            {
                foreach (var argument in args)
                {
                    var idx = argument.IndexOf(':');
                    if (idx > 0)
                    {
                        arguments[argument.Substring(0, idx)] = argument.Substring(idx + 1);
                    }
                    else
                    {
                        arguments[argument] = string.Empty;
                    }
                }

                return(ArgumentParserResult.Success(arguments));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(ArgumentParserResult.Failure());
            }
        }
        public void TestMsBuild()
        {
            var dic = ArgumentParserResult.Parse("/p:Configuration=Release /p:X=Y ").OptionsDictionary;

            Assert.AreEqual(1, dic.Count);
            Assert.AreEqual(2, dic["p"].Length);
            Assert.AreEqual("Configuration=Release", dic["p"][0]);
        }
        public void TestSvcUtil()
        {
            var dic = ArgumentParserResult.Parse("/namespace:http://schemas.datacontract.org/2004/07/WcfService19,MyNamespace").OptionsDictionary;

            Assert.AreEqual(1, dic.Count);
            Assert.AreEqual("namespace", dic.First().Key);
            Assert.AreEqual("http://schemas.datacontract.org/2004/07/WcfService19,MyNamespace", dic["namespace"][0]);
        }
        public void TestMultipleInstancesOfTheSameParameter()
        {
            var dic = ArgumentParserResult.Parse("/abc=sdfd /abc  \"This is some\" ok").OptionsDictionary;

            Assert.AreEqual(3, dic["abc"].Length);
            Assert.AreEqual("sdfd", dic["abc"][0]);
            Assert.AreEqual("ok", dic["abc"][2]);
        }
        public void TestBasic()
        {
            var dic = ArgumentParserResult.Parse("/abc  sdfd /efg  \"This is some\" ok").OptionsDictionary;

            Assert.AreEqual(2, dic.Count);
            Assert.AreEqual("abc", dic.First().Key);
            Assert.AreEqual(1, dic["abc"].Length);
            Assert.AreEqual(2, dic["efg"].Length);
            Assert.AreEqual("This is some", dic["efg"][0]);
        }
Beispiel #6
0
 public static bool runCheck(ArgumentParserResult parsed)
 {
     if (parsed.Arguments.ContainsKey("/input") && parsed.Arguments.ContainsKey("/outdir") && parsed.Arguments.ContainsKey("/outfile"))
     {
         return(true);
     }
     else
     {
         Console.WriteLine("You must specify the input file (/input:path/to/file.exe) and output directory (/outdir:path/to/output/directory)");
         return(false);
     }
 }
        public void TestFixedParameters()
        {
            var result = ArgumentParserResult.Parse("abc efg   \"this file is ok\"   /p:Configuration=Release /p:X=Y ");
            var dic    = result.OptionsDictionary;

            Assert.AreEqual(1, dic.Count);
            Assert.AreEqual(2, dic["p"].Length);
            Assert.AreEqual("Configuration=Release", dic["p"][0]);
            var fixedParameters = result.FixedParameters.ToArray();

            Assert.AreEqual(3, fixedParameters.Length);
            Assert.AreEqual("abc", fixedParameters[0]);
            Assert.AreEqual("this file is ok", fixedParameters[2]);
        }
        public void TestMakeCert()
        {
            var dic = ArgumentParserResult.Parse("-sk keyname -# 1234 -$ commercial -? -! -b 12/11/2014 -eku 123.456.789, 2244.2343.3 , 348.343 -nscp -sky exchange -sp \"Microsoft RSA SChannel Cryptographic Provider\" -sy 12 -n \"CN=XXZZYY\"").OptionsDictionary;

            Assert.AreEqual(12, dic.Count);
            Assert.AreEqual("sk", dic.First().Key);
            Assert.AreEqual(0, dic["?"].Length);
            Assert.AreEqual(0, dic["!"].Length);
            Assert.AreEqual("12/11/2014", dic["b"][0]);
            Assert.AreEqual("123.456.789,", dic["eku"][0]);
            Assert.AreEqual("Microsoft RSA SChannel Cryptographic Provider", dic["sp"][0]);
            Assert.AreEqual("12", dic["sy"][0]);
            Assert.AreEqual("CN=XXZZYY", dic["n"][0]);
        }
Beispiel #9
0
 private bool ResultsEqual(ArgumentParserResult actualResult, ArgumentParserResult expectedResult)
 {
     /*
      * var expectedDateRangeResult = expectedResult.DateRangeResult;
      * var expectedExecutionPolicyResult = expectedResult.ExecutionPolicyResult;
      * var actualDateRangeResult = actualResult.DateRangeResult;
      * var actualExecutionPolicyResult = actualResult.ExecutionPolicyResult;
      *
      * return (
      *      expectedDateRangeResult.DateRange.From == actualDateRangeResult.DateRange.From &&
      *      expectedDateRangeResult.DateRange.To == actualDateRangeResult.DateRange.To &&
      *      expectedExecutionPolicyResult.ExecuteAllScripts == actualExecutionPolicyResult.ExecuteAllScripts &&
      *      expectedExecutionPolicyResult.Exception.GetType() == actualExecutionPolicyResult.Exception.GetType()
      * );
      */
     return(false);
 }
Beispiel #10
0
        public void TestRobocopy()
        {
            var dic = ArgumentParserResult.Parse("/s /lev:32 /copy:astou  /a+:RASH  /a-:CU  /256 /rh:1233-2356 /xf thisfile.txt \"c:\\test\\this dir\\something.txt\" /save:jobname").OptionsDictionary;

            Assert.AreEqual(9, dic.Count);
            Assert.AreEqual("s", dic.First().Key);
            Assert.AreEqual(0, dic["s"].Length);
            Assert.AreEqual(2, dic["xf"].Length);
            Assert.AreEqual("32", dic["lev"][0]);
            Assert.AreEqual("astou", dic["copy"][0]);
            Assert.AreEqual("RASH", dic["a+"][0]);
            Assert.AreEqual("CU", dic["a-"][0]);
            Assert.AreEqual(0, dic["256"].Length);
            Assert.AreEqual("1233-2356", dic["rh"][0]);
            Assert.AreEqual("thisfile.txt", dic["xf"][0]);
            Assert.AreEqual("c:\\test\\this dir\\something.txt", dic["xf"][1]);
            Assert.AreEqual("jobname", dic["save"][0]);
        }
Beispiel #11
0
        public static void Main(string[] args)
        {
            Info.ShowLogo();

            // try to parse the command line arguments, show usage on failure and then bail
            ArgumentParserResult parsed = ArgumentParser.Parse(args);

            if (!parsed.ParsedOk)
            {
                Info.ShowUsage();
                return;
            }
            // Try to execute the command using the arguments passed in
            string commandName  = (0 != args.Length) ? args[0] : string.Empty;
            bool   commandFound = new CommandCollection().ExecuteCommand(commandName, parsed.Arguments);

            // show the usage if no commands were found for the command name
            if (!commandFound)
            {
                Info.ShowUsage();
            }
        }
Beispiel #12
0
        public void TestSilly()
        {
            var dic = ArgumentParserResult.Parse("abcde dsfdfd sdf").OptionsDictionary;

            Assert.AreEqual(0, dic.Count);
        }
Beispiel #13
0
 internal ArgumentParseFailedResult(CommandContext context, ArgumentParserResult parserResult)
 {
     Command      = context.Command;
     RawArguments = context.RawArguments;
     ParserResult = parserResult;
 }