44import org .fusesource .jansi .Ansi ;
55import org .fusesource .jansi .AnsiConsole ;
66import org .mcphackers .mcp .tasks .info .TaskInfo ;
7+ import org .mcphackers .mcp .tools .Util ;
78import org .mcphackers .mcp .tools .VersionsParser ;
89
10+ import java .io .IOException ;
911import java .nio .file .Files ;
1012import java .nio .file .Paths ;
1113import java .util .*;
@@ -28,7 +30,23 @@ public class MCP {
2830 .fgCyan ().a (" |_| \\ _\\ ___|\\ __|_| \\ ___/" ).fgYellow ().a ("|_| |_|\\ _____|_| " ).a ('\n' )
2931 .fgDefault ();
3032
31- public static void main (String [] args ) {
33+ private static boolean checkIfUpdating (String [] args ) throws IOException {
34+ if (args .length == 2 ) {
35+ if (args [0 ].equals ("update" )) {
36+ Util .runCommand (new String [] {
37+ Util .getJava (),
38+ "-jar" ,
39+ args [1 ]
40+ });
41+ return true ;
42+ }
43+ }
44+ return false ;
45+ }
46+
47+ public static void main (String [] args ) throws Exception {
48+ if (checkIfUpdating (args )) return ;
49+ Files .deleteIfExists (Paths .get (MCPConfig .UPDATE_JAR ));
3250 SelfCommandPrompt .runWithCMD (SelfCommandPrompt .suggestAppId (), "RetroMCP " + VERSION , args );
3351 AnsiConsole .systemInstall ();
3452 logger = new MCPLogger ();
@@ -39,20 +57,19 @@ public static void main(String[] args) {
3957
4058 boolean startedWithNoParams = false ;
4159 boolean exit = false ;
42-
43- if (args .length <= 0 ) {
44- startedWithNoParams = true ;
45- logger .println (logo );
46- }
60+ String version = null ;
4761 if (Files .exists (Paths .get (MCPConfig .VERSION ))) {
4862 try {
4963 VersionsParser .setCurrentVersion (new String (Files .readAllBytes (Paths .get (MCPConfig .VERSION ))));
5064 } catch (Exception e ) {
51- logger . info ( new Ansi ().fgBrightRed ().a ("Unable to get current version!" ).fgDefault ().toString () );
65+ version = new Ansi ().fgBrightRed ().a ("Unable to get current version!" ).fgDefault ().toString ();
5266 }
53- logger . info ( new Ansi ().a ("Current version: " ).fgBrightCyan ().a (VersionsParser .getCurrentVersion ()).fgDefault ().toString () );
67+ version = new Ansi ().a ("Current version: " ).fgBrightCyan ().a (VersionsParser .getCurrentVersion ()).fgDefault ().toString ();
5468 }
5569 if (args .length <= 0 ) {
70+ startedWithNoParams = true ;
71+ logger .println (logo );
72+ if (version != null ) logger .info (version );
5673 logger .println ("Enter a command to execute:" );
5774 }
5875 int executeTimes = 0 ;
@@ -116,7 +133,7 @@ public static void main(String[] args) {
116133 shutdown ();
117134 }
118135
119- private static void setParams (Map <String , Object > parsedArgs , EnumMode mode ) {
136+ private static void setParams (Map <String , Object > parsedArgs , EnumMode mode ) {
120137 for (Map .Entry <String , Object > arg : parsedArgs .entrySet ()) {
121138 Object value = arg .getValue ();
122139 String name = arg .getKey ();
0 commit comments