use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method main.
// main
public static void main(String[] args) throws Exception {
// command line handling
CommandLine cl = null;
Params params = null;
try {
cl = parseArgs(args);
if (cl.hasOption(OPT_HELP)) {
usage(null);
System.exit(0);
}
params = initParams(cl);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(1);
}
// parse tzdata source
ZoneInfoParser parser = new ZoneInfoParser();
for (File tzdataFile : params.tzdataFiles) {
Reader r = null;
try {
r = new InputStreamReader(new FileInputStream(tzdataFile), "UTF-8");
parser.readTzdata(r);
} catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("Line: " + e.getErrorOffset());
System.err.println("File: " + tzdataFile.getAbsolutePath());
e.printStackTrace();
System.exit(1);
} finally {
if (r != null)
r.close();
}
}
parser.analyze();
// read extra data file containing primary TZ list and zone match scores
if (params.extraDataFile != null) {
Reader r = null;
try {
r = new InputStreamReader(new FileInputStream(params.extraDataFile), "UTF-8");
readExtraData(r);
} catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("Line: " + e.getErrorOffset());
System.err.println("File: " + params.extraDataFile.getAbsolutePath());
e.printStackTrace();
System.exit(1);
} finally {
if (r != null)
r.close();
}
}
Writer out;
if (params.outputFile != null) {
out = new PrintWriter(params.outputFile, "UTF-8");
} else {
out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"));
}
try {
StringBuilder hdr = new StringBuilder("BEGIN:VCALENDAR");
hdr.append(CRLF);
hdr.append("PRODID:Zimbra-Calendar-Provider").append(CRLF);
hdr.append("VERSION:2.0").append(CRLF);
hdr.append("METHOD:PUBLISH").append(CRLF);
out.write(hdr.toString());
Map<String, VTimeZone> oldTimeZones = makeOldTimeZonesMap(params);
Set<Zone> zones = new TreeSet<Zone>(new ZoneComparatorByGmtOffset());
zones.addAll(parser.getZones());
Set<String> zoneIDs = new TreeSet<String>();
for (Zone zone : zones) {
zoneIDs.add(zone.getName());
}
for (Zone zone : zones) {
out.write(getTimeZoneForZone(zone, params, zoneIDs, oldTimeZones));
}
StringBuilder footer = new StringBuilder("END:VCALENDAR");
footer.append(CRLF);
out.write(footer.toString());
} finally {
out.close();
}
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class MimeDetect method main.
public static void main(String[] args) {
int limit = -1;
MimeDetect md = new MimeDetect();
Options opts = new Options();
CommandLineParser parser = new GnuParser();
int ret = 1;
opts.addOption("d", "data", false, "data only");
opts.addOption("g", "globs", true, "globs file");
opts.addOption("l", "limit", true, "size limit");
opts.addOption("m", "magic", true, "magic file");
opts.addOption("n", "name", false, "name only");
opts.addOption("v", "validate", false, "validate extension and data");
try {
CommandLine cl = parser.parse(opts, args);
String file;
String globs = LC.shared_mime_info_globs.value();
String magic = LC.shared_mime_info_magic.value();
String type;
if (cl.hasOption('g'))
globs = cl.getOptionValue('g');
if (cl.hasOption('l'))
limit = Integer.parseInt(cl.getOptionValue('l'));
if (cl.hasOption('m'))
magic = cl.getOptionValue('m');
if (cl.getArgs().length != 1)
usage(opts);
file = cl.getArgs()[0];
md.parse(globs, magic);
if (cl.hasOption('n')) {
type = md.detect(file);
} else if (file.equals("-")) {
type = md.detect(System.in, limit);
} else if (cl.hasOption('d')) {
type = md.detect(new FileInputStream(file), limit);
} else if (cl.hasOption('v')) {
type = md.validate(new File(file), limit);
} else {
type = md.detect(new File(file), limit);
}
if (type == null) {
System.out.println("unknown");
} else {
System.out.println(type);
ret = 0;
}
} catch (Exception e) {
e.printStackTrace(System.out);
if (e instanceof UnrecognizedOptionException)
usage(opts);
}
System.exit(ret);
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class RandomPassword method main.
public static void main(String[] args) {
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption("l", "localpart", false, "generated string does not contain dot(.)");
CommandLine cl = null;
boolean err = false;
try {
cl = parser.parse(options, args, true);
} catch (ParseException pe) {
System.err.println("error: " + pe.getMessage());
err = true;
}
if (err || cl.hasOption('h')) {
usage();
}
boolean localpart = false;
int minLength = DEFAULT_MIN_LENGTH;
int maxLength = DEFAULT_MAX_LENGTH;
if (cl.hasOption('l'))
localpart = true;
args = cl.getArgs();
if (args.length != 0) {
if (args.length != 2) {
usage();
}
try {
minLength = Integer.valueOf(args[0]).intValue();
maxLength = Integer.valueOf(args[1]).intValue();
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
}
System.out.println(generate(minLength, maxLength, localpart));
}
use of org.apache.commons.cli.CommandLine in project zm-mailbox by Zimbra.
the class SoapApiChangeLog method main.
/**
* Main
*/
public static void main(String[] args) throws Exception {
CommandLineParser parser = new PosixParser();
Options options = new Options();
Option opt;
opt = new Option("d", ARG_OUTPUT_DIR, true, "Output directory for changelog information");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", ARG_TEMPLATES_DIR, true, "Directory containing Freemarker templates");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("b", ARG_APIDESC_BASELINE_JSON, true, "JSON file - description of baseline SOAP API");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("c", ARG_APIDESC_CURRENT_JSON, true, "JSON file - description of current SOAP API");
opt.setRequired(true);
options.addOption(opt);
CommandLine cl = null;
try {
cl = parser.parse(options, args, true);
} catch (ParseException pe) {
System.err.println("error: " + pe.getMessage());
System.exit(2);
}
String baselineApiDescriptionJson = cl.getOptionValue('b');
String currentApiDescriptionJson = cl.getOptionValue('c');
SoapApiChangeLog clog = new SoapApiChangeLog(cl.getOptionValue('d'), cl.getOptionValue('t'));
clog.setBaselineDesc(SoapApiDescription.deserializeFromJson(new File(baselineApiDescriptionJson)));
clog.setCurrentDesc(SoapApiDescription.deserializeFromJson(new File(currentApiDescriptionJson)));
clog.makeChangeLogDataModel();
clog.writeChangelog();
}
use of org.apache.commons.cli.CommandLine in project alluxio by Alluxio.
the class JournalTool method parseInputArgs.
/**
* Parses the input args with a command line format, using
* {@link org.apache.commons.cli.CommandLineParser}.
*
* @param args the input args
* @return true if parsing succeeded
*/
private static boolean parseInputArgs(String[] args) {
CommandLineParser parser = new BasicParser();
CommandLine cmd;
try {
cmd = parser.parse(OPTIONS, args);
} catch (ParseException e) {
System.out.println("Failed to parse input args: " + e);
return false;
}
sNoTimeout = cmd.hasOption("noTimeout");
sHelp = cmd.hasOption("help");
return true;
}
Aggregations