Skip to content

Commit

Permalink
Improve options validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 10, 2019
1 parent 6c1ac19 commit 5962093
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
26 changes: 7 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"execa": "sindresorhus/execa#659f4444795c8c20c5b4ef61c8b9d744136604c0",
"fancy-log": "^1.3.3",
"is-ci": "^2.0.0",
"jest-validate": "^24.8.0",
"plugin-error": "^1.0.1",
"rename-fn": "^1.0.0",
"through2-concurrent": "^2.0.0"
Expand Down
19 changes: 15 additions & 4 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { validate } from 'jest-validate'
import isCi from 'is-ci'

import { pickBy } from './utils.js'

// Parse main arguments and options
// TODO: validate options (including that `input` is a string)
export const parseOpts = function(opts) {
const optsA = { ...DEFAULT_OPTS, ...opts }
const optsB = addStdio({ opts: optsA })
return optsB
export const parseOpts = function(opts = {}) {
const optsA = pickBy(opts, value => value !== undefined)

validate(optsA, { exampleConfig: EXAMPLE_OPTS })

const optsB = { ...DEFAULT_OPTS, ...optsA }
const optsC = addStdio({ opts: optsB })
return optsC
}

const DEFAULT_OPTS = {
Expand All @@ -14,6 +21,10 @@ const DEFAULT_OPTS = {
echo: isCi,
}

const EXAMPLE_OPTS = {
...DEFAULT_OPTS,
}

// Default to printing shell output to console.
const addStdio = function({ opts, opts: { stdio } }) {
// `execa` does not allow mixing `stdio` and `stdout|stderr` options
Expand Down

0 comments on commit 5962093

Please sign in to comment.