11package com .ksm .domino .cli ;
22
3- import static picocli .CommandLine .Command ;
4- import static picocli .CommandLine .Option ;
5- import static picocli .CommandLine .ScopeType ;
6- import static picocli .CommandLine .Spec ;
7-
83import java .net .http .HttpRequest .Builder ;
94import java .util .function .Consumer ;
105
6+ import org .apache .commons .lang3 .StringUtils ;
7+ import org .apache .commons .lang3 .Strings ;
8+ import org .apache .commons .lang3 .SystemUtils ;
9+ import org .fusesource .jansi .AnsiConsole ;
10+
1111import com .ksm .domino .cli .command .collaborator .Collaborator ;
1212import com .ksm .domino .cli .command .dataset .Dataset ;
1313import com .ksm .domino .cli .command .datasource .DataSource ;
2121import com .ksm .domino .cli .provider .OutputExceptionHandler ;
2222import com .ksm .domino .cli .provider .OutputFormat ;
2323import com .ksm .domino .cli .provider .VersionProvider ;
24+
2425import io .quarkus .picocli .runtime .annotations .TopCommand ;
25- import org .apache .commons .lang3 .StringUtils ;
26- import org .apache .commons .lang3 .Strings ;
27- import org .apache .commons .lang3 .SystemUtils ;
28- import org .fusesource .jansi .AnsiConsole ;
2926import picocli .CommandLine ;
27+ import picocli .CommandLine .Command ;
28+ import picocli .CommandLine .Option ;
29+ import picocli .CommandLine .ParameterException ;
30+ import picocli .CommandLine .ParseResult ;
31+ import picocli .CommandLine .ScopeType ;
32+ import picocli .CommandLine .Spec ;
3033
3134@ TopCommand
3235@ Command (name = "domino" ,
4649 Run .class ,
4750 Server .class
4851 })
49- public class Domino implements Runnable {
52+ public class Domino {
5053
5154 /**
5255 * Either the Domino Workspace built in API key or a user set key checked in order.
@@ -100,10 +103,12 @@ public static void main(String... args) {
100103 AnsiConsole .systemInstall (); // enable colors on Windows
101104 }
102105
103- final CommandLine commandLine = new CommandLine (new Domino ());
106+ Domino domino = new Domino ();
107+ final CommandLine commandLine = new CommandLine (domino );
104108 commandLine .setCaseInsensitiveEnumValuesAllowed (true );
105109 commandLine .setSubcommandsCaseInsensitive (true );
106110 commandLine .setOptionsCaseInsensitive (true );
111+ commandLine .setExecutionStrategy (domino ::executionStrategy );
107112 commandLine .setExecutionExceptionHandler (new OutputExceptionHandler ());
108113 int exitCode = commandLine .execute (args );
109114
@@ -113,23 +118,21 @@ public static void main(String... args) {
113118 System .exit (exitCode );
114119 }
115120
116- @ Override
117- public void run () {
121+ private int executionStrategy (ParseResult parseResult ) {
118122 if (!isTokenConfigured () && !isKeyConfigured ()) {
119- System .err .println ("Domino access token must be set with -a parameter or DOMINO_API_TOKEN environment variable!" );
120- return ;
123+ throw new ParameterException (spec .commandLine (), "Domino access token must be set with -a parameter or DOMINO_API_TOKEN environment variable!" );
121124 }
122125
123- if (!isTokenConfigured () && isKeyConfigured ()) {
126+ if (isKeyConfigured () && !isTokenConfigured ()) {
127+
124128 System .err .println ("Warning: Domino API Keys are being deprecated. Switch to using Domino service account tokens at your convenience." );
125129 }
126130
127131 if ((StringUtils .isBlank (apiUrl ) || Strings .CI .equals (ENV_API_URL , apiUrl )) && !isProxiable ()) {
128- System .err .println ("Domino API URL must be set with -u parameter or DOMINO_API_URL environment variable!" );
129- return ;
132+ throw new ParameterException (spec .commandLine (), "Domino API URL must be set with -u parameter or DOMINO_API_URL environment variable!" );
130133 }
131- // if the command was invoked without subcommand, show the usage help
132- spec . commandLine ().usage ( System . err );
134+
135+ return new CommandLine . RunLast ().execute ( parseResult ); // default execution strategy
133136 }
134137
135138 /**
0 commit comments