Skip to content

Commit

Permalink
fix(main): fix can not catch error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
isuke committed Nov 13, 2018
1 parent c2a3991 commit 2b93432
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,35 @@ const customHelp = (program, templateFilePath, definitionsFilePath) => {
//
// Main
//
try {
program
.option('-d, --duet', 'run git-duet mode')
.option('-D, --dry-run', 'run dry-run mode')
.option('-i, --interactive', 'run interactive mode')
.option('-S, --silent', "don't show commit command")
.option('-t, --typo-check', '[Already deleted this function] check spell')
.option('--gen-config', 'generate config files')
.version(version)

if (process.argv.includes('--gen-config')) {
program.parse(process.argv)
genConfig(program, templateFileName, definitionsFileName)
} else {
const projectRoot = getProjectRoot()
const rootPath = projectRoot === '' ? process.env.HOME : projectRoot

const templateFilePath = getFilePath(rootPath, templateFileName)
const definitionsFilePath = getFilePath(rootPath, definitionsFileName)

const template = fs.readFileSync(templateFilePath, 'utf8')
const definitions = loadDefinitions(definitionsFilePath)
const terms = _.keys(definitions)

customHelp(program, templateFilePath, definitionsFilePath)

setOptions(program, definitions, terms).parse(process.argv)

main(program, template, definitions, terms)
}
} catch (e) {
console.error(`${colors.error}${e.message}${colors.reset}`)
e.status ? process.exit(e.status) : process.exit(1)
program
.option('-d, --duet', 'run git-duet mode')
.option('-D, --dry-run', 'run dry-run mode')
.option('-i, --interactive', 'run interactive mode')
.option('-S, --silent', "don't show commit command")
.option('-t, --typo-check', '[Already deleted this function] check spell')
.option('--gen-config', 'generate config files')
.version(version)

if (process.argv.includes('--gen-config')) {
program.parse(process.argv)
genConfig(program, templateFileName, definitionsFileName)
} else {
const projectRoot = getProjectRoot()
const rootPath = projectRoot === '' ? process.env.HOME : projectRoot

const templateFilePath = getFilePath(rootPath, templateFileName)
const definitionsFilePath = getFilePath(rootPath, definitionsFileName)

const template = fs.readFileSync(templateFilePath, 'utf8')
const definitions = loadDefinitions(definitionsFilePath)
const terms = _.keys(definitions)

customHelp(program, templateFilePath, definitionsFilePath)

setOptions(program, definitions, terms).parse(process.argv)

main(program, template, definitions, terms).catch((e) => {
console.error(`${colors.error}${e.message}${colors.reset}`)
e.status ? process.exit(e.status) : process.exit(1)
})
}

0 comments on commit 2b93432

Please sign in to comment.