Example #1
0
  public void test11456() {
    // Posix
    Options options = new Options();
    options.addOption(OptionBuilder.hasOptionalArg().create('a'));
    options.addOption(OptionBuilder.hasArg().create('b'));
    String[] args = new String[] {"-a", "-bvalue"};

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine cmd = parser.parse(options, args);
      assertEquals(cmd.getOptionValue('b'), "value");
    } catch (ParseException exp) {
      fail("Unexpected Exception: " + exp.getMessage());
    }

    // GNU
    options = new Options();
    options.addOption(OptionBuilder.hasOptionalArg().create('a'));
    options.addOption(OptionBuilder.hasArg().create('b'));
    args = new String[] {"-a", "-b", "value"};

    parser = new GnuParser();

    try {
      CommandLine cmd = parser.parse(options, args);
      assertEquals(cmd.getOptionValue('b'), "value");
    } catch (ParseException exp) {
      fail("Unexpected Exception: " + exp.getMessage());
    }
  }
Example #2
0
  private static boolean setOptions(String[] lcommand) {

    Options loptions = new Options();
    loptions.addOption(new Option("d", "debug", false, "print debug information (highly verbose)"));
    loptions.addOption(new Option("o", "stdout", false, "print output files to standard output"));
    loptions.addOption(new Option("w", "warning", false, "print warning messages"));

    CommandLineParser clparser = new PosixParser();
    try {
      cmd = clparser.parse(loptions, lcommand);
    } catch (org.apache.commons.cli.ParseException e) {
      String mytoolcmd = "java -jar stave.jar";
      String myoptlist = " <options> <source files>";
      String myheader = "Convert JavaParser's AST to OpenJDK's AST";
      String myfooter = "More info: https://github.com/pcgomes/javaparser2jctree";

      HelpFormatter formatter = new HelpFormatter();
      // formatter.printUsage( new PrintWriter(System.out,true), 100, "java -jar synctask.jar",
      // loptions );
      // formatter.printHelp( mytoolcmd + myoptlist, myheader, loptions, myfooter, false);
      formatter.printHelp(mytoolcmd + myoptlist, loptions, false);
      return (false);
    }

    return (true);
  }
    public static Options parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length == 0) {
          System.err.println("No sstables to split");
          printUsage(options);
          System.exit(1);
        }
        Options opts = new Options(Arrays.asList(args));
        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.verbose = cmd.hasOption(VERBOSE_OPTION);
        opts.snapshot = !cmd.hasOption(NO_SNAPSHOT_OPTION);
        opts.sizeInMB = DEFAULT_SSTABLE_SIZE;

        if (cmd.hasOption(SIZE_OPTION))
          opts.sizeInMB = Integer.valueOf(cmd.getOptionValue(SIZE_OPTION));

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
Example #4
0
  public static void main(String args[]) throws IOException, ParseException {
    Options options = new Options();
    options.addOption("u", "uniquehits", false, "only output hits with a single mapping");
    options.addOption(
        "s",
        "nosuboptimal",
        false,
        "do not include hits whose score is not equal to the best score for the read");
    CommandLineParser parser = new GnuParser();
    CommandLine cl = parser.parse(options, args, false);
    boolean uniqueOnly = cl.hasOption("uniquehits");
    boolean filterSubOpt = cl.hasOption("nosuboptimal");

    ArrayList<String[]> lines = new ArrayList<String[]>();

    String line;
    String lastRead = "";
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    while ((line = reader.readLine()) != null) {
      String pieces[] = line.split("\t");
      if (!pieces[0].equals(lastRead)) {
        printLines(lines, uniqueOnly, filterSubOpt);
        lines.clear();
      }
      lines.add(pieces);
      lastRead = pieces[0];
    }
    printLines(lines, uniqueOnly, filterSubOpt);
  }
