33import com .beust .jcommander .JCommander ;
44import com .beust .jcommander .Parameter ;
55import com .beust .jcommander .ParameterException ;
6- import org .utplsql .api .exception .DatabaseNotCompatibleException ;
7- import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
8- import org .utplsql .cli .exception .DatabaseConnectionFailed ;
96
107public class Cli {
118
@@ -26,36 +23,31 @@ static int runWithExitCode( String[] args ) {
2623 JCommander jc = new JCommander ();
2724 jc .setProgramName ("utplsql" );
2825
29- CommandProvider cmdProvider = new CommandProvider ();
26+ CommandProvider cmdProvider = new CommandProvider (jc );
3027
3128 cmdProvider .commands ().forEach (cmd -> jc .addCommand (cmd .getCommand (), cmd ));
3229
3330 int exitCode = DEFAULT_ERROR_CODE ;
3431
35- try {
36- jc .parse (args );
32+ if ( args .length >= 1 && args [0 ].equals ("-h" ) ) // Help?
33+ {
34+ exitCode = 0 ;
35+ jc .usage ();
36+ }
37+ else {
38+ try {
39+ jc .parse (args );
3740
38- exitCode = cmdProvider .getCommand (jc .getParsedCommand ()).run ();
41+ exitCode = cmdProvider .getCommand (jc .getParsedCommand ()).run ();
3942
40- } catch (ParameterException e ) {
41- if (jc .getParsedCommand () != null ) {
42- System .err .println (e .getMessage ());
43- jc .usage (jc .getParsedCommand ());
44- } else {
45- jc .usage ();
43+ } catch (ParameterException e ) {
44+ exitCode = new HelpCommand (jc , e .getMessage ()).run ();
45+ } catch (Exception e ) {
46+ e .printStackTrace ();
4647 }
47- } catch (Exception e ) {
48- e .printStackTrace ();
4948 }
5049
5150 return exitCode ;
5251 }
5352
54- private static class HelpCommand {
55-
56- @ Parameter (names = {HELP_CMD , "--help" }, help = true )
57- public boolean callHelp ;
58-
59- }
60-
6153}
0 commit comments