77
88import io .jooby .internal .cli .CommandContextImpl ;
99import io .jooby .internal .cli .JLineCompleter ;
10- import io .jooby .internal .cli .VersionProvider ;
1110import org .jline .reader .EndOfFileException ;
1211import org .jline .reader .LineReader ;
1312import org .jline .reader .LineReaderBuilder ;
1615import org .jline .reader .impl .DefaultParser ;
1716import org .jline .terminal .Terminal ;
1817import org .jline .terminal .TerminalBuilder ;
19- import org .json .JSONArray ;
20- import org .json .JSONObject ;
21- import org .json .JSONTokener ;
2218import picocli .CommandLine ;
2319
2420import javax .annotation .Nonnull ;
2521import java .io .IOException ;
26- import java .io .InputStream ;
27- import java .net .URI ;
28- import java .net .URL ;
29- import java .net .URLConnection ;
3022import java .util .List ;
3123import java .util .Objects ;
32- import java .util .Optional ;
3324import java .util .stream .Collectors ;
3425
3526/**
5041 */
5142@ CommandLine .Command (
5243 name = "jooby" ,
53- versionProvider = VersionProvider .class ,
44+ versionProvider = Version .class ,
5445 mixinStandardHelpOptions = true ,
5546 version = "Print version information"
5647)
5748public class Cli extends Cmd {
58- public static String version ;
59-
6049 /** Command line specification. */
6150 private @ CommandLine .Spec CommandLine .Model .CommandSpec spec ;
6251
@@ -76,7 +65,8 @@ public class Cli extends Cmd {
7665 } else if ("-V" .equalsIgnoreCase (arg ) || "--version" .equals (arg )) {
7766 ctx .println (ctx .getVersion ());
7867 } else {
79- ctx .println ("Unknown command or option(s): " + args .stream ().collect (Collectors .joining (" " )));
68+ ctx .println (
69+ "Unknown command or option(s): " + args .stream ().collect (Collectors .joining (" " )));
8070 }
8171 }
8272 }
@@ -88,7 +78,6 @@ public class Cli extends Cmd {
8878 * @throws IOException If something goes wrong.
8979 */
9080 public static void main (String [] args ) throws IOException {
91- version = checkVersion ();
9281 // set up the completion
9382 Cli jooby = new Cli ();
9483 CommandLine cmd = new CommandLine (jooby )
@@ -103,7 +92,7 @@ public static void main(String[] args) throws IOException {
10392 .parser (new DefaultParser ())
10493 .build ();
10594
106- CommandContextImpl context = new CommandContextImpl (reader , version );
95+ CommandContextImpl context = new CommandContextImpl (reader , Version . VERSION );
10796 jooby .setContext (context );
10897 cmd .getSubcommands ().values ().stream ()
10998 .map (CommandLine ::getCommand )
@@ -131,25 +120,4 @@ public static void main(String[] args) throws IOException {
131120 }
132121 }
133122 }
134-
135- private static String checkVersion () {
136- try {
137- URL url = URI
138- .create ("http://search.maven.org/solrsearch/select?q=+g:io.jooby+a:jooby&start=0&rows=1" )
139- .toURL ();
140- URLConnection connection = url .openConnection ();
141- try (InputStream in = connection .getInputStream ()) {
142- JSONObject json = new JSONObject (new JSONTokener (in ));
143- JSONObject response = json .getJSONObject ("response" );
144- JSONArray docs = response .getJSONArray ("docs" );
145- JSONObject jooby = docs .getJSONObject (0 );
146- return jooby .getString ("latestVersion" );
147- }
148- } catch (Exception x ) {
149- return Optional .ofNullable (VersionProvider .class .getPackage ())
150- .map (Package ::getImplementationVersion )
151- .filter (Objects ::nonNull )
152- .orElse ("2.0.5" );
153- }
154- }
155123}
0 commit comments