Example #5
0
  public void run(String[] args)
      throws ParseException, TransformationException, IOException, AnalysisException {
    Options options = new Options();
    options.addOption("input", true, "input path");
    options.addOption("output", true, "output path");
    options.addOption("ext", true, "extension");
    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);
    String inDir = line.getOptionValue("input");
    String outDir = line.getOptionValue("output");
    String extension = line.getOptionValue("ext");

    File dir = new File(inDir);

    for (File f : FileUtils.listFiles(dir, new String[] {extension}, true)) {
      TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader();
      List<BxPage> pages = tvReader.read(new FileReader(f));
      BxDocument doc = new BxDocument().setPages(pages);
      doc.setFilename(f.getName());

      BxDocument rewritten = transform(doc);

      File f2 = new File(outDir + doc.getFilename());
      BxDocumentToTrueVizWriter wrt = new BxDocumentToTrueVizWriter();
      boolean created = f2.createNewFile();
      if (!created) {
        throw new IOException("Cannot create file: ");
      }
      FileWriter fw = new FileWriter(f2);
      wrt.write(fw, Lists.newArrayList(rewritten));
      fw.flush();
      fw.close();
    }
  }
Example #6
0
  public void init(String[] args) throws UserError {
    Context.reset();
    CommandLineParser globalParser = new GnuParser();

    List<String> globalArgs = new ArrayList<String>();

    boolean inGlobal = true;
    for (String arg : args) {
      if (inGlobal) {
        if (arg.startsWith("--")) {
          globalArgs.add(arg);
        } else {
          this.command = arg;
          inGlobal = false;
        }
      } else {
        commandArgs.add(arg);
      }
    }

    try {
      this.globalArguments =
          globalParser.parse(globalOptions, globalArgs.toArray(new String[globalArgs.size()]));
    } catch (ParseException e) {
      throw new UserError("Error parsing global command line argument: " + e.getMessage());
    }
  }
  public static boolean parseArgs(String[] args) {
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
      cmd = parser.parse(options, args);

      if (cmd.hasOption("tbn") && cmd.hasOption("tbp")) {
        tbUsername = cmd.getOptionValue("tbn");
        tbPassword = cmd.getOptionValue("tbp");
      } else {
        System.out.println("Please enter your Topbot username and password");
        return false;
      }

      if (cmd.hasOption("n")) {
        numAccounts = Integer.parseInt(cmd.getOptionValue("n"));

        if (numAccounts >= 9)
          System.out.println("WARNING: The number of accounts exceeds the number of f2p worlds!");
      } else numAccounts = DEFAULT_ACCOUNT_NUM;

      if (cmd.hasOption("bp")) botPassword = cmd.getOptionValue("bp");
      else botPassword = DEFAULT_PW;

      if (cmd.hasOption("s")) script = cmd.getOptionValue("s");
      else script = DEFAULT_SCRIPT;

      return true;
    } catch (Exception e) {
      System.out.println("Couldn't parse arguments");
      return false;
    }
  }
    public static Options parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length >= 4 || args.length < 2) {
          String msg = args.length < 2 ? "Missing arguments" : "Too many arguments";
          errorMsg(msg, options);
          System.exit(1);
        }

        String keyspace = args[0];
        String cf = args[1];
        String snapshot = null;
        if (args.length == 3) snapshot = args[2];

        Options opts = new Options(keyspace, cf, snapshot);

        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.keepSource = cmd.hasOption(KEEP_SOURCE);

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
Example #9
0
	public static String[] ginit(String[] args) {
		if (System.getenv("KONOHA_DEBUG") != null) {
			verboseDebug = true;
			verboseGc = true;
			verboseSugar = true;
			verboseCode = true;
		}
		
		CommandLineParser parser = new BasicParser();
		CommandLine commandLine = null;
		try {
			commandLine = parser.parse(longOptions, args);
		} catch (ParseException e) {
			// TODO
		}
		
		if(commandLine.hasOption("verbose")) {
			verboseDebug = true;
			System.out.println("option vervose");
		}
		if(commandLine.hasOption("verbose:gc")) {
			verboseGc = true;
			System.out.println("option vervose:gc");
		}
		if(commandLine.hasOption("verbose:sugar")) {
			verboseSugar = true;
			System.out.println("option vervose:sugar");
		}
		if(commandLine.hasOption("verbose:code")) {
			verboseCode = true;
			System.out.println("option vervose:code");
		}
		if(commandLine.hasOption("interactive")) {
			interactiveFlag = true;
			System.out.println("option interactive");
		}
		if(commandLine.hasOption("typecheck")) {
			compileonlyFlag = true;
			System.out.println("option typecheck");
		}
		if(commandLine.hasOption("start-with")) {
			startupScript = commandLine.getOptionValue("start-with");
			System.out.println("option start-with");
			System.out.println(" with arg " + startupScript);
		}
		if(commandLine.hasOption("test")) {
			testScript = commandLine.getOptionValue("test");
			System.out.println(" with arg " + testScript);
		}
		if(commandLine.hasOption("test-with")) {
			testScript = commandLine.getOptionValue("test");
			System.out.println(" with arg " + testScript);
		}
		if(commandLine.hasOption("builtin-test")) {
			builtinTest = commandLine.getOptionValue("builtin-test");
			System.out.println(" with arg " + builtinTest);
		}
		return commandLine.getArgs();
	}
