@@ -28,10 +28,6 @@ async function main(args: string[]): Promise<number> {
2828 // parse options using mri or github actions
2929 const opts = parseArgs ( args )
3030
31- const installSetupCppPromise = opts [ "setup-cpp" ]
32- ? installSetupCpp ( packageJson . version , opts [ "node-package-manager" ] )
33- : Promise . resolve ( )
34-
3531 // print help
3632 if ( opts . help ) {
3733 printHelp ( )
@@ -129,13 +125,20 @@ async function main(args: string[]): Promise<number> {
129125
130126 await finalizeRC ( rcOptions )
131127
132- if ( successMessages . length === 0 && errorMessages . length === 0 ) {
133- if ( ! opts . version && ! opts . help ) {
134- info ( "setup-cpp was called without any arguments. Nothing to do." )
135- }
136- return 0
128+ const noTool = successMessages . length === 0 && errorMessages . length === 0
129+
130+ // if setup-cpp option is not passed, install setup-cpp by default unless only help or version is passed
131+ // So that --help and --version are immutable
132+ if ( opts [ "setup-cpp" ] === undefined ) {
133+ opts [ "setup-cpp" ] = ! ( noTool && ( opts . version || opts . help ) )
137134 }
138135
136+ const installSetupCppPromise = opts [ "setup-cpp" ]
137+ ? installSetupCpp ( packageJson . version , opts [ "node-package-manager" ] )
138+ : Promise . resolve ( )
139+
140+ await Promise . all ( [ checkUpdatePromise , installSetupCppPromise ] )
141+
139142 // report the messages in the end
140143 for ( const tool of successMessages ) {
141144 success ( tool )
@@ -144,27 +147,26 @@ async function main(args: string[]): Promise<number> {
144147 error ( tool )
145148 }
146149
147- info ( "setup-cpp finished" )
148-
149- if ( ! GITHUB_ACTIONS ) {
150- switch ( process . platform ) {
151- case "win32" : {
152- warning ( "Run `RefreshEnv.cmd` or restart your shell to update the environment." )
153- break
154- }
155- case "linux" :
156- case "darwin" : {
157- warning ( "Run `source ~/.cpprc` or restart your shell to update the environment." )
158- break
159- }
160- default : {
161- // nothing
150+ if ( successMessages . length !== 0 || errorMessages . length !== 0 ) {
151+ info ( "setup-cpp finished" )
152+
153+ if ( ! GITHUB_ACTIONS ) {
154+ switch ( process . platform ) {
155+ case "win32" : {
156+ warning ( "Run `RefreshEnv.cmd` or restart your shell to update the environment." )
157+ break
158+ }
159+ case "linux" :
160+ case "darwin" : {
161+ warning ( "Run `source ~/.cpprc` or restart your shell to update the environment." )
162+ break
163+ }
164+ default : {
165+ // nothing
166+ }
162167 }
163168 }
164169 }
165-
166- await Promise . all ( [ checkUpdatePromise , installSetupCppPromise ] )
167-
168170 return errorMessages . length === 0 ? 0 : 1 // exit with non-zero if any error message
169171}
170172
0 commit comments