Skip to content

Commit

Permalink
Add check for validity of awaitOptions #11
Browse files Browse the repository at this point in the history
  • Loading branch information
tshino committed Dec 1, 2021
1 parent 7e1a3a8 commit a2a1d5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions generator/gen_keymap_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ function makeWrapper(keybinding) {
return wrapped;
}

function checkAwaitOptions(awaitOptions) {
for (const awaitOption of awaitOptions.values()) {
if (!genWrapperUtil.isValidAwaitOption(awaitOption)) {
console.error('Error: Invalid awaitOption found:', awaitOption);
process.exit(1);
}
}
}

function resolveWildcardInAwaitOptions(awaitOptions, baseKeybindings) {
const newAwaitOptions = new Map;
for (const [ command, awaitOption ] of awaitOptions) {
Expand Down Expand Up @@ -64,6 +73,7 @@ async function makeKeymapWrapper(configPath) {

const rawAwaitOptions = new Map(config['awaitOptions'] || []);
const awaitOptions = resolveWildcardInAwaitOptions(rawAwaitOptions, baseKeybindings);
checkAwaitOptions(awaitOptions);

const wrappers = baseKeybindings.map(
keybinding => {
Expand Down
10 changes: 10 additions & 0 deletions generator/gen_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ function makeWrapper(keybinding) {
return wrapped;
}

function checkAwaitOptions(awaitOptions) {
for (const awaitOption of awaitOptions.values()) {
if (!genWrapperUtil.isValidAwaitOption(awaitOption)) {
console.error('Invalid awaitOption found:', awaitOption);
process.exit(1);
}
}
}

async function main() {
const packageJson = await genWrapperUtil.readJSON(PackageJsonPath);
const config = await genWrapperUtil.readJSON(ConfigPath);

const exclusion = new Set(config['exclusion'] || []);
const awaitOptions = new Map(config['awaitOptions'] || []);
checkAwaitOptions(awaitOptions);

const baseKeybindings = await genWrapperUtil.loadBaseKeybindings(config['baseKeybindings'] || []);

Expand Down

0 comments on commit a2a1d5e

Please sign in to comment.