Skip to content

Commit

Permalink
⚡ Change some of the process.exit behaviours to returns
Browse files Browse the repository at this point in the history
  • Loading branch information
segersniels committed Sep 4, 2019
1 parent a4faa3a commit 2a6d03a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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
Expand All @@ -110,8 +110,6 @@ export default class Supdock {
info(`\n${metadata.extraUsageInfo}`)
}
}

process.exit(0)
}

private executeInParallel (command: string, type: string) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a6d03a

Please sign in to comment.