Beispiel #1
0
        /*  ALIAS
            GNU Options
                -d=DIR, --dir=DIR
                    Install the script into directory DIR, rather than
                    searching for a suitable directory in $PATH.
                -m, --manpage
                    Display the manpage for the alias script given as the
                    single argument. The alias can be an absolute pathname, or
                    the name of a script in $PATH. If the argument isn't an
                    alias script, or if multiple arguments are given, then all
                    arguments are passed to the system 'man' command. This
                    allows you to alias your man command like this:
                    alias man='0alias --manpage'
                -r, --resolve
                    Print the interface URI for the given alias script to stdout

            GNU Standard Options
                -h, --help
                    Show the built-in help text.
                -V, --version
                    Display version information.
        */
        static void Main(string[] args)
        {
            // Set parser
            OptionParser parser = new OptionParser();
            parser.ProgramInfo.Name = "Alias";
            parser.ProgramInfo.Version = "1.3.2.1";

            // Add reqired option, which has reqired parameter
            OptionValue<string> dir = new OptionValue<string>();
            parser.AddOption(
                new Option(new string[] { "-d", "--dir" },
                    "Install the script into directory DIR, rather than searching for a suitable directory in $PATH.",
                    new StoreAction<string>(dir)
                ) { Required = true, ParametersRequired = true}
            );

            // Add option, which has not any parameter
            OptionValue<bool> manpage = new OptionValue<bool>(false);
            parser.AddOption(
                new Option(new string[] { "-m", "--manpage" },
                    "Display the manpage for the alias script given as the single argument.",
                    new StoreConstAction<bool>(manpage, true)
                ) { ParametersCount = 0 }
            );

            // Add option, which has not any parameter
            OptionValue<bool> resolve = new OptionValue<bool>(false);
            parser.AddOption(
                new Option(new string[] { "-r", "--resolve" },
                    "Print the interface URI for the given alias script to stdout.",
                    new StoreConstAction<bool>(resolve, true)
                ) { ParametersCount = 0 }
            );

            try
            {
                // Run options parser (for example with args: --dir ./rootdir/nextdir/ -r)
                IList<string> remainingArgs = parser.ParseArguments(args);
                Console.WriteLine("dir: {0}", dir.Value);
                Console.WriteLine("manpage: {0}", manpage.Value);
                Console.WriteLine("resolve: {0}", resolve.Value);
            }
            catch (ParseException exception)
            {
                // User control the exception
                System.Console.WriteLine("exception: " + exception.Message);
            }
        }
Beispiel #2
0
        static void Main(string[] aArgs)
        {
            Helper       helper    = new Helper(aArgs);
            OptionParser optParser = helper.OptionParser;

            OptionParser.OptionString option1 = new OptionParser.OptionString("-1", "--protocol", "UDP", "Protocol (UDP or TCP)", "PROTOCOL");
            OptionParser.OptionString option2 = new OptionParser.OptionString("-2", "--clientaddr", "127.0.0.1", "Client IP address", "CLIENTADDRESS");
            OptionParser.OptionInt    option3 = new OptionParser.OptionInt("-3", "--clientport", 51936, "Client port", "CLIENTPORT");
            OptionParser.OptionString option4 = new OptionParser.OptionString("-4", "--serveraddr", "127.0.0.1", "Server IP address", "SERVERADDRESS");
            OptionParser.OptionInt    option5 = new OptionParser.OptionInt("-5", "--serverport", 51936, "Server port", "SERVERPORT");
            OptionParser.OptionInt    option6 = new OptionParser.OptionInt("-6", "--size", 4, "Size of each packet (bytes)", "PACKETSIZE");
            OptionParser.OptionInt    option7 = new OptionParser.OptionInt("-7", "--total", 20, "Total number of packets to send", "PACKETTOTAL");
            OptionParser.OptionInt    option8 = new OptionParser.OptionInt("-8", "--delay", 0, "Delay between packets (0.1ms steps)", "PACKETDELAY");
            optParser.AddOption(option1);
            optParser.AddOption(option2);
            optParser.AddOption(option3);
            optParser.AddOption(option4);
            optParser.AddOption(option5);
            optParser.AddOption(option6);
            optParser.AddOption(option7);
            helper.ProcessCommandLine();

            Client test = new Client(option1.Value, option2.Value, option3.Value, option4.Value, option5.Value, option6.Value, option7.Value, option8.Value);

            // run the test ...
            test.ClientServerTest();
            helper.Dispose();
        }
