Skip to content

Commit 60997d7

Browse files
committed
New entry point for Picocli
1 parent 3b5e168 commit 60997d7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/main/java/org/utplsql/cli/Cli.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.beust.jcommander.JCommander;
44
import com.beust.jcommander.ParameterException;
5+
import picocli.CommandLine;
6+
7+
import java.util.List;
58

69
public class Cli {
710

@@ -50,5 +53,34 @@ static int runWithExitCode( String[] args ) {
5053

5154
return exitCode;
5255
}
56+
static int runPicocliWithExitCode( String[] args ) {
57+
58+
LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
59+
LocaleInitializer.initLocale();
60+
61+
CommandLine commandLine = new CommandLine(UtplsqlPicocliCommand.class);
62+
commandLine.setTrimQuotes(true);
63+
64+
int exitCode = DEFAULT_ERROR_CODE;
65+
66+
try {
67+
68+
List<CommandLine> parsedLines = commandLine.parse(args);
69+
70+
for ( CommandLine parsedLine : parsedLines ) {
71+
Object command = parsedLine.getCommand();
72+
if ( command instanceof ICommand ) {
73+
exitCode = ((ICommand)command).run();
74+
break;
75+
}
76+
}
77+
} catch (ParameterException e) {
78+
e.printStackTrace();
79+
} catch (Exception e) {
80+
e.printStackTrace();
81+
}
82+
83+
return exitCode;
84+
}
5385

5486
}

src/test/java/org/utplsql/cli/RunCommandIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void run_withDbmsOutputEnabled() throws Exception {
7070

7171
int result = TestHelper.runApp("run",
7272
TestHelper.getConnectionString(),
73-
"-dbout",
73+
"-D",
7474
"--failure-exit-code=2");
7575

7676
assertValidReturnCode(result);

src/test/java/org/utplsql/cli/TestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static RunAction createRunAction(String... args) throws Exception {
5454
}
5555

5656
static int runApp(String... args) {
57-
return Cli.runWithExitCode(args);
57+
return Cli.runPicocliWithExitCode(args);
5858
}
5959

6060
static Version getFrameworkVersion() throws SQLException {

0 commit comments

Comments
 (0)