Example #10
0
  // TODO add exception for invalid options
  private void loadCLO(String[] args) {
    Options options = new Options();

    String[][] clolist = {
      // {"variable/optionname", "description"},
      {"genConfig", "general configuration file location"},
      {"inWeightsLoc", "input weights configuration file location"},
      {"inDBLoc", "input database file location"},
      {"outWeightsLoc", "output weights configuration file location"},
      {"outDBLoc", "output database file location"},
      {"p3pLocation", "adding to DB: single policy file location"},
      {"p3pDirLocation", "adding to DB: multiple policy directory location"},
      {"newDB", "create new database in place of old one (doesn't check for existence of old one"},
      {"newPolicyLoc", "the policy object to process"},
      {"userResponse", "response to specified policy"},
      {"userIO", "user interface"},
      {"userInit", "initialization via user interface"},
      {"policyDB", "PolicyDatabase backend"},
      {"cbrV", "CBR to use"},
      {"blanketAccept", "automatically accept the user suggestion"},
      {"loglevel", "level of things save to the log- see java logging details"},
      {"policyDB", "PolicyDatabase backend"},
      {"NetworkRType", "Network Resource type"},
      {"NetworkROptions", "Network Resource options"},
      {"confidenceLevel", "Confidence threshold for consulting a networked resource"},
      {"useNet", "use networking options"},
      {"loglocation", "where to save the log file"},
      {"loglevel", "the java logging level to use. See online documentation for enums."}
    };

    for (String[] i : clolist) {
      options.addOption(i[0], true, i[1]);
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
    } catch (ParseException e) {
      System.err.println("Error parsing commandline arguments.");
      e.printStackTrace();
      System.exit(3);
    }
    /*
    for(String i : args)
    {
    	System.err.println(i);
    }
    */
    for (String[] i : clolist) {
      if (cmd.hasOption(i[0])) {
        System.err.println("found option i: " + i);
        genProps.setProperty(i[0], cmd.getOptionValue(i[0]));
      }
    }
    System.err.println(genProps);
  }
 @Test
 public void testNoInputfile() throws ParseException {
   expectedEx.expect(ParseException.class);
   expectedEx.expectMessage("no input file");
   String cmd = "-o aaa.c";
   String[] args = cmd.split(" ");
   CommandLineParser c = new CommandLineParser(args);
   c.scan();
 }
 @Test
 public void testIllegleGenerator() throws ParseException {
   expectedEx.expect(ParseException.class);
   expectedEx.expectMessage("expect {RuntimeC|Bytecode|Dalvik|X86}");
   String cmd = "-codegen abc LinkedList.java";
   String[] args = cmd.split(" ");
   CommandLineParser c = new CommandLineParser(args);
   c.scan();
 }
Example #13
0
 public void test15648() throws Exception {
   CommandLineParser parser = new PosixParser();
   final String[] args = new String[] {"-m", "\"Two Words\""};
   Option m = OptionBuilder.hasArgs().create("m");
   Options options = new Options();
   options.addOption(m);
   CommandLine line = parser.parse(options, args);
   assertEquals("Two Words", line.getOptionValue("m"));
 }
 @Test
 public void testIllegleVisualFormat() throws ParseException {
   expectedEx.expect(ParseException.class);
   expectedEx.expectMessage("expect {bmp|pdf|svg|jpg}");
   String cmd = "LinkedList.java -v jpeg";
   String[] args = cmd.split(" ");
   CommandLineParser c = new CommandLineParser(args);
   c.scan();
 }
 @Test
 public void testMutilInputfile() throws ParseException {
   expectedEx.expect(ParseException.class);
   expectedEx.expectMessage("can only parse one file");
   String cmd = "-o aaa.c input1.java input2.java";
   String[] args = cmd.split(" ");
   CommandLineParser c = new CommandLineParser(args);
   c.scan();
 }
