More intuitive story picker

This commit is contained in:
Dragon Fire
2021-03-10 20:37:08 -05:00
parent 3d3234600e
commit 92876125ca
+18 -3
View File
@@ -26,10 +26,25 @@ module.exports = class KinoCommand extends Command {
args: [
{
key: 'story',
prompt: `What story do you want to read? Either ${list(stories, 'or')}.`,
prompt: stripIndents`
What story do you want to read? You can type the number or the name.
\`\`\`
${stories.map((story, i) => `${i.toString().padStart(2, '0')}. ${story}`).join('\n')}
\`\`\`
`,
type: 'string',
oneOf: stories.map(story => story.toLowerCase()),
parse: story => story.toLowerCase()
validate: story => {
if (stories.some(story => story.toLowerCase() === story.toLowerCase())) return true;
const num = Number.parseInt(story, 10);
return Boolean(stories[num]);
},
parse: story => {
if (stories.some(story => story.toLowerCase() === story.toLowerCase())) {
return story.toLowerCase();
}
const num = Number.parseInt(story, 10);
return stories[num];
}
}
]
});