-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow only valid options for commands (#1467)
* error on invalid options * adding test * adding changeset * fixing tests * bug fix * fixing tests
- Loading branch information
Showing
9 changed files
with
313 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'preact-cli': patch | ||
--- | ||
|
||
Allow only valid options for commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
exports.build = require('./build'); | ||
exports.create = require('./create'); | ||
exports.list = require('./list'); | ||
exports.watch = require('./watch'); | ||
const { command: build, options: buildOptions } = require('./build'); | ||
const { command: create, options: createOptions } = require('./create'); | ||
const list = require('./list'); | ||
const { command: watch, options: watchOptions } = require('./watch'); | ||
|
||
module.exports = { | ||
build, | ||
buildOptions, | ||
create, | ||
createOptions, | ||
list, | ||
watch, | ||
watchOptions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { error } = require('../util'); | ||
|
||
function validateArgs(argv, options, command) { | ||
let normalizedOptions = options.map(option => option.name.split(',')).flat(1); | ||
normalizedOptions = normalizedOptions.map(option => { | ||
option = option.trim(); | ||
if (option.startsWith('--')) { | ||
return option.substr(2); | ||
} else if (option.startsWith('-')) { | ||
return option.substr(1); | ||
} | ||
}); | ||
for (const arg in argv) { | ||
if (arg === '_') { | ||
// ignore this arg | ||
continue; | ||
} | ||
if (!normalizedOptions.includes(arg)) { | ||
error( | ||
`Invalid argument ${arg} passed to ${command}. Please refer to 'preact ${command} --help' for full list of options.\n\n` | ||
); | ||
throw new Error('Invalid argunment found.'); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
validateArgs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.