Example #16
0
 /**
  * processes the command line input
  *
  * @param args command line arg vector
  */
 public CommandLine parseArgs(final String[] args) throws ProjectToolException {
   final CommandLineParser parser = new PosixParser();
   try {
     cli = parser.parse(options, args);
   } catch (ParseException e) {
     help();
     throw new ProjectToolException(e);
   }
   initArgs();
   return cli;
 }
    public static LoaderOptions parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length == 0) {
          System.err.println("Missing sstable directory argument");
          printUsage(options);
          System.exit(1);
        }

        if (args.length > 1) {
          System.err.println("Too many arguments");
          printUsage(options);
          System.exit(1);
        }

        String dirname = args[0];
        File dir = new File(dirname);

        if (!dir.exists()) errorMsg("Unknown directory: " + dirname, options);

        if (!dir.isDirectory()) errorMsg(dirname + " is not a directory", options);

        LoaderOptions opts = new LoaderOptions(dir);

        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.verbose = cmd.hasOption(VERBOSE_OPTION);
        opts.noProgress = cmd.hasOption(NOPROGRESS_OPTION);

        if (cmd.hasOption(IGNORE_NODES_OPTION)) {
          String[] nodes = cmd.getOptionValue(IGNORE_NODES_OPTION).split(",");
          try {
            for (String node : nodes) {
              opts.ignores.add(InetAddress.getByName(node));
            }
          } catch (UnknownHostException e) {
            errorMsg(e.getMessage(), options);
          }
        }

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
Example #18
0
 public static void parseAndPopulate(Object instance, String input)
     throws CommandLineParserException, OptionValidatorException {
   CommandLineParser cl = generateCommandLineParser(instance.getClass());
   InvocationProviders invocationProviders =
       new AeshInvocationProviders(
           new AeshConverterInvocationProvider(),
           new AeshCompleterInvocationProvider(),
           new AeshValidatorInvocationProvider());
   cl.getCommandPopulator()
       .populateObject(instance, cl.parse(input), invocationProviders, null, true);
 }
 @Test
 public void test() throws ParseException {
   String cmd = "-o aaa.c LinkedList.java -codegen Bytecode -v svg";
   String[] args = cmd.split(" ");
   CommandLineParser c = new CommandLineParser(args);
   c.scan();
   assertEquals(Control.ConCodeGen.Kind_t.Bytecode, Control.ConCodeGen.codegen);
   assertEquals("LinkedList.java", Control.ConCodeGen.fileName);
   assertEquals("aaa.c", Control.ConCodeGen.outputName);
   assertEquals("Svg", Control.visualize.name());
 }
Example #20
0
  public CommandLine parse(String[] cmd) {
    CommandLineParser parser = new ActualPosixParser();
    try {
      setCommandLine(parser.parse(options, cmd));
      return getCommandLine();
    } catch (ParseException e) {
      System.out.println("Error while parsing commandline:" + e.getMessage());
    }

    return null;
  }
Example #21
0
  public void runCommand(String[] args, boolean tsqlMode) throws Exception {
    CommandLineParser parser = new PosixParser();

    if (args.length == 0) {
      printUsage(tsqlMode);
      return;
    }

    CommandLine cmd = parser.parse(options, args);

    String hostName = null;
    Integer port = null;
    if (cmd.hasOption("h")) {
      hostName = cmd.getOptionValue("h");
    }
    if (cmd.hasOption("p")) {
      port = Integer.parseInt(cmd.getOptionValue("p"));
    }

    String param;
    if (cmd.getArgs().length > 1) {
      printUsage(tsqlMode);
      return;
    } else {
      param = cmd.getArgs()[0];
    }

    // if there is no "-h" option,
    if (hostName == null) {
      if (tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) {
        // it checks if the client service address is given in configuration and distributed mode.
        // if so, it sets entryAddr.
        hostName = tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[0];
      }
    }
    if (port == null) {
      if (tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) {
        // it checks if the client service address is given in configuration and distributed mode.
        // if so, it sets entryAddr.
        port =
            Integer.parseInt(
                tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[1]);
      }
    }

    if ((hostName == null) ^ (port == null)) {
      return;
    } else if (hostName != null && port != null) {
      tajoConf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, hostName + ":" + port);
    }

    processConfKey(writer, param);
    writer.flush();
  }
