Parses command-line input and prints help menu.

@throws Exception
480670
public static void executeHelp(String[] args, PrintStream stream) throws Exception {
        String subCmd = (args.length > 0) ? args[0] : "";
        if(subCmd.equals("add")) {
            SubCommandStoreAdd.printHelp(stream);
        } else if(subCmd.equals("update")) {
            SubCommandStoreUpdate.printHelp(stream);
        } else if(subCmd.equals("delete")) {
            SubCommandStoreDelete.printHelp(stream);
        } else if(subCmd.equals("rollback-ro")) {
            SubCommandStoreRollbackReadOnly.printHelp(stream);
        } else if(subCmd.equals("truncate-partition")) {
            SubCommandStoreTruncatePartition.printHelp(stream);
        } else if(subCmd.equals("truncate-store")) {
            SubCommandStoreTruncateStore.printHelp(stream);
        } else {
            printHelp(stream);
        }
    }
722494
public static void main(String[] args) throws Exception {
        setCustomErrStream();

        CommandLine cmdLine = null;
        try {
            cmdLine = new CommandLine(args != null ? Arrays.copyOf(args, args.length) : null);

        } catch (final Exception e) {
        	// Cant use the CommandLine help here as the 
        	// i18n messages wont have been loaded
            System.out.println("Failed due to invalid parameters: " + Arrays.toString(args));
            System.out.println(e.getMessage());
            System.out.println("Use '-h' for more details.");
            System.exit(1);
        }

        ZapBootstrap bootstrap = createZapBootstrap(cmdLine);
        try {
            int rc = bootstrap.start();
            if (rc != 0) {
                System.exit(rc);
            }

        } catch (final Exception e) {
            logger.fatal(e.getMessage(), e);
            System.exit(1);
        }

    }
458896
boolean parseCmdLineArgs(String[] args) throws IllegalArgumentException {
        for (int i = 0; i < args.length; i++) {
            if (args[i].toLowerCase().contains("help") || args[i].toLowerCase().contains("usage")) {
                // print the usage information and exit.
                printUsage();
                return true;
            }
            boolean accepted = false;
            for (Option option : options) {
                if (args[i].equalsIgnoreCase(option.name)) {
                    if (i + option.nargs < args.length) {
                        i += option.accept(args, i + 1);
                    } else {
                        throw new IllegalArgumentException(getLocalizedParmString("CWTRA0022E",
                                                                                  new Object[] { option.name, option.nargs }));
                    }
                    accepted = true;
                    break;
                }
            }
            if (!accepted) {
                throw new IllegalArgumentException(getLocalizedParmString("CWTRA0023E", new Object[] { args[i] }));
            }
        }
        return false;
    }
678203
public static void main(final String args[])
		throws Exception {
		if (hasParameter(args,"--help") ||
			hasParameter(args,"-h")) {
			showUsage(null);
		}
		String  url				 = getParameter(args, "--url");
		String  outfile			 = getParameter(args, "--out");
		String  fontPath	 	 = getParameter(args, "--fontpath");
		String  password		 = getParameter(args, "--password");
		String  keystorePath     = getParameter(args, "--ks");
		String  keystorePassword = getParameter(args, "--kspassword");
		String  keyPassword		 = getParameter(args, "--keypassword");
		String  cryptReason		 = getParameter(args, "--cryptreason");
		String  cryptLocation    = getParameter(args, "--cryptlocation");
		
		if (outfile == null) {
			showUsage("--out file must exists !");
		} // end if

		try {
			new URL(url);
		} // end try
		catch (final Exception e) {
			showUsage("--url must be a valid URL !");
		} // end catch
		try {
			File fout = new File(outfile);

			List			 headerFooterList = new ArrayList();

			FileOutputStream out = new FileOutputStream(fout);
			System.out.println("before conversion");

			Map properties = new HashMap();

			headerFooterList.add(new IHtmlToPdfTransformer.CHeaderFooter(
					"<table width=\"100%\"><tbody><tr><td align=\"left\">Generated with YaHPConverter.</td><td align=\"right\">Page <pagenumber>/<pagecount></td></tr></tbody></table>",
					IHtmlToPdfTransformer.CHeaderFooter.HEADER));
			headerFooterList.add(new IHtmlToPdfTransformer.CHeaderFooter(
					"© 2011 Quentin Anciaux",
					IHtmlToPdfTransformer.CHeaderFooter.FOOTER));
			
			properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS,
					IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);
			if (fontPath != null)
				properties.put(IHtmlToPdfTransformer.FOP_TTF_FONT_PATH, fontPath);

			if (password != null) {
				System.out.println(password);
				properties.put(IHtmlToPdfTransformer.USE_PDF_ENCRYPTION,
					"true");
				properties.put(IHtmlToPdfTransformer.PDF_ALLOW_SCREEN_READERS,
					"true");
				properties.put(IHtmlToPdfTransformer.PDF_ENCRYPTION_PASSWORD,
					password);

				if (keystorePath != null) {
					properties.put(IHtmlToPdfTransformer.USE_PDF_SIGNING,
						"true");
					properties.put(IHtmlToPdfTransformer.PDF_SIGNING_PRIVATE_KEY_FILE,
						keystorePath);
					properties.put(IHtmlToPdfTransformer.PDF_SIGNING_KEYSTORE_PASSWORD,
						keystorePassword);
					properties.put(IHtmlToPdfTransformer.PDF_SIGNING_PRIVATE_KEY_PASSWORD,
						keyPassword);

					if (cryptReason != null) {
						properties.put(IHtmlToPdfTransformer.PDF_SIGNING_REASON,
							cryptReason);
					} // end if

					if (cryptLocation != null) {
						properties.put(IHtmlToPdfTransformer.PDF_SIGNING_LOCATION,
							cryptLocation);
					} // end if
				} // end if
			} // end if

			converter.convertToPdf(new URL(url),
				IHtmlToPdfTransformer.A4P, headerFooterList, out,
				properties);
			System.out.println("after conversion");
			out.flush();
			out.close();
		} // end try
		catch (final Throwable t) {
			t.printStackTrace();
			System.err.println("An error occurs while converting '" +
				url + "' to '" + outfile + "'. Cause : " +
				t.getMessage());
			System.exit(-1);
		} // end catch

		System.exit(0);
	}
