use of org.apache.commons.cli.CommandLine in project heron by twitter.
the class CppCheckstyle method main.
public static void main(String[] args) throws IOException {
CommandLineParser parser = new DefaultParser();
// create the Options
Options options = new Options();
options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file").desc("bazel extra action protobuf file").build());
options.addOption(Option.builder("c").required(true).hasArg().longOpt("cpplint_file").desc("Executable cpplint file to invoke").build());
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);
String extraActionFile = line.getOptionValue("f");
String cpplintFile = line.getOptionValue("c");
Collection<String> sourceFiles = getSourceFiles(extraActionFile);
if (sourceFiles.size() == 0) {
LOG.fine("No cpp files found by checkstyle");
return;
}
LOG.fine(sourceFiles.size() + " cpp files found by checkstyle");
// Create and run the command
List<String> commandBuilder = new ArrayList<>();
commandBuilder.add(cpplintFile);
commandBuilder.add("--linelength=100");
// TODO: https://github.com/twitter/heron/issues/466,
// Remove "runtime/references" when we fix all non-const references in our codebase.
// TODO: https://github.com/twitter/heron/issues/467,
// Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions
commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn");
commandBuilder.addAll(sourceFiles);
runLinter(commandBuilder);
} catch (ParseException exp) {
LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java " + CLASSNAME, options);
}
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class FixCalendarTZUtil method main.
public static void main(String[] args) {
CliUtil.toolSetup();
FixCalendarTZUtil util = null;
try {
util = new FixCalendarTZUtil();
} catch (ServiceException e) {
System.err.println(e.getMessage());
System.exit(1);
}
try {
CommandLine cl = util.getCommandLine(args);
if (cl == null)
return;
if (!cl.hasOption(O_RULEFILE))
throw new ParseException("Missing required option --" + O_RULEFILE);
String after = null;
if (cl.hasOption(O_AFTER))
after = cl.getOptionValue(O_AFTER);
util.doit(getZAuthToken(cl), cl.getOptionValue(O_RULEFILE), cl.getOptionValues(O_ACCOUNT), after, cl.hasOption(O_SYNC));
System.exit(0);
} catch (ParseException e) {
util.usage(e);
} catch (Exception e) {
System.err.println("Error occurred: " + e.getMessage());
util.usage(null);
}
System.exit(1);
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class FixCalendarPriorityUtil method main.
public static void main(String[] args) {
CliUtil.toolSetup();
FixCalendarPriorityUtil util = null;
try {
util = new FixCalendarPriorityUtil();
} catch (ServiceException e) {
System.err.println(e.getMessage());
System.exit(1);
}
try {
CommandLine cl = util.getCommandLine(args);
if (cl == null)
return;
util.doit(getZAuthToken(cl), cl.getOptionValues(O_ACCOUNT), cl.hasOption(O_SYNC));
System.exit(0);
} catch (ParseException e) {
util.usage(e);
} catch (Exception e) {
System.err.println("Error occurred: " + e.getMessage());
util.usage(null);
}
System.exit(1);
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class WaitSetValidator method main.
/**
* @param args
*/
public static void main(String[] args) {
CliUtil.toolSetup();
WaitSetValidator t = new WaitSetValidator();
CommandLineParser parser = new PosixParser();
Options options = new Options();
options.addOption("i", "id", true, "Wait Set ID");
options.addOption("h", "host", true, "Hostname");
options.addOption("u", "user", true, "Username");
options.addOption("p", "pw", true, "Password");
options.addOption("?", "help", false, "Help");
options.addOption("v", "verbose", false, "Verbose");
CommandLine cl = null;
boolean err = false;
String[] hosts;
String[] ids;
try {
cl = parser.parse(options, args, true);
} catch (ParseException pe) {
printError("error: " + pe.getMessage());
err = true;
}
if (err || cl.hasOption('?')) {
t.usage();
}
String id = null, host = null, user = null, pw = null;
if (!cl.hasOption('i'))
t.usage();
id = cl.getOptionValue('i');
if (cl.hasOption('h'))
host = cl.getOptionValue('h');
else
host = "http://localhost:7071/service/admin";
if (cl.hasOption('u'))
user = cl.getOptionValue('u');
else
user = "admin";
if (cl.hasOption('p'))
pw = cl.getOptionValue('p');
else
pw = "test123";
if (cl.hasOption('v'))
t.setVerbose(true);
hosts = host.split(",");
ids = id.split(",");
if (hosts.length != ids.length) {
System.err.println("If multiple hosts or ids are specified, the same number is required of each");
System.exit(3);
}
for (int i = 0; i < hosts.length; i++) {
if (i > 0)
System.out.println("\n\n");
System.out.println("Checking server " + hosts[i] + " waitsetId=" + ids[i]);
t.run(ids[i], hosts[i], user, pw);
}
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class ZMailboxUtil method main.
public static void main(String[] args) throws IOException, ServiceException {
CliUtil.toolSetup();
SoapTransport.setDefaultUserAgent("zmmailbox", BuildInfo.VERSION);
ZMailboxUtil pu = new ZMailboxUtil();
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption("a", "admin", true, "admin account name to auth as");
options.addOption("z", "zadmin", false, "use zimbra admin name/password from localconfig for admin/password");
options.addOption("h", "help", false, "display usage");
options.addOption("f", "file", true, "use file as input stream");
options.addOption("u", "url", true, "http[s]://host[:port] of server to connect to");
options.addOption("r", "protocol", true, "protocol to use for request/response [soap11, soap12, json]");
options.addOption("m", "mailbox", true, "mailbox to open");
options.addOption(null, "auth", true, "account name to auth as; defaults to -m unless -A is used");
options.addOption("A", "admin-priv", false, "execute requests with admin privileges");
options.addOption("p", "password", true, "auth password");
options.addOption("P", "passfile", true, "filename with password in it");
options.addOption("t", "timeout", true, "timeout (in seconds)");
options.addOption("v", "verbose", false, "verbose mode");
options.addOption("d", "debug", false, "debug mode");
options.addOption(SoapCLI.OPT_AUTHTOKEN);
options.addOption(SoapCLI.OPT_AUTHTOKENFILE);
CommandLine cl = null;
boolean err = false;
try {
cl = parser.parse(options, args, true);
} catch (ParseException pe) {
stderr.println("error: " + pe.getMessage());
err = true;
}
if (err || cl.hasOption('h')) {
pu.usage();
}
try {
boolean isAdmin = false;
pu.setVerbose(cl.hasOption('v'));
if (cl.hasOption('a')) {
pu.setAdminAccountName(cl.getOptionValue('a'));
pu.setUrl(DEFAULT_ADMIN_URL, true);
isAdmin = true;
}
if (cl.hasOption('z')) {
pu.setAdminAccountName(LC.zimbra_ldap_user.value());
pu.setPassword(LC.zimbra_ldap_password.value());
pu.setUrl(DEFAULT_ADMIN_URL, true);
isAdmin = true;
}
if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE))
pu.usage();
if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
pu.setAdminAuthToken(ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN)));
pu.setUrl(DEFAULT_ADMIN_URL, true);
isAdmin = true;
}
if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
pu.setAdminAuthToken(ZAuthToken.fromJSONString(authToken));
pu.setUrl(DEFAULT_ADMIN_URL, true);
isAdmin = true;
}
String authAccount, targetAccount;
if (cl.hasOption('m')) {
if (!cl.hasOption('p') && !cl.hasOption('P') && !cl.hasOption('y') && !cl.hasOption('Y') && !cl.hasOption('z')) {
throw ZClientException.CLIENT_ERROR("-m requires one of the -p/-P/-y/-Y/-z options", null);
}
targetAccount = cl.getOptionValue('m');
} else {
targetAccount = null;
}
if ((cl.hasOption("A") || cl.hasOption("auth")) && !cl.hasOption('m')) {
throw ZClientException.CLIENT_ERROR("-A/--auth requires -m", null);
}
if (cl.hasOption("A")) {
if (!isAdmin) {
throw ZClientException.CLIENT_ERROR("-A requires admin auth", null);
}
if (cl.hasOption("auth")) {
throw ZClientException.CLIENT_ERROR("-A cannot be combined with --auth", null);
}
authAccount = null;
} else if (cl.hasOption("auth")) {
authAccount = cl.getOptionValue("auth");
} else {
// default case
authAccount = targetAccount;
}
if (!StringUtil.isNullOrEmpty(authAccount))
pu.setAuthAccountName(authAccount);
if (!StringUtil.isNullOrEmpty(targetAccount))
pu.setTargetAccountName(targetAccount);
if (cl.hasOption('u'))
pu.setUrl(cl.getOptionValue('u'), isAdmin);
if (cl.hasOption('p'))
pu.setPassword(cl.getOptionValue('p'));
if (cl.hasOption('P')) {
pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
}
if (cl.hasOption('d'))
pu.setDebug(true);
if (cl.hasOption('t'))
pu.setTimeout(cl.getOptionValue('t'));
args = cl.getArgs();
pu.setInteractive(args.length < 1);
pu.initMailbox();
if (args.length < 1) {
InputStream is = null;
if (cl.hasOption('f')) {
is = new FileInputStream(cl.getOptionValue('f'));
} else {
if (LC.command_line_editing_enabled.booleanValue()) {
try {
CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmmailbox_history");
} catch (IOException e) {
System.err.println("Command line editing will be disabled: " + e);
if (pu.mGlobalVerbose) {
e.printStackTrace(System.err);
}
}
}
// This has to happen last because JLine modifies System.in.
is = System.in;
}
pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
} else {
pu.execute(args);
}
} catch (ServiceException e) {
Throwable cause = e.getCause();
stderr.println("ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? "" : " (cause: " + cause.getClass().getName() + " " + cause.getMessage() + ")"));
if (pu.mGlobalVerbose)
e.printStackTrace(stderr);
System.exit(2);
}
}
Aggregations