Example #22
0
  public void test14786() throws Exception {
    Option o = OptionBuilder.isRequired().withDescription("test").create("test");
    Options opts = new Options();
    opts.addOption(o);
    opts.addOption(o);

    CommandLineParser parser = new GnuParser();

    String[] args = new String[] {"-test"};

    CommandLine line = parser.parse(opts, args);
    assertTrue(line.hasOption("test"));
  }
Example #23
0
  public static void main(String[] args) {
    Main main = new Main();

    main.header("Liquibase SDK");

    try {
      main.init(args);

      if (main.command == null) {
        throw new UserError("No command passed");
      }

      if (main.command.equals("help")) {
        main.printHelp();
        return;
      }

      VagrantControl vagrantControl;
      if (main.command.equals("vagrant")) {
        vagrantControl = new VagrantControl(main);
      } else {
        throw new UserError("Unknown command: " + main.command);
      }

      CommandLineParser commandParser = new GnuParser();
      try {
        CommandLine commandArguments =
            commandParser.parse(
                vagrantControl.getOptions(),
                main.commandArgs.toArray(new String[main.commandArgs.size()]));

        vagrantControl.execute(commandArguments);
      } catch (ParseException e) {
        throw new UserError("Error parsing command arguments: " + e.getMessage());
      }

      main.divider();
      main.out("Command executed successfully");

    } catch (UserError userError) {
      main.out("");
      main.header("ERROR EXECUTING COMMAND");
      main.out(userError.getMessage());
      main.out("");
      main.out("");
      return;
    } catch (Throwable exception) {
      System.out.println("Unexpected error: " + exception.getMessage());
      exception.printStackTrace();
    }
  }
Example #24
0
  public void test15046() throws Exception {
    CommandLineParser parser = new PosixParser();
    final String[] CLI_ARGS = new String[] {"-z", "c"};
    Option option = new Option("z", "timezone", true, "affected option");
    Options cliOptions = new Options();
    cliOptions.addOption(option);
    parser.parse(cliOptions, CLI_ARGS);

    // now add conflicting option
    cliOptions.addOption("c", "conflict", true, "conflict option");
    CommandLine line = parser.parse(cliOptions, CLI_ARGS);
    assertEquals(option.getValue(), "c");
    assertTrue(!line.hasOption("c"));
  }
Example #25
0
  public void test11457() {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("verbose").create());
    String[] args = new String[] {"--verbose"};

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine cmd = parser.parse(options, args);
      assertTrue(cmd.hasOption("verbose"));
    } catch (ParseException exp) {
      exp.printStackTrace();
      fail("Unexpected Exception: " + exp.getMessage());
    }
  }
  public static void main(String[] args) throws Exception {

    String propertyFile = null;

    // create the command line parser
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("f", "file", true, "The properties file");
    options.addOption("v", "verbose", false, "Verbose logging output");
    options.addOption("h", "help", false, "Help output");

    try {
      CommandLine line = parser.parse(options, args);

      if (line.hasOption('v')) {
        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG);
      }

      if (line.hasOption('h')) {
        usage(options);
      }

      if (line.hasOption('f')) {
        propertyFile = line.getOptionValue('f');
      } else {
        throw new Exception("Please supply -f");
      }

    } catch (Exception e) {
      log.error("Invalid command line: " + e, e);
      usage(options);
    }

    Properties props = new Properties();
    props.load(new FileReader(propertyFile));
    startFromProperties(props);

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    log.info("Received shutdown signal. Shutting down...");
                    server.stop(3);
                  }
                }));
  }
