@@ -71,6 +71,26 @@ const securityOptions = {
7171
7272let yargsInstance ;
7373
74+ function isPromptInterrupted ( error ) {
75+ return error ?. name === 'ExitPromptError' ||
76+ error ?. name === 'AbortPromptError' ||
77+ error ?. message ?. includes ( 'User force closed' ) ;
78+ }
79+
80+ function runSecurityAction ( cli , action ) {
81+ return Promise . resolve ( action ) . catch ( ( error ) => {
82+ if ( ! isPromptInterrupted ( error ) ) {
83+ throw error ;
84+ }
85+
86+ if ( cli . spinner . isSpinning ) {
87+ cli . spinner . stop ( ) ;
88+ }
89+ cli . warn ( 'Aborted.' ) ;
90+ cli . setExitCode ( 1 ) ;
91+ } ) ;
92+ }
93+
7494export function builder ( yargs ) {
7595 yargsInstance = yargs ;
7696 return yargs . options ( securityOptions )
@@ -117,40 +137,36 @@ export function builder(yargs) {
117137export function handler ( argv ) {
118138 const logStream = process . stdout . isTTY ? process . stdout : process . stderr ;
119139 const cli = new CLI ( logStream ) ;
140+ let action ;
120141
121142 if ( argv . start ) {
122- return startSecurityRelease ( cli , argv ) ;
123- }
124- if ( argv [ 'apply-patches' ] ) {
125- return applySecurityPatches ( cli , argv ) ;
143+ action = startSecurityRelease ( cli , argv ) ;
144+ } else if ( argv [ 'apply-patches' ] ) {
145+ action = applySecurityPatches ( cli , argv ) ;
146+ } else if ( argv . sync ) {
147+ action = syncSecurityRelease ( cli , argv ) ;
148+ } else if ( argv [ 'update-date' ] ) {
149+ action = updateReleaseDate ( cli , argv ) ;
150+ } else if ( argv [ 'pre-release' ] ) {
151+ action = createPreRelease ( cli , argv ) ;
152+ } else if ( argv [ 'add-report' ] ) {
153+ action = addReport ( cli , argv ) ;
154+ } else if ( argv [ 'remove-report' ] ) {
155+ action = removeReport ( cli , argv ) ;
156+ } else if ( argv [ 'notify-pre-release' ] ) {
157+ action = notifyPreRelease ( cli , argv ) ;
158+ } else if ( argv [ 'request-cve' ] ) {
159+ action = requestCVEs ( cli , argv ) ;
160+ } else if ( argv [ 'post-release' ] ) {
161+ action = createPostRelease ( cli , argv ) ;
162+ } else if ( argv . cleanup ) {
163+ action = cleanupSecurityRelease ( cli , argv ) ;
126164 }
127- if ( argv . sync ) {
128- return syncSecurityRelease ( cli , argv ) ;
129- }
130- if ( argv [ 'update-date' ] ) {
131- return updateReleaseDate ( cli , argv ) ;
132- }
133- if ( argv [ 'pre-release' ] ) {
134- return createPreRelease ( cli , argv ) ;
135- }
136- if ( argv [ 'add-report' ] ) {
137- return addReport ( cli , argv ) ;
138- }
139- if ( argv [ 'remove-report' ] ) {
140- return removeReport ( cli , argv ) ;
141- }
142- if ( argv [ 'notify-pre-release' ] ) {
143- return notifyPreRelease ( cli , argv ) ;
144- }
145- if ( argv [ 'request-cve' ] ) {
146- return requestCVEs ( cli , argv ) ;
147- }
148- if ( argv [ 'post-release' ] ) {
149- return createPostRelease ( cli , argv ) ;
150- }
151- if ( argv . cleanup ) {
152- return cleanupSecurityRelease ( cli , argv ) ;
165+
166+ if ( action ) {
167+ return runSecurityAction ( cli , action ) ;
153168 }
169+
154170 yargsInstance . showHelp ( ) ;
155171}
156172
0 commit comments