Beispiel #3
0
    static void Main(string[] aArgs)
    {
        HelperVolkano helper    = new HelperVolkano(aArgs);
        OptionParser  optParser = helper.OptionParser;

        optParser.Usage = "usage: FacDef.exe [options] [target ugly name]";

        OptionParser.OptionBool optNoExec = new OptionParser.OptionBool(null, "--noexec", "Do not reboot target after reprogramming");
        OptionParser.OptionBool optWait   = new OptionParser.OptionBool("-w", "--wait", "Wait to discover rebooted target after reprogramming (ignored with --noexec)");

        optParser.AddOption(optNoExec);
        optParser.AddOption(optWait);

        helper.Start();

        if (optParser.PosArgs.Count != 1)
        {
            Console.WriteLine(optParser.Help());
            System.Environment.Exit(1);
        }

        string uglyname = optParser.PosArgs[0];

        // create the console

        IConsole console = new FlashInfoConsole();

        // create the reprogrammer

        FactoryDefaulter defaulter = new FactoryDefaulter(helper.IpAddress, console, uglyname);

        defaulter.NoExec = optNoExec.Value;
        defaulter.Wait   = optWait.Value;

        if (!defaulter.Execute())
        {
            defaulter.Close();
            System.Environment.Exit(1);
        }

        defaulter.Close();
    }
Beispiel #4
0
    public DoktorTest(string[] aArgs)
    {
        iMutex      = new Mutex();
        iHelper     = new Helper(aArgs);
        iOptionShow = new OptionParser.OptionBool("-s", "--show", "Show tests");

        OptionParser options = iHelper.OptionParser;

        options.Usage = "usage: DoktorTest [options] [test]\n";

        options.AddOption(iOptionShow);

        string id = "DoktorTest";

        iTests    = Test.CreateTests(id);
        iSupplies = Supply.CreateSupplies(id);
    }
Beispiel #5
0
    static void Main(string[] aArgs)
    {
        Helper helper = new Helper(aArgs);

        OptionParser optParser = helper.OptionParser;

        optParser.Usage = "usage: FindDevice [options] [device name]";
        OptionParser.OptionInt optTimeout = new OptionParser.OptionInt("-w", "--wait", 5, "Time to wait for finding the device (s)", "TIMEOUT");
        optParser.AddOption(optTimeout);

        helper.ProcessCommandLine();

        if (optParser.PosArgs.Count != 1)
        {
            Console.WriteLine(optParser.Help());
            return;
        }

        string uglyname = optParser.PosArgs[0];
        int    timeout  = optTimeout.Value;

        DeviceFinder finder = new DeviceFinder(uglyname);

        Device device;

        try
        {
            device = finder.Find(helper.Interface.Interface.Info.IPAddress, timeout * 1000);
        }
        catch (DeviceFinderException)
        {
            Console.WriteLine("Device not found");
            return;
        }

        helper.Dispose();

        Console.WriteLine("Udn: " + device.Udn);

        System.Environment.Exit(0);
    }
