Skip to content

Commit

Permalink
fix: safe guard against no / wrong input
Browse files Browse the repository at this point in the history
This is missing a safe guard against cases where a user inputs a command
that is missing. Currently there is no good way to solve with this
commander.js. We need to implement #10
solve this.
  • Loading branch information
sQVe committed Dec 12, 2018
1 parent e6d1750 commit 7b1f7d9
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ const addCommand = settings =>

const addAction = action => [
'action',
isTest
? // NOTE: Commander.js sadly does not include a way to hook onto given
// actions for integration testing. We solve this by outputting state
// when NODE_ENV is test.
(input, { layout, json }) =>
console.log (JSON.stringify ([action, input, layout, !!json]))
: actions[action],
(input, opts) => {
if (!input) return program.outputHelp ()

return isTest
? // NOTE: Commander.js sadly does not include a way to hook onto given
// actions for integration testing. We solve this by outputting state
// when NODE_ENV is test.
console.log (
JSON.stringify ([action, input, !!opts.cp, !!opts.json, opts.layout])
)
: actions[action] (input, opts)
},
]
const commonOptions = [
['option', '-c, --cp', 'copy code to clipboard', false],
Expand Down Expand Up @@ -71,10 +76,18 @@ program.on ('--help', () =>
[
'',
'Examples:',
' view all',
' search flatten --output json all',
' tag --print ic array',
' v head',
' view head',
'',
' s -j flatten',
' search --json flatten',
'',
' t -l ic array',
' tag --layout ic array',
].join ('\n')
)
)
program.parse (process.argv)
if (process.argv.length <= 2) {
program.outputHelp ()
}

0 comments on commit 7b1f7d9

Please sign in to comment.