@@ -32,15 +32,16 @@ program.command('license-version')
3232 . action ( async ( ) => {
3333 const client = new LicensingClient ( ) ;
3434 await client . Version ( ) ;
35+ process . exit ( 0 ) ;
3536 } ) ;
3637
3738program . command ( 'activate-license' )
3839 . description ( 'Activate a Unity license.' )
40+ . option ( '-l, --license <license>' , 'License type (personal, professional, floating). Required.' )
3941 . option ( '-e, --email <email>' , 'Email associated with the Unity account. Required when activating a personal or professional license.' )
4042 . option ( '-p, --password <password>' , 'Password for the Unity account. Required when activating a personal or professional license.' )
4143 . option ( '-s, --serial <serial>' , 'License serial number. Required when activating a professional license.' )
42- . option ( '-l, --license <license>' , 'License type (personal, professional, floating).' )
43- . option ( '-c, --config <config>' , 'Path to the configuration file. Required when activating a floating license.' )
44+ . option ( '-c, --config <config>' , 'Path to the configuration file, or base64 encoded JSON string. Required when activating a floating license.' )
4445 . option ( '--verbose' , 'Enable verbose logging.' )
4546 . action ( async ( options ) => {
4647 if ( options . verbose ) {
@@ -53,13 +54,15 @@ program.command('activate-license')
5354 const licenseStr : string = options . license ?. toString ( ) ?. trim ( ) ;
5455
5556 if ( ! licenseStr || licenseStr . length === 0 ) {
56- throw new Error ( 'License type is required. Use -l or --license to specify it.' ) ;
57+ Logger . instance . error ( 'License type is required. Use -l or --license to specify it.' ) ;
58+ process . exit ( 1 ) ;
5759 }
5860
5961 const licenseType : LicenseType = options . license . toLowerCase ( ) as LicenseType ;
6062
6163 if ( ! [ LicenseType . personal , LicenseType . professional , LicenseType . floating ] . includes ( licenseType ) ) {
62- throw new Error ( `Invalid license type: ${ licenseType } ` ) ;
64+ Logger . instance . error ( `Invalid license type: ${ licenseType } ` ) ;
65+ process . exit ( 1 ) ;
6366 }
6467
6568 if ( licenseType !== LicenseType . floating ) {
@@ -83,6 +86,7 @@ program.command('activate-license')
8386 username : options . email ,
8487 password : options . password
8588 } ) ;
89+ process . exit ( 0 ) ;
8690 } ) ;
8791
8892program . command ( 'return-license' )
@@ -100,16 +104,19 @@ program.command('return-license')
100104 const licenseStr : string = options . license ?. toString ( ) ?. trim ( ) ;
101105
102106 if ( ! licenseStr || licenseStr . length === 0 ) {
103- throw new Error ( 'License type is required. Use -l or --license to specify it.' ) ;
107+ Logger . instance . error ( 'License type is required. Use -l or --license to specify it.' ) ;
108+ process . exit ( 1 ) ;
104109 }
105110
106111 const licenseType : LicenseType = licenseStr . toLowerCase ( ) as LicenseType ;
107112
108113 if ( ! [ LicenseType . personal , LicenseType . professional , LicenseType . floating ] . includes ( licenseType ) ) {
109- throw new Error ( `Invalid license type: ${ licenseType } ` ) ;
114+ Logger . instance . error ( `Invalid license type: ${ licenseType } ` ) ;
115+ process . exit ( 1 ) ;
110116 }
111117
112118 await client . Deactivate ( licenseType ) ;
119+ process . exit ( 0 ) ;
113120 } ) ;
114121
115122program . commandsGroup ( 'Unity Hub:' ) ;
@@ -123,6 +130,8 @@ program.command('hub-version')
123130 process . stdout . write ( `${ version } \n` ) ;
124131 } catch ( error ) {
125132 process . stdout . write ( `${ error } \n` ) ;
133+ } finally {
134+ process . exit ( 0 ) ;
126135 }
127136 } ) ;
128137
@@ -148,6 +157,8 @@ program.command('hub-install')
148157 } else {
149158 process . stdout . write ( `${ hubPath } \n` ) ;
150159 }
160+
161+ process . exit ( 0 ) ;
151162 } ) ;
152163
153164program . command ( 'hub-path' )
@@ -163,13 +174,15 @@ program.command('hub-path')
163174 } else {
164175 process . stdout . write ( `${ hub . executable } \n` ) ;
165176 }
177+
178+ process . exit ( 0 ) ;
166179 } ) ;
167180
168181program . command ( 'hub' )
169182 . description ( 'Run commands directly to the Unity Hub. (You need not to pass --headless or -- to this command).' )
183+ . allowUnknownOption ( true )
170184 . argument ( '<args...>' , 'Arguments to pass to the Unity Hub executable.' )
171185 . option ( '--verbose' , 'Enable verbose logging.' )
172- . allowUnknownOption ( true )
173186 . action ( async ( args : string [ ] , options ) => {
174187 if ( options . verbose ) {
175188 Logger . instance . logLevel = LogLevel . DEBUG ;
@@ -179,6 +192,7 @@ program.command('hub')
179192
180193 const unityHub = new UnityHub ( ) ;
181194 await unityHub . Exec ( args , { silent : false , showCommand : Logger . instance . logLevel === LogLevel . DEBUG } ) ;
195+ process . exit ( 0 ) ;
182196 } ) ;
183197
184198program . command ( 'setup-unity' )
@@ -206,7 +220,8 @@ program.command('setup-unity')
206220 }
207221
208222 if ( ! options . unityVersion && ! unityProject ) {
209- throw new Error ( 'You must specify a Unity version or project path with -u, --unity-version, -p, --unity-project.' ) ;
223+ Logger . instance . error ( 'You must specify a Unity version or project path with -u, --unity-version, -p, --unity-project.' ) ;
224+ process . exit ( 1 ) ;
210225 }
211226
212227 const unityVersion = unityProject ?. version ?? new UnityVersion ( options . unityVersion , options . changeset ) ;
@@ -266,6 +281,8 @@ program.command('setup-unity')
266281 }
267282 }
268283 }
284+
285+ process . exit ( 0 ) ;
269286 } ) ;
270287
271288program . command ( 'uninstall-unity' )
@@ -289,6 +306,7 @@ program.command('uninstall-unity')
289306 const unityVersion = new UnityVersion ( unityVersionStr , options . changeset , options . arch ) ;
290307 const unityHub = new UnityHub ( ) ;
291308 const installedEditors = await unityHub . ListInstalledEditors ( ) ;
309+
292310 if ( unityVersion . isLegacy ( ) ) {
293311 const installPath = await unityHub . GetInstallPath ( ) ;
294312 unityEditor = new UnityEditor ( path . join ( installPath , `Unity ${ unityVersion . toString ( ) } ` , 'Unity.exe' ) ) ;
@@ -299,7 +317,8 @@ program.command('uninstall-unity')
299317 const editorPath = options . unityEditor ?. toString ( ) ?. trim ( ) || process . env . UNITY_EDITOR_PATH || undefined ;
300318
301319 if ( ! editorPath || editorPath . length === 0 ) {
302- throw new Error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
320+ Logger . instance . error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
321+ process . exit ( 1 ) ;
303322 }
304323
305324 try {
@@ -332,11 +351,12 @@ program.command('open-project')
332351 }
333352
334353 Logger . instance . debug ( JSON . stringify ( options ) ) ;
335- const projectPath = options . unityProject ?. toString ( ) ?. trim ( ) || process . env . UNITY_PROJECT_PATH || process . cwd ( ) ;
354+ const projectPath = options . unityProject ?. toString ( ) ?. trim ( ) || process . env . UNITY_PROJECT_PATH || undefined ;
336355 const unityProject = await UnityProject . GetProject ( projectPath ) ;
337356
338357 if ( ! unityProject ) {
339- throw new Error ( `The specified path is not a valid Unity project: ${ projectPath } ` ) ;
358+ Logger . instance . error ( `The specified path is not a valid Unity project: ${ projectPath } ` ) ;
359+ process . exit ( 1 ) ;
340360 }
341361
342362 const unityVersion = unityProject ?. version ?? new UnityVersion ( options . unityVersion , options . changeset ) ;
@@ -380,7 +400,8 @@ program.command('run')
380400 const unityProject = await UnityProject . GetProject ( projectPath ) ;
381401
382402 if ( ! unityProject ) {
383- throw new Error ( `The specified path is not a valid Unity project: ${ projectPath } ` ) ;
403+ Logger . instance . error ( `The specified path is not a valid Unity project: ${ projectPath } ` ) ;
404+ process . exit ( 1 ) ;
384405 }
385406
386407 if ( ! unityEditor ) {
@@ -389,7 +410,8 @@ program.command('run')
389410 }
390411
391412 if ( ! unityEditor ) {
392- throw new Error ( 'The Unity Editor path was not specified. Use --unity-editor to specify it or set the UNITY_EDITOR_PATH environment variable.' ) ;
413+ Logger . instance . error ( 'The Unity Editor path was not specified. Use --unity-editor to specify it or set the UNITY_EDITOR_PATH environment variable.' ) ;
414+ process . exit ( 1 ) ;
393415 }
394416
395417 if ( ! args . includes ( '-logFile' ) ) {
@@ -400,6 +422,7 @@ program.command('run')
400422 await unityEditor . Run ( {
401423 args : [ ...args ]
402424 } ) ;
425+ process . exit ( 0 ) ;
403426 } ) ;
404427
405428program . command ( 'list-project-templates' )
@@ -418,7 +441,8 @@ program.command('list-project-templates')
418441 const unityVersionStr = options . unityVersion ?. toString ( ) ?. trim ( ) ;
419442
420443 if ( ! unityVersionStr && ! options . unityEditor ) {
421- throw new Error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
444+ Logger . instance . error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
445+ process . exit ( 1 ) ;
422446 }
423447
424448 let unityEditor : UnityEditor ;
@@ -442,14 +466,13 @@ program.command('list-project-templates')
442466 if ( options . json ) {
443467 process . stdout . write ( `\n${ JSON . stringify ( { templates } ) } \n` ) ;
444468 } else {
445- process . stdout . write ( `Available project templates:\n` ) ;
446- for ( const template of templates ) {
447- process . stdout . write ( ` - ${ path . basename ( template ) } \n` ) ;
448- }
469+ process . stdout . write ( `Available project templates:\n${ templates . map ( t => ` - ${ path . basename ( t ) } ` ) . join ( '\n' ) } \n` ) ;
449470 }
450471 } else {
451472 process . stdout . write ( 'No project templates found for this Unity Editor.\n' ) ;
452473 }
474+
475+ process . exit ( 0 ) ;
453476 } ) ;
454477
455478program . command ( 'create-project' )
@@ -471,7 +494,8 @@ program.command('create-project')
471494 const unityVersionStr = options . unityVersion ?. toString ( ) ?. trim ( ) ;
472495
473496 if ( ! unityVersionStr && ! options . unityEditor ) {
474- throw new Error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
497+ Logger . instance . error ( 'You must specify a Unity version or editor path with -u, --unity-version, -e, --unity-editor.' ) ;
498+ process . exit ( 1 ) ;
475499 }
476500
477501 let unityEditor : UnityEditor ;
@@ -483,7 +507,8 @@ program.command('create-project')
483507 const editorPath = options . unityEditor ?. toString ( ) ?. trim ( ) || process . env . UNITY_EDITOR_PATH ;
484508
485509 if ( ! editorPath || editorPath . length === 0 ) {
486- throw new Error ( 'The Unity Editor path was not specified. Use -e or --unity-editor to specify it, or set the UNITY_EDITOR_PATH environment variable.' ) ;
510+ Logger . instance . error ( 'The Unity Editor path was not specified. Use -e or --unity-editor to specify it, or set the UNITY_EDITOR_PATH environment variable.' ) ;
511+ process . exit ( 1 ) ;
487512 }
488513
489514 unityEditor = new UnityEditor ( editorPath ) ;
@@ -506,7 +531,10 @@ program.command('create-project')
506531
507532 if ( ! unityEditor . version . isLegacy ( ) && options . template && options . template . length > 0 ) {
508533 const templatePath = unityEditor . GetTemplatePath ( options . template ) ;
509- args . push ( '-cloneFromTemplate' , templatePath ) ;
534+
535+ if ( templatePath ) {
536+ args . push ( '-cloneFromTemplate' , templatePath ) ;
537+ }
510538 }
511539
512540 await unityEditor . Run ( { projectPath, args } ) ;
@@ -518,6 +546,8 @@ program.command('create-project')
518546 } else {
519547 process . stdout . write ( `Unity project created at: ${ projectPath } \n` ) ;
520548 }
549+
550+ process . exit ( 0 ) ;
521551 } ) ;
522552
523553program . parse ( process . argv ) ;
0 commit comments