1304158
public static CommandLine parse(Options options, String... args) throws Exception {
        return CommandLineParser.parse(options, args);
    }
361275
public void actionParent() throws Exception {

        String ouFqn = CmsOrganizationalUnit.getParentFqn(getParamOufqn());

        Map<String, String[]> params = new HashMap<String, String[]>();
        params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, new String[] {ouFqn});
        params.put(CmsDialog.PARAM_ACTION, new String[] {CmsDialog.DIALOG_INITIAL});
        String toolPath = getCurrentToolPath().substring(0, getCurrentToolPath().lastIndexOf("/"));
        getToolManager().jspForwardTool(this, toolPath, params);
        actionCloseDialog();
    }
1220516
@Override
  public int run(String[] argv) throws Exception {
    int exitCode = 0;

    Options options = buildOptions();
    if(argv.length == 0) {
      printHelp();
      return -1;
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;

    try {
      cmd = parser.parse(options, argv);
    } catch (ParseException e) {
      System.out.println(
        "Error parsing command-line options: " + e.getMessage());
      printHelp();
      return -1;
    }

    if(cmd.hasOption("h")) { // print help and exit
      printHelp();
      return -1;
    }

    boolean printToScreen    = false;
    String inputFilenameArg  = cmd.getOptionValue("i");
    String outputFilenameArg = cmd.getOptionValue("o");
    String processor         = cmd.getOptionValue("p");
    if(processor == null) { processor = defaultProcessor; }

    if(cmd.hasOption("v")) { // print output to screen too
      printToScreen = true;
      System.out.println("input  [" + inputFilenameArg  + "]");
      System.out.println("output [" + outputFilenameArg + "]");
    }

    try {
      go(EditsVisitorFactory.getEditsVisitor(
        outputFilenameArg,
        processor,
        TokenizerFactory.getTokenizer(inputFilenameArg),
        printToScreen));
    } catch (EOFException e) {
      System.err.println("Input file ended unexpectedly. Exiting");
      exitCode = 255;
    } catch(IOException e) {
      System.err.println("Encountered exception. Exiting: " + e.getMessage());
      exitCode = 1;
    }

    return exitCode;
  }
645085
public static void executeHelp(String[] args, PrintStream stream) throws IOException {
        String subCmd = (args.length > 0) ? args[0] : "";
        if(subCmd.equals("list")) {
            SubCommandAsyncJobList.printHelp(stream);
        } else if(subCmd.equals("stop")) {
            SubCommandAsyncJobStop.printHelp(stream);
        } else {
            printHelp(stream);
        }
    }
413541
private void helpAction(String arg) {
        if (arg == null) {
            printMainUsage();
            return;
        }

        String helpTarget = arg.toLowerCase();

        if (helpTarget.equals(ACTION_VIEW)) {
            printViewUsage();
        } else if (helpTarget.equals(ACTION_COPY)) {
            printCopyUsage();
        } else if (helpTarget.equals(ACTION_LISTINSTANCES)) {
            printListInstancesUsage();
        } else {
            printMainUsage();
        }
    }
430504
public function parse() {
		$fp = fopen($this->file, "r");
		if (!$fp) {
			throw new Exception("Could not open XML input file");
		}

		$data = fread($fp, 4096);
		while ($data) {
			if (!xml_parse($this->xmlParser, $data, feof($fp))) {
				$errorString = xml_error_string(xml_get_error_code($this->xmlParser));
				$errorLineNo = xml_get_current_line_number($this->xmlParser);
				$msg = sprintf("Warning: XML error: %s at line %d", $errorString, $errorLineNo);
				echo $msg;
				$this->config = array();
			}

			$data = fread($fp, 4096);
		}
	}
132263
public static void main(final String[] args) {
        Switch about = new Switch("a", "about", "display about message");
        Switch help = new Switch("h", "help", "display help message");
        FileArgument inputHmlFile = new FileArgument("i", "input-hml-file", "input HML file, default stdin", false);
        FileArgument outputFile = new FileArgument("o", "output-file", "output allele assignment file, default stdout", false);

        ArgumentList arguments = new ArgumentList(about, help, inputHmlFile, outputFile);
        CommandLine commandLine = new CommandLine(args);

        ExtractExpectedHaploids extractExpectedHaploids = null;
        try
        {
            CommandLineParser.parse(commandLine, arguments);
            if (about.wasFound()) {
                About.about(System.out);
                System.exit(0);
            }
            if (help.wasFound()) {
                Usage.usage(USAGE, null, commandLine, arguments, System.out);
                System.exit(0);
            }
            extractExpectedHaploids = new ExtractExpectedHaploids(inputHmlFile.getValue(), outputFile.getValue());
        }
        catch (CommandLineParseException | IllegalArgumentException e) {
            Usage.usage(USAGE, e, commandLine, arguments, System.err);
            System.exit(-1);
        }
        try {
            System.exit(extractExpectedHaploids.call());
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
797392
public static void main(String[] args) throws Exception {
        OptionParser parser = null;
        OptionSet options = null;
        try {
            parser = getParser();
            options = parser.parse(args);
        } catch(OptionException oe) {
            parser.printHelpOn(System.out);
            printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
            return;
        }

        /* validate options */
        if(options.has("help")) {
            parser.printHelpOn(System.out);
            printUsage();
            return;
        }
        if(!options.hasArgument("url") || !options.hasArgument("in-dir")
           || !options.hasArgument("out-dir")) {
            parser.printHelpOn(System.out);
            printUsageAndDie("Missing a required argument.");
            return;
        }

        String url = (String) options.valueOf("url");

        String inDir = (String) options.valueOf("in-dir");
        Utils.mkdirs(new File(inDir));

        String outDir = (String) options.valueOf("out-dir");
        Utils.mkdirs(new File(outDir));

        List<String> storeNames = null;
        if(options.hasArgument("store-names")) {
            @SuppressWarnings("unchecked")
            List<String> list = (List<String>) options.valuesOf("store-names");
            storeNames = list;
        }

        Integer keyParallelism = DEFAULT_KEY_PARALLELISM;
        if(options.hasArgument("parallelism")) {
            keyParallelism = (Integer) options.valueOf("parallelism");
        }

        Integer progressPeriodOps = DEFAULT_PROGRESS_PERIOD_OPS;
        if(options.hasArgument("progress-period-ops")) {
            progressPeriodOps = (Integer) options.valueOf("progress-period-ops");
        }

        Integer outputBatchSize = DEFAULT_OUTPUT_BATCH_SIZE;
        if(options.hasArgument("output-batch-size")) {
            outputBatchSize = (Integer) options.valueOf("output-batch-size");
        }

        boolean details = options.has("details");

        try {
            KeyVersionFetcherCLI sampler = new KeyVersionFetcherCLI(url,
                                                                    inDir,
                                                                    outDir,
                                                                    storeNames,
                                                                    keyParallelism,
                                                                    progressPeriodOps,
                                                                    outputBatchSize,
                                                                    details);

            try {
                if(!sampler.sampleStores()) {
                    logger.error("Key-versions were not successfully sampled from some stores.");
                }
            } finally {
                sampler.stop();
            }

        } catch(Exception e) {
            logger.error("Exception during key-version sampling: ", e);
        }
    }
1208796
static public void main (String[] args) throws Exception {
		if (args.length == 0) {
			String commandLine = "-f 0 -wi 1 -i 1 -t 1 -w 1s -r 1s " // For developement only (fork 0, short runs).
			// + "-bs 2500000 ArrayBenchmark" //
			// + "-rf csv FieldSerializerBenchmark.field FieldSerializerBenchmark.tagged" //
			// + "FieldSerializerBenchmark.tagged" //
			;
			System.out.println(commandLine);
			args = commandLine.split(" ");
		}
		Main.main(args);
	}
299943
public function parse()
    {
        // check if a help flag is set
        try {
            $key = $this->checkInputs('-h', '--help');
            if ($key !== false) {
                throw new \Exception('Help flag is set');
            }
        } catch (\Exception $e) {
            $this->outputHelp();
            return false;
        }

        // loop through options and see if they are in the inputs
        foreach ($this->options as $option => $info) {
            // if option is in inputs
            $key = $this->checkInputs($info['short'], $info['long']);
            if ($key === false) {
                $this->pinputs[$info['short']] = false;
                $this->pinputs[$info['long']] = false;
            } else {
                // check if next input should be in input
                if (array_key_exists('input', $info) && $info['input'] == true) {
                    $this->pinputs[$info['short']] = $this->inputs[$key + 1];
                    $this->pinputs[$info['long']] = $this->inputs[$key + 1];
                    unset($this->inputs[$key]); // remove flag from inputs array
                    unset($this->inputs[$key + 1]);
                } else {
                    $this->pinputs[$info['short']] = true;
                    $this->pinputs[$info['long']] = true;
                    unset($this->inputs[$key]);
                }
            }
        }

        // Loop through each of the remaining inputs and assign them to their
        // params
        $count = 0; // count because cannot rely on key value of inputs
        foreach ($this->inputs as $key => $input) {
            // If parameter for input exists
            if (array_key_exists($count, $this->params)) {
                $this->pinputs[$this->params[$count]['name']] = $input;
                unset($this->inputs[$key]); // remove input from inputs
            }
            $count++;
        }

        // loop through remaining flags and insert them at their indexes
        if (!empty($this->inputs)) {
            $this->inputs = array_values($this->inputs);
        }
        $this->pinputs = array_merge($this->inputs, $this->pinputs);

        // check required inputs
        try {
            $this->checkRequired();
        } catch (\Exception $e) {
            echo $e->getMessage() . PHP_EOL . PHP_EOL;
            $this->outputHelp(true);
            return false;
        }

        return true;
    }
281519
public static void executeCommand(String[] args) throws Exception {
        String subCmd = (args.length > 0) ? args[0] : "";
        args = AdminToolUtils.copyArrayCutFirst(args);
        if(subCmd.equals("query-keys")) {
            SubCommandDebugQueryKeys.executeCommand(args);
        } else if(subCmd.equals("route")) {
            SubCommandDebugRoute.executeCommand(args);
        } else {
            printHelp(System.out);
        }
    }
1170219
protected static void main(String[] args, CliTool command) {
    JCommander jc = new JCommander(command);
    jc.addConverterFactory(new CustomParameterConverters());
    jc.setProgramName(command.getClass().getAnnotation(Parameters.class).commandNames()[0]);

    ExitStatus exitStatus = ExitStatus.SUCCESS;
    try {
      jc.parse(args);
      if (command.help) {
        helpDisplayCommandOptions(System.err, jc);
      } else {
        exitStatus = command.call();
      }
    } catch (ExitStatusException e) {
      System.err.println(e.getMessage());
      if (e.getCause() != null) {
        e.getCause().printStackTrace(System.err);
      }
      exitStatus = e.exitStatus;
    } catch (MissingCommandException e) {
      System.err.println("Invalid argument: " + e);
      System.err.println();
      helpDisplayCommandOptions(System.err, jc);
      exitStatus = ExitStatus.ERROR_INVALID_ARGUMENTS;
    } catch (ParameterException e) {
      System.err.println("Invalid argument: " + e.getMessage());
      System.err.println();

      if (jc.getParsedCommand() == null) {
        helpDisplayCommandOptions(System.err, jc);
      } else {
        helpDisplayCommandOptions(System.err, jc.getParsedCommand(), jc);
      }
      exitStatus = ExitStatus.ERROR_INVALID_ARGUMENTS;
    } catch (Throwable t) {
      System.err.println("An unhandled exception occurred. Stack trace below.");
      t.printStackTrace(System.err);
      exitStatus = ExitStatus.ERROR_OTHER;
    }

    if (command.callSystemExit) {
      System.exit(exitStatus.code);
    }
  }
230128
private void doit(String[] args)
    {
        try
        {
            // load parameters from the commandline
            loadParameters(args);

            // Try to load the private key
            importKeyPair();
        }
        catch (Exception e)
        {
            System.out.println("Exception: " + e.getMessage());
            e.printStackTrace();
            
            System.exit(23);
        }
    }