1 package org.kit.furia;
2
3 import java.io.InputStream;
4 import java.util.Properties;
5
6 import org.ajmm.obsearch.example.HelpException;
7 import org.apache.commons.cli.CommandLine;
8 import org.apache.commons.cli.CommandLineParser;
9 import org.apache.commons.cli.GnuParser;
10 import org.apache.commons.cli.HelpFormatter;
11 import org.apache.commons.cli.Option;
12 import org.apache.commons.cli.Options;
13 import org.apache.commons.cli.ParseException;
14 import org.apache.log4j.PropertyConfigurator;
15
16 public class AbstractFuriaChanCommandLine {
17
18 public static void initLogger() {
19 try {
20
21 InputStream is = AbstractFuriaChanCommandLine.class
22 .getResourceAsStream("/furiaLog4j.config");
23 Properties props = new Properties();
24 props.load(is);
25 PropertyConfigurator.configure(props);
26 } catch (final Exception e) {
27 System.err.print("Make sure log4j is configured properly"
28 + e.getMessage());
29 e.printStackTrace();
30 System.exit(48);
31 }
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public static CommandLine getCommandLine(final Options options,
50 final Class c, final String[] args) throws ParseException,
51 HelpException {
52 final CommandLineParser parser = new GnuParser();
53 final Option help = new Option("help", "print this message");
54 options.addOption(help);
55 final CommandLine line = parser.parse(options, args);
56
57 if (line.hasOption("help")) {
58 final HelpFormatter formatter = new HelpFormatter();
59 formatter.printHelp(c.getName(), options, true);
60 throw new HelpException();
61 }
62 return line;
63 }
64
65 }