77import fi .helsinki .cs .tmc .cli .io .HelpGenerator ;
88import fi .helsinki .cs .tmc .cli .io .Io ;
99import fi .helsinki .cs .tmc .cli .io .ShutdownHandler ;
10- import fi .helsinki .cs .tmc .cli .tmcstuff .WorkDir ;
1110import fi .helsinki .cs .tmc .cli .updater .TmcCliUpdater ;
1211
1312import org .apache .commons .cli .CommandLine ;
@@ -49,6 +48,7 @@ public Application(CliContext context) {
4948
5049 options .addOption ("h" , "help" , false , "Display help information about tmc-cli" );
5150 options .addOption ("v" , "version" , false , "Give the version of the tmc-cli" );
51+ options .addOption ("f" , "force-update" , false , "Force the auto-update" );
5252
5353 //TODO implement the inTests as context.property
5454 if (!context .inTests ()) {
@@ -90,7 +90,11 @@ private String[] parseArgs(String[] args) {
9090 return null ;
9191 }
9292
93- if (line .hasOption ("h" )) {
93+ boolean showHelp = line .hasOption ("h" );
94+ boolean showVersion = line .hasOption ("v" );
95+ boolean forceUpdate = line .hasOption ("f" );
96+
97+ if (showHelp ) {
9498 // don't run the help sub-command with -h switch
9599 if (commandName .equals ("help" )) {
96100 runCommand ("help" , new String [0 ]);
@@ -99,10 +103,14 @@ private String[] parseArgs(String[] args) {
99103 runCommand (commandName , new String []{"-h" });
100104 return null ;
101105 }
102- if (line . hasOption ( "v" ) ) {
106+ if (showVersion ) {
103107 io .println ("TMC-CLI version " + EnvironmentUtil .getVersion ());
104108 return null ;
105109 }
110+ if (forceUpdate ) {
111+ runAutoUpdate ();
112+ return null ;
113+ }
106114 return subArgs .toArray (new String [subArgs .size ()]);
107115 }
108116
@@ -113,12 +121,12 @@ public void printHelp(String description) {
113121 public void run (String [] args ) {
114122 context .setApp (this );
115123
116- if (!context .inTests () && versionCheck ()) {
124+ String [] commandArgs = parseArgs (args );
125+ if (commandArgs == null ) {
117126 return ;
118127 }
119128
120- String [] commandArgs = parseArgs (args );
121- if (commandArgs == null ) {
129+ if (!context .inTests () && versionCheck ()) {
122130 return ;
123131 }
124132
@@ -156,6 +164,12 @@ private boolean versionCheck() {
156164 return false ;
157165 }
158166
167+ return runAutoUpdate ();
168+ }
169+
170+ public boolean runAutoUpdate () {
171+ Map <String , String > properties = context .getProperties ();
172+ Date now = new Date ();
159173 TmcCliUpdater update = new TmcCliUpdater (io , EnvironmentUtil .getVersion (),
160174 EnvironmentUtil .isWindows ());
161175 boolean updated = update .run ();
0 commit comments