Beispiel #6
0
    private void OptionStringTests()
    {
        // string option tests
        OptionParser optParser;

        OptionParser.OptionString optString1 = new OptionParser.OptionString("-a", "--stringa", "defaultstring1", "string help", "STRING");
        OptionParser.OptionString optString2 = new OptionParser.OptionString("-b", "--stringb", "defaultstring2", "string help", "STRING");
        TEST(optString1.ShortName == "-a");
        TEST(optString1.LongName == "--stringa");
        TEST(optString1.Value == "defaultstring1");
        TEST(optString2.ShortName == "-b");
        TEST(optString2.LongName == "--stringb");
        TEST(optString2.Value == "defaultstring2");

        // no args
        optParser = new OptionParser(new string[] {});
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 0);
        TEST(optString1.Value == "defaultstring1");
        TEST(optString2.Value == "defaultstring2");

        // positional args only
        optParser = new OptionParser(new string[] { "arg1", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "defaultstring1");
        TEST(optString2.Value == "defaultstring2");

        // 1 good arg
        optParser = new OptionParser(new string[] { "-a", "stringa", "arg1", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "defaultstring2");

        optParser = new OptionParser(new string[] { "--stringa", "stringa", "arg1", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "defaultstring2");

        optParser = new OptionParser(new string[] { "arg1", "-a", "stringa", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "defaultstring2");

        optParser = new OptionParser(new string[] { "arg1", "arg2", "-a", "stringa" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "defaultstring2");

        // 2 good args
        optParser = new OptionParser(new string[] { "-b", "stringb", "-a", "stringa", "arg1", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "stringb");

        optParser = new OptionParser(new string[] { "-b", "stringb", "arg1", "arg2", "-a", "stringa" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optString1.Value == "stringa");
        TEST(optString2.Value == "stringb");

        // missing option value
        optParser = new OptionParser(new string[] { "-b", "-a", "stringa", "arg1", "arg2" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
        TEST(optString1.Value == "defaultstring1");
        TEST(optString2.Value == "defaultstring2");

        optParser = new OptionParser(new string[] { "-b", "stringb", "arg1", "arg2", "-a" });
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
        TEST(optString1.Value == "defaultstring1");
        TEST(optString2.Value == "defaultstring2");

        // help tests
        OptionParser.OptionHelp help;
        help       = new OptionParser.OptionHelp();
        optString1 = new OptionParser.OptionString("-a", null, "defaultstring1", "string help", "STRING");
        optString1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a STRING             string help\n");

        help       = new OptionParser.OptionHelp();
        optString1 = new OptionParser.OptionString(null, "--stringa", "defaultstring1", "string help", "STRING");
        optString1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  --stringa=STRING      string help\n");

        help       = new OptionParser.OptionHelp();
        optString1 = new OptionParser.OptionString("-a", "--stra", "defaultstring1", "string help", "STR");
        optString1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a STR, --stra=STR    string help\n");

        help       = new OptionParser.OptionHelp();
        optString1 = new OptionParser.OptionString("-a", "--stringa", "defaultstring1", "string help", "STRING");
        optString1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a STRING, --stringa=STRING\n                        string help\n");
    }
Beispiel #7
0
    private void OptionBoolTests()
    {
        // bool option tests
        OptionParser optParser;

        OptionParser.OptionBool optBool1 = new OptionParser.OptionBool("-a", "--boola", "bool help");
        OptionParser.OptionBool optBool2 = new OptionParser.OptionBool("-b", "--boolb", "bool help");
        TEST(optBool1.ShortName == "-a");
        TEST(optBool1.LongName == "--boola");
        TEST(optBool1.Value == false);
        TEST(optBool2.ShortName == "-b");
        TEST(optBool2.LongName == "--boolb");
        TEST(optBool2.Value == false);

        // no args
        optParser = new OptionParser(new string[] {});
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 0);
        TEST(optBool1.Value == false);
        TEST(optBool2.Value == false);

        // positional args only
        optParser = new OptionParser(new string[] { "arg1", "arg2" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == false);
        TEST(optBool2.Value == false);

        // 1 good arg
        optParser = new OptionParser(new string[] { "-a", "arg1", "arg2" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == false);

        optParser = new OptionParser(new string[] { "--boola", "arg1", "arg2" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == false);

        optParser = new OptionParser(new string[] { "arg1", "-a", "arg2" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == false);

        optParser = new OptionParser(new string[] { "arg1", "arg2", "-a" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == false);

        // 2 good args
        optParser = new OptionParser(new string[] { "-b", "-a", "arg1", "arg2" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == true);

        optParser = new OptionParser(new string[] { "-b", "arg1", "arg2", "-a" });
        optParser.AddOption(optBool1);
        optParser.AddOption(optBool2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optBool1.Value == true);
        TEST(optBool2.Value == true);

        // help tests
        OptionParser.OptionHelp help;
        help     = new OptionParser.OptionHelp();
        optBool1 = new OptionParser.OptionBool("-a", null, "bool help");
        optBool1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a                    bool help\n");

        help     = new OptionParser.OptionHelp();
        optBool1 = new OptionParser.OptionBool(null, "--boola", "bool help");
        optBool1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  --boola               bool help\n");

        help     = new OptionParser.OptionHelp();
        optBool1 = new OptionParser.OptionBool("-a", "--boola", "bool help");
        optBool1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a, --boola           bool help\n");

        help     = new OptionParser.OptionHelp();
        optBool1 = new OptionParser.OptionBool("-a", "--boolaaaaaaaaaa", "bool help");
        optBool1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a, --boolaaaaaaaaaa  bool help\n");

        help     = new OptionParser.OptionHelp();
        optBool1 = new OptionParser.OptionBool("-a", "--boolaaaaaaaaaaa", "bool help");
        optBool1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a, --boolaaaaaaaaaaa\n                        bool help\n");
    }
Beispiel #8
0
    private void OptionIntTests()
    {
        // int option tests
        OptionParser optParser;

        OptionParser.OptionInt optInt1 = new OptionParser.OptionInt("-a", "--inta", 123, "int help", "INT");
        OptionParser.OptionInt optInt2 = new OptionParser.OptionInt("-b", "--intb", 456, "int help", "INT");
        TEST(optInt1.ShortName == "-a");
        TEST(optInt1.LongName == "--inta");
        TEST(optInt1.Value == 123);
        TEST(optInt2.ShortName == "-b");
        TEST(optInt2.LongName == "--intb");
        TEST(optInt2.Value == 456);

        // no args
        optParser = new OptionParser(new string[] {});
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 0);
        TEST(optInt1.Value == 123);
        TEST(optInt2.Value == 456);

        // positional args only
        optParser = new OptionParser(new string[] { "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 123);
        TEST(optInt2.Value == 456);

        // 1 good arg
        optParser = new OptionParser(new string[] { "-a", "789", "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 456);

        optParser = new OptionParser(new string[] { "--inta", "789", "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 456);

        optParser = new OptionParser(new string[] { "arg1", "-a", "789", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 456);

        optParser = new OptionParser(new string[] { "arg1", "arg2", "-a", "789" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 456);

        // 2 good args
        optParser = new OptionParser(new string[] { "-b", "987", "-a", "789", "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 987);

        optParser = new OptionParser(new string[] { "-b", "987", "arg1", "arg2", "-a", "789" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        optParser.Parse();
        TEST(optParser.PosArgs.Count == 2);
        TEST(optParser.PosArgs[0] == "arg1");
        TEST(optParser.PosArgs[1] == "arg2");
        TEST(optInt1.Value == 789);
        TEST(optInt2.Value == 987);

        // missing option value
        optParser = new OptionParser(new string[] { "-b", "-a", "789", "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
        TEST(optInt1.Value == 123);
        TEST(optInt2.Value == 456);

        optParser = new OptionParser(new string[] { "-b", "987", "arg1", "arg2", "-a" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
        TEST(optInt1.Value == 123);
        TEST(optInt2.Value == 456);

        // bad option value
        optParser = new OptionParser(new string[] { "-b", "98w7", "-a", "789", "arg1", "arg2" });
        optParser.AddOption(optInt1);
        optParser.AddOption(optInt2);
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
        TEST(optInt1.Value == 123);
        TEST(optInt2.Value == 456);

        // help tests
        OptionParser.OptionHelp help;
        help    = new OptionParser.OptionHelp();
        optInt1 = new OptionParser.OptionInt("-a", null, 123, "int help", "INT");
        optInt1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a INT                int help\n");

        help    = new OptionParser.OptionHelp();
        optInt1 = new OptionParser.OptionInt(null, "--inta", 123, "int help", "INT");
        optInt1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  --inta=INT            int help\n");

        help    = new OptionParser.OptionHelp();
        optInt1 = new OptionParser.OptionInt("-a", "--inta", 123, "int help", "INT");
        optInt1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a INT, --inta=INT    int help\n");

        help    = new OptionParser.OptionHelp();
        optInt1 = new OptionParser.OptionInt("-a", "--inta", 123, "int help", "INTEGER");
        optInt1.AppendHelp(help);
        TEST(help.ToString() == "options:\n  -a INTEGER, --inta=INTEGER\n                        int help\n");
    }
Beispiel #9
0
    public override void Test()
    {
        // Option creation tests

        // no option names
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, null, "defaultstring", "test string help", "STRING");

        // bad short option names
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "", null, "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "s", null, "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "-", null, "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "--", null, "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "-sd", null, "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        "--sd", null, "defaultstring", "test string help", "STRING");

        // bad long option names
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "", "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "s", "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "-", "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "-s", "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "--", "defaultstring", "test string help", "STRING");
        TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString),
                        null, "-sd", "defaultstring", "test string help", "STRING");

        // Some tests for different option types
        OptionStringTests();
        OptionIntTests();
        OptionBoolTests();

        // Parsing tests
        OptionParser optParser = new OptionParser(new string[] { "-a", "aval", "--bc", "bcval" });

        OptionParser.OptionString optString1 = new OptionParser.OptionString("-a", null, "defaultstring", "string help", "STRING");
        OptionParser.OptionString optString2 = new OptionParser.OptionString(null, "--bc", "defaultstring", "string help", "STRING");
        OptionParser.OptionString optString3 = new OptionParser.OptionString("-a", "--bc", "defaultstring", "string help", "STRING");
        OptionParser.OptionInt    optInt4    = new OptionParser.OptionInt("-a", null, 123, "int help", "INT");
        OptionParser.OptionBool   optBool5   = new OptionParser.OptionBool(null, "--bc", "bool help");

        // test adding already existing options
        optParser.AddOption(optString1);
        optParser.AddOption(optString2);
        TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString1);
        TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString2);
        TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString3);
        TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optInt4);
        TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optBool5);

        optParser.Parse();
        TEST(optParser.PosArgs.Count == 0);
        TEST(optString1.Value == "aval");
        TEST(optString2.Value == "bcval");
        TEST(optString3.Value == "defaultstring");
        TEST(optInt4.Value == 123);
        TEST(optBool5.Value == false);

        // test undefined options
        optParser = new OptionParser(new string[] { "-d" });
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);

        optParser = new OptionParser(new string[] { "--de" });
        TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse");
        TEST(optParser.PosArgs.Count == 0);
    }
Beispiel #10
0
    static void Main(string[] aArgs)
    {
        HelperVolkano helper    = new HelperVolkano(aArgs);
        OptionParser  optParser = helper.OptionParser;

        optParser.Usage = "usage: Reprog.exe [options] [target ugly name] [rom file | bundle file]";

        OptionParser.OptionBool   optFallback  = new OptionParser.OptionBool("-f", "--fallback", "Target fallback rather than main");
        OptionParser.OptionBool   optNoExec    = new OptionParser.OptionBool(null, "--noexec", "Do not reboot target after reprogramming");
        OptionParser.OptionBool   optWait      = new OptionParser.OptionBool("-w", "--wait", "Wait to discover rebooted target after reprogramming (ignored with --noexec)");
        OptionParser.OptionBool   optNoTrust   = new OptionParser.OptionBool(null, "--notrust", "Reprogram to factory fresh paying no attention to current flash contents");
        OptionParser.OptionBool   optBootstrap = new OptionParser.OptionBool(null, "--bootstrap", "Additionally reprogram the boostrap");
        OptionParser.OptionBool   optUnsafe    = new OptionParser.OptionBool(null, "--unsafe", "Program directly to flash / no 2 phase programming.");
        OptionParser.OptionString optEmulator  = new OptionParser.OptionString("-e", "--emulator", "", "Flash emulator name (SrecA)", "Emulator name");
        OptionParser.OptionString optOutput    = new OptionParser.OptionString("-o", "--output", "", "Flash emulator output filename", "Output filename");


        optParser.AddOption(optFallback);
        optParser.AddOption(optNoExec);
        optParser.AddOption(optWait);
        optParser.AddOption(optNoTrust);
        optParser.AddOption(optBootstrap);
        optParser.AddOption(optUnsafe);
        optParser.AddOption(optEmulator);
        optParser.AddOption(optOutput);

        helper.Start();

        if (optParser.PosArgs.Count != 2)
        {
            Console.WriteLine(optParser.Help());
            System.Environment.Exit(1);
        }

        string uglyname = optParser.PosArgs[0];
        string xmlfile  = optParser.PosArgs[1];

        // create the console

        IConsole console = new FlashInfoConsole();

        // create the reprogrammer

        Reprogrammer reprog = new Reprogrammer(helper.IpAddress, console, uglyname, xmlfile);

        reprog.Fallback  = optFallback.Value;
        reprog.NoExec    = optNoExec.Value;
        reprog.Wait      = optWait.Value;
        reprog.NoTrust   = optNoTrust.Value;
        reprog.Bootstrap = optBootstrap.Value;
        reprog.Emulator  = optEmulator.Value;
        reprog.Output    = optOutput.Value;
        reprog.Unsafe    = optUnsafe.Value;

        // reprog

        if (!reprog.Execute())
        {
            reprog.Close();
            System.Environment.Exit(1);
        }

        reprog.Close();
        System.Environment.Exit(0);
    }
Beispiel #11
0
        /*  TIME
            GNU Options
                -f FORMAT, --format=FORMAT
                    Specify output format, possibly overriding the format
                    specified in the environment variable TIME.
                -p, --portability
                    Use the portable output format.
                -o FILE, --output=FILE
                    Do not send the results to stderr, but overwrite the
                    specified file.
                -a, --append
                    (Used together with -o.) Do not overwrite but append.
                -v, --verbose
                    Give very verbose output about all the program knows about.

            GNU Standard Options
                -h --help
                    Print a usage message on standard output and exit
                    successfully.
                -V, --version
                    Print version information on standard output, then exit
                    successfully.
                --
                    Terminate option list.
        */
        static void Main(string[] args)
        {
            // Set parser
            OptionParser parser = new OptionParser();
            parser.ProgramInfo.Name = "Time";
            parser.ProgramInfo.Version = "3.14";

            // Add option, which has reqired parameter and meta variable "TIME"
            OptionValue<string> format = new OptionValue<string>("DD.MM.YYYY");
            parser.AddOption(
                new Option(new string[] { "-f", "--format" },
                    "Specify output format, possibly overriding the format specified in the environment variable TIME.",
                    new StoreAction<string>(format)
                ) { ParametersRequired = true }
            );

            // Add option, which has not any parameter
            OptionValue<bool> portability = new OptionValue<bool>(false);
            parser.AddOption(
                new Option(new string[] { "-p", "--portability" },
                    "Use the portable output format.",
                    new StoreConstAction<bool>(portability, true)
                ) { ParametersCount = 0 }
            );

            // Add option, which has reqired parameter
            OptionValue<string> output = new OptionValue<string>();
            parser.AddOption(
                new Option(new string[] { "-o", "--output" },
                    "Do not send the results to stderr, but overwrite the specified file.",
                    new StoreAction<string>(output)
                ) { ParametersRequired = true}
            );

            // Add option, which has not any parameter
            OptionValue<bool> append = new OptionValue<bool>(false);
            parser.AddOption(
                new Option(new string[] { "-a", "--append" },
                    "(Used together with -o.) Do not overwrite but append.",
                    new StoreConstAction<bool>(append, true)
                ) { ParametersCount = 0 }
            );

            // Add option, which has not any parameter
            OptionValue<bool> verbose = new OptionValue<bool>(false);
            parser.AddOption(
                new Option(new string[] { "-v", "--verbose" },
                    "Give very verbose output about all the program knows about.",
                    new StoreConstAction<bool>(verbose, true)
                ) { ParametersCount = 0 }
            );

            try
            {
                // Run options parser (for example with args: -f YYYY.MM.DDD -p -o ./outputfile -a -v)
                IList<string> remainingArgs = parser.ParseArguments(args);
                Console.WriteLine("format: {0}", format.Value);
                Console.WriteLine("portability: {0}", portability.Value);
                Console.WriteLine("output: {0}", output.Value);
                Console.WriteLine("append: {0}", append.Value);
                Console.WriteLine("verbose: {0}", verbose.Value);
            }
            catch (ParseException exception)
            {
                // User control the exception
                System.Console.WriteLine("exception: " + exception.ToString());
            }
        }