Exemple #1
0
        public void Arguments()
        {
            string args;

            Energy.Base.Command.Arguments argv;
            args = "/help";
            argv = new Energy.Base.Command.Arguments(args)
                   .Switch("help")
                   .Slash(true)
                   .Parse();
            Assert.IsNotNull(argv);
            Assert.IsFalse(argv["help"].IsEmpty);
            argv.Alias("?", "help").Parse("");
            Assert.IsNotNull(argv);
            Assert.IsTrue(argv["help"].IsEmpty);
            argv.Alias("?", "help");
            argv.Parse("/?");
            Assert.IsNotNull(argv);
            Assert.IsFalse(argv["help"].IsEmpty);

            args = @"-q --b -abc /? param1 ""param -x 2"" -- param3 /opt1/opt2";
            argv = new Energy.Base.Command.Arguments(args)
                   .Alias("q", "quiet")
                   .Alias("?", "help")
                   .Switch("help")
                   .Switch("quiet")
                   .Parameter("help", 0)
                   .Parameter("input")
                   .Parameter("output")
                   .Alias("i", "input")
                   .Help("input", "Input file")
                   //.Strict(true)
                   //.Slash(true)
                   .Parse();
            Assert.IsNotNull(argv);

            argv.Long(false).Short(false).Slash(false);
            argv.Parse();

            Assert.AreEqual(9, argv.Count);

            int n;

            n = 0;
            argv.Options.ForEach((x) =>
            {
                if (!x.IsNull)
                {
                    n++;
                }
            });
            Assert.AreEqual(0, n);

            argv.Skip(1).Parse();
            Assert.AreEqual(8, argv.Count);
        }
Exemple #2
0
 private static bool Setup(string[] args)
 {
     Energy.Base.Command.Arguments arguments = new Energy.Base.Command.Arguments(args)
                                               .Parameter("type").Alias("t", "type")
                                               .Parameter("host").Alias("h", "host")
                                               .Parameter("port").Alias("p", "port")
                                               .Parameter("rack").Alias("r", "rack")
                                               .Parameter("slot").Alias("s", "slot")
                                               .Switch("interactive").Alias("i", "interactive")
                                               .Switch("quiet").Alias("q", "quiet")
                                               .Parameter("execute").Alias("x", "execute")
                                               .Switch("help").Alias("?", "help").Alias("8888", "help")
                                               .Help("type", "PLC type")
                                               .Description("type", "1200, 300, 200, 400, 1500 or LOGO")
                                               .Example("type", "1200")
                                               .Help("host", "IP host or address")
                                               .Example("host", "192.168.0.1")
                                               .Parse()
     ;
     if (!arguments["help"].IsEmpty)
     {
         PrintHelp(arguments);
         return(false);
     }
     if (!arguments["type"].IsEmpty)
     {
         Global.Configuration.Type = arguments["type"].Value;
     }
     if (!arguments["host"].IsEmpty)
     {
         Global.Configuration.Host = arguments["host"].Value;
     }
     if (!arguments["port"].IsEmpty)
     {
         Global.Configuration.Port = arguments["port"].Value;
     }
     if (!arguments["rack"].IsEmpty)
     {
         Global.Configuration.Rack = arguments["rack"].Value;
     }
     if (!arguments["slot"].IsEmpty)
     {
         Global.Configuration.Slot = arguments["slot"].Value;
     }
     Global.Configuration.Interactive = !arguments["interactive"].IsEmpty;
     Global.Configuration.Quiet       = !arguments["quiet"].IsEmpty;
     return(true);
 }