Example #27
0
  public static GalenPageAction readFrom(String actionText) {
    String[] args = CommandLineParser.parseCommandLine(actionText);

    if (args.length < 2) {
      throw new SyntaxException(Line.UNKNOWN_LINE, "Cannot parse: " + actionText);
    }

    if (args[0].equals("inject")) {
      return injectActionFrom(args);
    } else if (args[0].equals("run")) {
      return runActionFrom(args);
    } else if (args[0].equals("check")) {
      return checkActionFrom(args, actionText);
    } else if (args[0].equals("cookie")) {
      return cookieActionFrom(args);
    } else if (args[0].equals("open")) {
      return openActionFrom(args);
    } else if (args[0].equals("resize")) {
      return resizeActionFrom(args);
    } else if (args[0].equals("wait")) {
      return waitActionFrom(args);
    } else if (args[0].equals("properties")) {
      return propertiesActionFrom(args);
    } else if (args[0].equals("dump")) {
      return dumpPageActionFrom(args, actionText);
    } else throw new SyntaxException(Line.UNKNOWN_LINE, "Unknown action: " + args[0]);
  }
  /**
   * Processing the input command line arguments
   *
   * @param args a list of pride db accessions
   */
  private void processCmdArgs(String[] args) {
    try {
      // parse command line input
      CommandLine cmd = cmdParser.parse(cmdOptions, args);

      // get accessions
      java.util.List<Comparable> accs = null;
      if (cmd.hasOption(ACCESSION_CMD)) {
        String accStr = cmd.getOptionValue(ACCESSION_CMD);
        accs = new ArrayList<Comparable>(AccessionUtils.expand(accStr));
      }

      // get user name
      String username = null;
      if (cmd.hasOption(USER_NAME_CMD)) {
        username = cmd.getOptionValue(USER_NAME_CMD);
      }

      // get password
      String password = null;
      if (cmd.hasOption(PASSWORD_CMD)) {
        password = cmd.getOptionValue(PASSWORD_CMD);
      }

      if (accs != null || username != null) {
        OpenValidPrideExperimentTask task =
            new OpenValidPrideExperimentTask(accs, username, password);
        task.setGUIBlocker(new DefaultGUIBlocker(task, GUIBlocker.Scope.NONE, null));
        getDesktopContext().addTask(task);
      }
    } catch (ParseException e) {
      System.err.println("Parsing command line option failed. Reason: " + e.getMessage());
    }
  }
Example #29
0
  public void test11458() {
    Options options = new Options();
    options.addOption(OptionBuilder.withValueSeparator('=').hasArgs().create('D'));
    options.addOption(OptionBuilder.withValueSeparator(':').hasArgs().create('p'));
    String[] args = new String[] {"-DJAVA_HOME=/opt/java", "-pfile1:file2:file3"};

    CommandLineParser parser = new PosixParser();

    try {
      CommandLine cmd = parser.parse(options, args);

      String[] values = cmd.getOptionValues('D');

      assertEquals(values[0], "JAVA_HOME");
      assertEquals(values[1], "/opt/java");

      values = cmd.getOptionValues('p');

      assertEquals(values[0], "file1");
      assertEquals(values[1], "file2");
      assertEquals(values[2], "file3");

      java.util.Iterator iter = cmd.iterator();
      while (iter.hasNext()) {
        Option opt = (Option) iter.next();
        switch (opt.getId()) {
          case 'D':
            assertEquals(opt.getValue(0), "JAVA_HOME");
            assertEquals(opt.getValue(1), "/opt/java");
            break;
          case 'p':
            assertEquals(opt.getValue(0), "file1");
            assertEquals(opt.getValue(1), "file2");
            assertEquals(opt.getValue(2), "file3");
            break;
          default:
            fail("-D option not found");
        }
      }
    } catch (ParseException exp) {
      fail(
          "Unexpected Exception:\nMessage:"
              + exp.getMessage()
              + "Type: "
              + exp.getClass().getName());
    }
  }
  public static void main(String[] args) {
    Options options = KeyGenCLI.buildOptions();
    HelpFormatter helpFormatter = new HelpFormatter();
    CommandLineParser parser = new GnuParser();

    try {
      CommandLine commandLine = parser.parse(options, args);
      String service = commandLine.getOptionValue("service");
      String key = Crypto.generateAes128KeyWithSeed(service);

      if (key == null) {
        throw new Exception("Key was not generated!");
      }

      JSONObject keyObject = new JSONObject();
      keyObject.put("name", service);
      keyObject.put("data", key);

      System.out.println(String.format("Key: `%s`\n", key));

      System.out.println("Key object:");
      System.out.println(keyObject.toString());
    } catch (MissingOptionException e) {
      System.out.println("Missing required option(s)!");
      helpFormatter.printHelp(
          "\nKeyGenCLI",
          "This tool generates a unique key and prints the result.",
          options,
          "",
          true);
    } catch (UnrecognizedOptionException e) {
      System.out.println("Unrecognized option!");
      helpFormatter.printHelp(
          "\nKeyGenCLI",
          "This tool generates a unique key and prints the result.",
          options,
          "",
          true);
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }