List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:com.netscape.cmstools.tps.authenticator.AuthenticatorAddCLI.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 av a 2 s .co m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 0) { throw new Exception("Too many arguments specified."); } String input = cmd.getOptionValue("input"); AuthenticatorData authenticatorData; try (BufferedReader in = new BufferedReader(new FileReader(input)); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw, true)) { String line; while ((line = in.readLine()) != null) { out.println(line); } authenticatorData = AuthenticatorData.valueOf(sw.toString()); } AuthenticatorClient authenticatorClient = authenticatorCLI.getAuthenticatorClient(); authenticatorData = authenticatorClient.addAuthenticator(authenticatorData); MainCLI.printMessage("Added authenticator \"" + authenticatorData.getID() + "\""); AuthenticatorCLI.printAuthenticatorData(authenticatorData, true); }
From source file:com.netscape.cmstools.tps.connector.ConnectorAddCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/* www . java2 s.com*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 0) { throw new Exception("Too many arguments specified."); } String input = cmd.getOptionValue("input"); ConnectorData connectorData; try (BufferedReader in = new BufferedReader(new FileReader(input)); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw, true)) { String line; while ((line = in.readLine()) != null) { out.println(line); } connectorData = ConnectorData.valueOf(sw.toString()); } ConnectorClient connectorClient = connectorCLI.getConnectorClient(); connectorData = connectorClient.addConnector(connectorData); MainCLI.printMessage("Added connector \"" + connectorData.getID() + "\""); ConnectorCLI.printConnectorData(connectorData, true); }
From source file:com.netscape.cmstools.tps.profile.ProfileAddCLI.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 != 0) { throw new Exception("Too many arguments specified."); } String input = cmd.getOptionValue("input"); ProfileData profileData; try (BufferedReader in = new BufferedReader(new FileReader(input)); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw, true)) { String line; while ((line = in.readLine()) != null) { out.println(line); } profileData = ProfileData.valueOf(sw.toString()); } ProfileClient profileClient = profileCLI.getProfileClient(); profileData = profileClient.addProfile(profileData); MainCLI.printMessage("Added profile \"" + profileData.getID() + "\""); ProfileCLI.printProfileData(profileData, true); }
From source file:com.netscape.cmstools.tps.profile.ProfileMappingAddCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();//from w ww . ja va 2 s. c o m return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 0) { throw new Exception("Too many arguments specified."); } String input = cmd.getOptionValue("input"); ProfileMappingData profileMappingData; try (BufferedReader in = new BufferedReader(new FileReader(input)); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw, true)) { String line; while ((line = in.readLine()) != null) { out.println(line); } profileMappingData = ProfileMappingData.valueOf(sw.toString()); } ProfileMappingClient profileMappingClient = profileMappingCLI.getProfileMappingClient(); profileMappingData = profileMappingClient.addProfileMapping(profileMappingData); MainCLI.printMessage("Added profile mapping \"" + profileMappingData.getID() + "\""); ProfileMappingCLI.printProfileMappingData(profileMappingData, true); }
From source file:alluxio.cli.fs.command.MountCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); if (args.length == 0) { Map<String, MountPointInfo> mountTable = mFileSystem.getMountTable(); UfsCommand.printMountInfo(mountTable); return 0; }/*from w ww . j a va 2s.c o m*/ AlluxioURI alluxioPath = new AlluxioURI(args[0]); AlluxioURI ufsPath = new AlluxioURI(args[1]); MountOptions options = MountOptions.defaults(); if (cl.hasOption(READONLY_OPTION.getLongOpt())) { options.setReadOnly(true); } if (cl.hasOption(SHARED_OPTION.getLongOpt())) { options.setShared(true); } if (cl.hasOption(OPTION_OPTION.getLongOpt())) { Properties properties = cl.getOptionProperties(OPTION_OPTION.getLongOpt()); options.setProperties(Maps.fromProperties(properties)); } mFileSystem.mount(alluxioPath, ufsPath, options); System.out.println("Mounted " + ufsPath + " at " + alluxioPath); return 0; }
From source file:alluxio.cli.fs.command.DistributedLoadCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI path = new AlluxioURI(args[0]); int replication = 1; if (cl.hasOption(REPLICATION)) { replication = Integer.parseInt(cl.getOptionValue(REPLICATION)); }/*from w w w. j a va 2 s .c o m*/ try { load(path, replication); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return -1; } return 0; }
From source file:com.netflix.bdp.s3mper.cli.S3mper.java
private void processSQS(String[] args) throws Exception { GnuParser parser = new GnuParser(); Options options = new Options(); CommandLine cmdline = parser.parse(options, args); SQS_CMD cmd = SQS_CMD.valueOf(cmdline.getArgs()[0].toUpperCase()); AlertJanitor janitor = new AlertJanitor(); janitor.initalize(PathUtil.S3N, new Configuration()); String queue = janitor.resolveQueueUrl(cmdline.getArgs()[1]); switch (cmd) { case LOG:/*from w w w . j a v a 2s.c om*/ janitor.writeLogs(queue, new Path(cmdline.getArgs()[2])); break; case PURGE: janitor.clearAll(queue); break; default: usage(); } }
From source file:alluxio.cli.fs.command.HelpCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); SortedSet<String> sortedCmds; Map<String, Command> commands = FileSystemShellUtils.loadCommands(mFileSystem); try (PrintWriter pw = new PrintWriter(System.out)) { if (args.length == 0) { // print help messages for all supported commands. sortedCmds = new TreeSet<>(commands.keySet()); for (String commandName : sortedCmds) { Command command = commands.get(commandName); printCommandInfo(command, pw); pw.println();//from w w w. j a v a 2 s.c om } } else if (commands.containsKey(args[0])) { Command command = commands.get(args[0]); printCommandInfo(command, pw); } else { pw.println(args[0] + " is an unknown command."); return -1; } return 0; } }
From source file:alluxio.cli.fs.command.SetReplicationCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI path = new AlluxioURI(args[0]); Integer replicationMax = cl.hasOption("max") ? Integer.valueOf(cl.getOptionValue("max")) : null; Integer replicationMin = cl.hasOption("min") ? Integer.valueOf(cl.getOptionValue("min")) : null; boolean recursive = cl.hasOption("R"); if (replicationMax == null && replicationMin == null) { throw new IOException("At least one option of '-max' or '-min' must be specified"); }/*from www.j a v a2 s. c om*/ if (replicationMax != null && replicationMin != null && replicationMax >= 0 && replicationMax < replicationMin) { throw new IOException("Invalid values for '-max' and '-min' options"); } setReplication(path, replicationMax, replicationMin, recursive); return 0; }
From source file:alluxio.cli.fsadmin.command.UfsCommand.java
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); String ufsPath = args[0];/*w ww. jav a 2s .c om*/ AlluxioURI ufsUri = new AlluxioURI(ufsPath); if (!PathUtils.normalizePath(ufsUri.getPath(), AlluxioURI.SEPARATOR).equals(AlluxioURI.SEPARATOR)) { System.out.println("The ufs path should have only scheme and authority but no path."); return -1; } if (cl.hasOption(MODE_OPTION.getLongOpt())) { UnderFileSystem.UfsMode mode; switch (cl.getOptionValue(MODE_OPTION.getLongOpt())) { case "noAccess": mode = UnderFileSystem.UfsMode.NO_ACCESS; break; case "readOnly": mode = UnderFileSystem.UfsMode.READ_ONLY; break; case "readWrite": mode = UnderFileSystem.UfsMode.READ_WRITE; break; default: System.out.println("Unrecognized mode"); return -1; } mMasterClient.updateUfsMode(ufsUri, UpdateUfsModeOptions.defaults().setUfsMode(mode)); System.out.println("Ufs mode updated"); return 0; } System.out.println("No attribute to update"); return 0; }