List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:alluxio.shell.command.WithWildCardPathCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI inputPath = new AlluxioURI(args[0]); List<AlluxioURI> paths = AlluxioShellUtils.getAlluxioURIs(mFileSystem, inputPath); if (paths.size() == 0) { // A unified sanity check on the paths throw new IOException(inputPath + " does not exist."); }// ww w . j av a2 s.com Collections.sort(paths, createAlluxioURIComparator()); List<String> errorMessages = new ArrayList<>(); for (AlluxioURI path : paths) { try { runCommand(path, cl); } catch (AlluxioException | IOException e) { errorMessages.add(e.getMessage()); } } if (errorMessages.size() != 0) { throw new IOException(Joiner.on('\n').join(errorMessages)); } return 0; }
From source file:com.netscape.cmstools.selftests.SelfTestShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from ww w .j a va2 s .c o m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No SelfTest ID specified."); } String selfTestID = args[0]; String output = cmd.getOptionValue("output"); SelfTestClient selfTestClient = selfTestCLI.getSelfTestClient(); SelfTestData selfTestInfo = selfTestClient.getSelfTest(selfTestID); if (output == null) { MainCLI.printMessage("SelfTest \"" + selfTestID + "\""); SelfTestCLI.printSelfTestData(selfTestInfo); } else { try (PrintWriter out = new PrintWriter(new FileWriter(output))) { out.println(selfTestInfo); } MainCLI.printMessage("Stored selfTest \"" + selfTestID + "\" into " + output); } }
From source file:com.netscape.cmstools.tps.authenticator.AuthenticatorShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from www . j a va 2s . co m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No Authenticator ID specified."); } String authenticatorID = args[0]; String output = cmd.getOptionValue("output"); AuthenticatorClient authenticatorClient = authenticatorCLI.getAuthenticatorClient(); AuthenticatorData authenticatorData = authenticatorClient.getAuthenticator(authenticatorID); if (output == null) { MainCLI.printMessage("Authenticator \"" + authenticatorID + "\""); AuthenticatorCLI.printAuthenticatorData(authenticatorData, true); } else { try (PrintWriter out = new PrintWriter(new FileWriter(output))) { out.println(authenticatorData); } MainCLI.printMessage("Stored authenticator \"" + authenticatorID + "\" into " + output); } }
From source file:com.netscape.cmstools.tps.connector.ConnectorShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from w w w. j ava 2 s .c o m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No Connector ID specified."); } String connectorID = args[0]; String output = cmd.getOptionValue("output"); ConnectorClient connectorClient = connectorCLI.getConnectorClient(); ConnectorData connectorData = connectorClient.getConnector(connectorID); if (output == null) { MainCLI.printMessage("Connector \"" + connectorID + "\""); ConnectorCLI.printConnectorData(connectorData, true); } else { try (PrintWriter out = new PrintWriter(new FileWriter(output))) { out.println(connectorData); } MainCLI.printMessage("Stored connector \"" + connectorID + "\" into " + output); } }
From source file:com.netscape.cmstools.tps.profile.ProfileMappingShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from w w w .jav a 2 s. c o m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No Profile Mapping ID specified."); } String profileMappingID = cmdArgs[0]; String output = cmd.getOptionValue("output"); ProfileMappingClient profileMappingClient = profileMappingCLI.getProfileMappingClient(); ProfileMappingData profileMappingData = profileMappingClient.getProfileMapping(profileMappingID); if (output == null) { MainCLI.printMessage("ProfileMapping \"" + profileMappingID + "\""); ProfileMappingCLI.printProfileMappingData(profileMappingData, true); } else { try (PrintWriter out = new PrintWriter(new FileWriter(output))) { out.println(profileMappingData); } MainCLI.printMessage("Stored profile mapping \"" + profileMappingID + "\" into " + output); } }
From source file:com.netscape.cmstools.tps.profile.ProfileShowCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/*from w w w. j a v a 2 s.c o m*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No Profile ID specified."); } String profileID = args[0]; String output = cmd.getOptionValue("output"); ProfileClient profileClient = profileCLI.getProfileClient(); ProfileData profileData = profileClient.getProfile(profileID); if (output == null) { MainCLI.printMessage("Profile \"" + profileID + "\""); ProfileCLI.printProfileData(profileData, true); } else { try (PrintWriter out = new PrintWriter(new FileWriter(output))) { out.println(profileData); } MainCLI.printMessage("Stored profile \"" + profileID + "\" into " + output); } }
From source file:goraci.Print.java
public int run(String[] args) throws Exception { Options options = new Options(); options.addOption("s", "start", true, "start key"); options.addOption("e", "end", true, "end key"); options.addOption("l", "limit", true, "number to print"); GnuParser parser = new GnuParser(); CommandLine cmd = null; try {/*from ww w .ja v a2s .c o m*/ cmd = parser.parse(options, args); if (cmd.getArgs().length != 0) { throw new ParseException("Command takes no arguments"); } } catch (ParseException e) { System.err.println("Failed to parse command line " + e.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getClass().getSimpleName(), options); System.exit(-1); } DataStore<Long, CINode> store = DataStoreFactory.getDataStore(Long.class, CINode.class, new Configuration()); Query<Long, CINode> query = store.newQuery(); if (cmd.hasOption("s")) query.setStartKey(new BigInteger(cmd.getOptionValue("s"), 16).longValue()); if (cmd.hasOption("e")) query.setEndKey(new BigInteger(cmd.getOptionValue("e"), 16).longValue()); if (cmd.hasOption("l")) query.setLimit(Integer.parseInt(cmd.getOptionValue("l"))); else query.setLimit(100); Result<Long, CINode> rs = store.execute(query); while (rs.next()) { CINode node = rs.get(); System.out.printf("%016x:%016x:%012d:%s\n", rs.getKey(), node.getPrev(), node.getCount(), node.getClient()); } store.close(); return 0; }
From source file:alluxio.cli.fs.command.WithWildCardPathCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); for (String arg : args) { AlluxioURI inputPath = new AlluxioURI(arg); List<AlluxioURI> paths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, inputPath); if (paths.size() == 0) { // A unified sanity check on the paths throw new IOException(inputPath + " does not exist."); }//w w w .j ava 2 s.c o m Collections.sort(paths, createAlluxioURIComparator()); List<String> errorMessages = new ArrayList<>(); for (AlluxioURI path : paths) { try { runCommand(path, cl); } catch (AlluxioException | IOException e) { errorMessages.add(e.getMessage() != null ? e.getMessage() : e.toString()); } } if (errorMessages.size() != 0) { throw new IOException(Joiner.on('\n').join(errorMessages)); } } return 0; }
From source file:alluxio.shell.command.PersistCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); for (String path : args) { AlluxioURI inputPath = new AlluxioURI(path); persist(inputPath);/*from w w w. j a v a 2 s .c o m*/ } return 0; }
From source file:com.netscape.cmstools.tps.token.TokenAddCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/*from w w w . j a v a2 s . c o m*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { throw new Exception("No Token ID specified."); } String tokenID = cmdArgs[0]; TokenData tokenData = new TokenData(); tokenData.setTokenID(tokenID); String userID = cmd.getOptionValue("user"); tokenData.setUserID(userID); String policy = cmd.getOptionValue("policy"); tokenData.setPolicy(policy); TokenClient tokenClient = tokenCLI.getTokenClient(); tokenData = tokenClient.addToken(tokenData); MainCLI.printMessage("Added token \"" + tokenID + "\""); TokenCLI.printToken(tokenData); }