Пример #1
0
        /// <summary>parse args</summary>
        /// <exception cref="System.ArgumentException"/>
        private static CommandLine ParseArgs(Options opts, params string[] args)
        {
            OptionBuilder.WithArgName("NameNode|DataNode");
            OptionBuilder.HasArg();
            OptionBuilder.WithDescription("specify jmx service (NameNode by default)");
            Option jmx_service = OptionBuilder.Create("service");

            OptionBuilder.WithArgName("mbean server");
            OptionBuilder.HasArg();
            OptionBuilder.WithDescription("specify mbean server (localhost by default)");
            Option jmx_server = OptionBuilder.Create("server");

            OptionBuilder.WithDescription("print help");
            Option jmx_help = OptionBuilder.Create("help");

            OptionBuilder.WithArgName("mbean server port");
            OptionBuilder.HasArg();
            OptionBuilder.WithDescription("specify mbean server port, " + "if missing - it will try to connect to MBean Server in the same VM"
                                          );
            Option jmx_port = OptionBuilder.Create("port");

            OptionBuilder.WithArgName("VM's connector url");
            OptionBuilder.HasArg();
            OptionBuilder.WithDescription("connect to the VM on the same machine;" + "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | "
                                          + "grep sun.management.JMXConnectorServer.address\n " + "to find the url");
            Option jmx_localVM = OptionBuilder.Create("localVM");

            opts.AddOption(jmx_server);
            opts.AddOption(jmx_help);
            opts.AddOption(jmx_service);
            opts.AddOption(jmx_port);
            opts.AddOption(jmx_localVM);
            CommandLine       commandLine = null;
            CommandLineParser parser      = new GnuParser();

            try
            {
                commandLine = parser.Parse(opts, args, true);
            }
            catch (ParseException e)
            {
                PrintUsage(opts);
                throw new ArgumentException("invalid args: " + e.Message);
            }
            return(commandLine);
        }