use of org.apache.commons.cli.UnrecognizedOptionException in project kie-wb-common by kiegroup.
the class AFMavenCli method doMain.
public int doMain(AFCliRequest cliRequest, ClassWorld classWorld) {
PlexusContainer localContainer = null;
try {
initialize(cliRequest);
cli(cliRequest);
logging(cliRequest);
version(cliRequest);
properties(cliRequest);
localContainer = container(cliRequest, classWorld);
commands(cliRequest);
configure(cliRequest);
toolchains(cliRequest);
populateRequest(cliRequest);
repository(cliRequest);
return execute(cliRequest);
} catch (ExitException e) {
e.getStackTrace();
return e.exitCode;
} catch (UnrecognizedOptionException e) {
e.getStackTrace();
return 1;
} catch (BuildAbort e) {
e.getStackTrace();
AFCLIReportingUtils.showError(slf4jLogger, "ABORTED", e, cliRequest.isShowErrors());
return 2;
} catch (Exception e) {
e.getStackTrace();
AFCLIReportingUtils.showError(slf4jLogger, "Error executing Maven.", e, cliRequest.isShowErrors());
return 1;
} finally {
if (localContainer != null) {
localContainer.dispose();
localContainer = null;
}
}
}
use of org.apache.commons.cli.UnrecognizedOptionException in project Angelia-core by Maxopoly.
the class PluginManager method parseOptions.
private Map<String, List<String>> parseOptions(AngeliaPlugin plugin, String[] args) {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
for (Option opt : plugin.getOptions()) {
options.addOption(opt);
}
CommandLine cmd;
try {
cmd = parser.parse(options, args, true);
} catch (MissingArgumentException e) {
Option opt = e.getOption();
connection.getLogger().warn("An incorrect amount of argument(s) was supplied for the option " + opt.getArgName() + ". Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (MissingOptionException e) {
List<String> missingOptions = e.getMissingOptions();
StringBuilder sb = new StringBuilder();
for (String opt : missingOptions) {
sb.append(opt + " ");
}
connection.getLogger().warn("The required argument(s) " + sb.toString() + "were not supplied. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (UnrecognizedOptionException e) {
connection.getLogger().warn("The supplied option " + e.getOption() + " could not be recognized. Run \"helpplugin " + plugin.getName() + "\" for more information on how to use this command");
return null;
} catch (ParseException e) {
connection.getLogger().error("An unknown exception occured while trying to parse arguments", e);
return null;
}
Map<String, List<String>> parsedValues = new HashMap<String, List<String>>();
for (Option option : cmd.getOptions()) {
if (option.hasArg()) {
parsedValues.put(option.getOpt(), Arrays.asList(cmd.getOptionValues(option.getOpt())));
} else {
parsedValues.put(option.getOpt(), new LinkedList<String>());
}
}
return parsedValues;
}
use of org.apache.commons.cli.UnrecognizedOptionException in project Shadbot by Shadorc.
the class WallpaperCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
LoadingMessage loadingMsg = new LoadingMessage("Loading wallpaper...", context.getChannel());
loadingMsg.send();
if (wallhaven == null) {
wallhaven = new Wallhaven(APIKeys.get(APIKey.WALLHAVEN_LOGIN), APIKeys.get(APIKey.WALLHAVEN_PASSWORD));
}
Options options = new Options();
options.addOption("p", PURITY, true, FormatUtils.format(Purity.values(), purity -> purity.toString().toLowerCase(), ", "));
options.addOption("c", CATEGORY, true, FormatUtils.format(Category.values(), cat -> cat.toString().toLowerCase(), ", "));
Option ratioOpt = new Option("rat", RATIO, true, "image ratio");
ratioOpt.setValueSeparator('x');
options.addOption(ratioOpt);
Option resOpt = new Option("res", RESOLUTION, true, "image resolution");
resOpt.setValueSeparator('x');
options.addOption(resOpt);
Option keyOpt = new Option("k", KEYWORD, true, KEYWORD);
keyOpt.setValueSeparator(',');
options.addOption(keyOpt);
CommandLine cmdLine;
try {
List<String> args = StringUtils.split(context.getArg());
cmdLine = new DefaultParser().parse(options, args.toArray(new String[args.size()]));
} catch (UnrecognizedOptionException | org.apache.commons.cli.MissingArgumentException err) {
loadingMsg.delete();
throw new IllegalCmdArgumentException(String.format("%s. Use `%shelp %s` for more information.", err.getMessage(), context.getPrefix(), this.getName()));
} catch (ParseException err) {
loadingMsg.delete();
Utils.handle("getting a wallpaper", context, err);
return;
}
Purity purity = this.parseEnum(loadingMsg, context, Purity.class, PURITY, cmdLine.getOptionValue(PURITY, Purity.SFW.toString()));
if ((purity.equals(Purity.NSFW) || purity.equals(Purity.SKETCHY)) && !context.getChannel().isNSFW()) {
loadingMsg.edit(TextUtils.mustBeNSFW(context.getPrefix()));
return;
}
SearchQueryBuilder queryBuilder = new SearchQueryBuilder();
queryBuilder.purity(purity);
if (cmdLine.hasOption(CATEGORY)) {
queryBuilder.categories(this.parseEnum(loadingMsg, context, Category.class, CATEGORY, cmdLine.getOptionValue(CATEGORY)));
}
if (cmdLine.hasOption(RATIO)) {
Dimension dim = this.parseDim(loadingMsg, context, RATIO, cmdLine.getOptionValues(RATIO));
queryBuilder.ratios(new Ratio((int) dim.getWidth(), (int) dim.getHeight()));
}
if (cmdLine.hasOption(RESOLUTION)) {
Dimension dim = this.parseDim(loadingMsg, context, RESOLUTION, cmdLine.getOptionValues(RESOLUTION));
queryBuilder.resolutions(new Resolution((int) dim.getWidth(), (int) dim.getHeight()));
}
if (cmdLine.hasOption(KEYWORD)) {
queryBuilder.keywords(cmdLine.getOptionValues(KEYWORD));
}
try {
List<Wallpaper> wallpapers = wallhaven.search(queryBuilder.pages(1).build());
if (wallpapers.isEmpty()) {
loadingMsg.edit(TextUtils.noResult(context.getMessage().getContent()));
return;
}
Wallpaper wallpaper = wallpapers.get(ThreadLocalRandom.current().nextInt(wallpapers.size()));
String tags = FormatUtils.format(wallpaper.getTags(), tag -> String.format("`%s`", StringUtils.remove(tag.toString(), "#")), " ");
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Wallpaper").withAuthorUrl(wallpaper.getUrl()).withImage(wallpaper.getImageUrl()).appendField("Resolution", wallpaper.getResolution().toString(), false).appendField("Tags", tags, false);
loadingMsg.edit(embed.build());
} catch (ConnectionException err) {
loadingMsg.delete();
Utils.handle("getting a wallpaper", context, err.getCause());
}
}
use of org.apache.commons.cli.UnrecognizedOptionException in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsTransformerMain method run.
/**
***************************************************************************
* {@link Runnable} Interface
***************************************************************************
*/
public void run(String[] args) throws IOException {
if (needsHelp(args)) {
printHelp();
System.exit(0);
}
try {
CommandLine cli = _parser.parse(_options, args, true);
runApplication(cli, args);
} catch (MissingOptionException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (MissingArgumentException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (UnrecognizedOptionException ex) {
System.err.println("Unknown argument: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (AlreadySelectedException ex) {
System.err.println("Argument already selected: " + ex.getMessage());
printHelp();
System.exit(-2);
} catch (ParseException ex) {
System.err.println(ex.getMessage());
printHelp();
System.exit(-2);
} catch (TransformSpecificationException ex) {
System.err.println("error with transform line: " + ex.getLine());
System.err.println(ex.getMessage());
System.exit(-1);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
use of org.apache.commons.cli.UnrecognizedOptionException 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);
}
Aggregations