equal
deleted
inserted
replaced
38 * @author Ing. František Kučera (frantovo.cz) |
38 * @author Ing. František Kučera (frantovo.cz) |
39 */ |
39 */ |
40 public class CLIStarter implements ConfigurationProvider { |
40 public class CLIStarter implements ConfigurationProvider { |
41 |
41 |
42 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
42 private static final Logger log = Logger.getLogger(CLIStarter.class.getName()); |
|
43 private static final int EXIT_SUCCESS = 0; |
|
44 private static final int EXIT_EXPECTED_ERROR = 3; |
|
45 private static final int EXIT_SQL_ERROR = 4; |
43 private CLIOptions options; |
46 private CLIOptions options; |
44 private Configuration configuration; |
47 private Configuration configuration; |
45 |
48 |
46 public static void main(String[] args) { |
49 public static void main(String[] args) { |
47 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
50 log.log(Level.FINE, "Starting " + Constants.PROGRAM_NAME); |
48 |
51 int exitCode = EXIT_EXPECTED_ERROR; |
|
52 |
49 if (args.length == 0) { |
53 if (args.length == 0) { |
50 args = new String[]{CLIParser.Tokens.INFO_HELP}; |
54 args = new String[]{CLIParser.Tokens.INFO_HELP}; |
51 } |
55 } |
52 |
56 |
53 try { |
57 try { |
56 options.validate(); |
60 options.validate(); |
57 CLIStarter starter = new CLIStarter(options); |
61 CLIStarter starter = new CLIStarter(options); |
58 starter.installDefaultConfiguration(); |
62 starter.installDefaultConfiguration(); |
59 starter.process(); |
63 starter.process(); |
60 log.log(Level.FINE, "All done"); |
64 log.log(Level.FINE, "All done"); |
|
65 exitCode = EXIT_SUCCESS; |
61 } catch (CLIParserException e) { |
66 } catch (CLIParserException e) { |
62 log.log(Level.SEVERE, "Unable to parse CLI options", e); |
67 log.log(Level.SEVERE, "Unable to parse CLI options", e); |
63 } catch (InvalidOptionsException e) { |
68 } catch (InvalidOptionsException e) { |
64 log.log(Level.SEVERE, "Invalid CLI options", e); |
69 log.log(Level.SEVERE, "Invalid CLI options", e); |
65 for (InvalidOptionsException.OptionProblem p : e.getProblems()) { |
70 for (InvalidOptionsException.OptionProblem p : e.getProblems()) { |
67 } |
72 } |
68 } catch (ConfigurationException e) { |
73 } catch (ConfigurationException e) { |
69 log.log(Level.SEVERE, "Configuration problem", e); |
74 log.log(Level.SEVERE, "Configuration problem", e); |
70 } catch (SQLException e) { |
75 } catch (SQLException e) { |
71 log.log(Level.SEVERE, "SQL problem", e); |
76 log.log(Level.SEVERE, "SQL problem", e); |
|
77 exitCode = EXIT_SQL_ERROR; |
72 } catch (FormatterException e) { |
78 } catch (FormatterException e) { |
73 log.log(Level.SEVERE, "Formatting problem", e); |
79 log.log(Level.SEVERE, "Formatting problem", e); |
74 } |
80 } |
|
81 |
|
82 System.exit(exitCode); |
75 } |
83 } |
76 |
84 |
77 public CLIStarter(CLIOptions options) { |
85 public CLIStarter(CLIOptions options) { |
78 this.options = options; |
86 this.options = options; |
79 } |
87 } |