Skip to content

Commit

Permalink
on error, suggest viewing usage instructions instead of displaying th…
Browse files Browse the repository at this point in the history
…em by default
  • Loading branch information
75lb committed Jun 6, 2021
1 parent e818472 commit 74e1467
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Renamer {
const fileSet = new FileSet()
await fileSet.add(options.files)
if (fileSet.notExisting.length) {
throw new Error(`Files do not exist: ${fileSet.notExisting.join(', ')}`)
throw new Error(`These paths or patterns do not exist: ${fileSet.notExisting.join(', ')}`)
}
const replaceChain = new ReplaceChain()
await replaceChain.loadPlugins(options.chain)
Expand Down
2 changes: 0 additions & 2 deletions lib/cli-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ class CliApp {
this.view.write('complete', stats, this.options)
} catch (err) {
this.halt(err)
this.printUsage(allOptionDefinitions, cliArgs.plugin)
}
}
} catch (err) {
this.halt(err)
this.printUsage()
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/view/default.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DefaultView {

logError (err) {
this.log(chalk.red('ERROR: ' + err.message))
this.log(chalk.red('\nRun `renamer --help` for usage instructions.\n'))
}

logComplete (stats) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli-bad-input.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestView extends DefaultView {
}
}

tom.test('invalid option: exit code set to 1, usage guide displayed, no file renamed', async function () {
tom.test('invalid option: exit code set to 1, usage guide suggested, no file renamed', async function () {
const fixturePath = createFixture(`${testRoot}/${this.index}/one`)
const origCode = process.exitCode
const logs = []
Expand All @@ -43,7 +43,7 @@ tom.test('invalid option: exit code set to 1, usage guide displayed, no file ren
a.deepEqual(fs.existsSync(`${testRoot}/${this.index}/yeah`), false)
a.equal(logs.length, 2)
a.equal(/Unknown option: --broken/.test(logs[0]), true)
a.equal(/For detailed instructions/.test(logs[1]), true)
a.equal(/Run `renamer --help` for usage instructions/.test(logs[1]), true)
})

tom.test('--view: broken plugin', async function () {
Expand Down

0 comments on commit 74e1467

Please sign in to comment.