diff --git a/index.ts b/index.ts index 96661840..cc65e1a1 100755 --- a/index.ts +++ b/index.ts @@ -12,10 +12,12 @@ async function run () { } else { supdock.usage() } + return } if (flags.version || flags.v) { supdock.version() + return } // Fallback to default Docker execution if command is unknown to Supdock diff --git a/src/helpers/logger.ts b/src/helpers/logger.ts index af02bb03..12d919f0 100644 --- a/src/helpers/logger.ts +++ b/src/helpers/logger.ts @@ -28,5 +28,9 @@ export const warn = (msg: string) => { export const error = (msg: string) => { log(chalk.red(msg)) - process.exit(1) + + // Don't exit when testing + if (process.env.NODE_ENV !== 'test') { + process.exit(1) + } } diff --git a/src/index.ts b/src/index.ts index 7c3b46e3..94c3bcc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -67,14 +67,14 @@ export default class Supdock { public usage (command?: string) { if (!command) { const commandNames = Object.keys(this.commands) - logAndForget(generateGeneralDescription(this.commands, commandNames)) + log(generateGeneralDescription(this.commands, commandNames)) } else { this.commandUsage(command) } } public version () { - logAndForget(version) + log(version) } public getCustomCommands () { @@ -87,7 +87,7 @@ export default class Supdock { // When command has custom usage defined log that instead of throwing the unknown command to docker if (usage) { this.spawn('docker', usage.split(' ')) - process.exit(0) + return } // Allow commands to have their own detailed usage information when a complete custom command @@ -110,8 +110,6 @@ export default class Supdock { info(`\n${metadata.extraUsageInfo}`) } } - - process.exit(0) } private executeInParallel (command: string, type: string) { @@ -282,6 +280,12 @@ export default class Supdock { choices, nonFlags ) + + // Unable to determine choice + if (!choice) { + return + } + const id = choice.split('-')[0].trim() // Define custom command logic if needed for specific commands