Skip to content

Instantly share code, notes, and snippets.

@MarcoNicolodi
Last active January 27, 2019 14:18
Show Gist options
  • Save MarcoNicolodi/9674d2ce9c2e13cea56e3bb2731ca1e5 to your computer and use it in GitHub Desktop.
Save MarcoNicolodi/9674d2ce9c2e13cea56e3bb2731ca1e5 to your computer and use it in GitHub Desktop.
const chooseFile = async ({ directory, message, matching }) => {
let candidateFiles
if (matching) {
candidateFiles = await filesystem.find(directory, { matching })
} else {
candidateFiles = await filesystem.list(directory)
}
const promptConfig = {
name: 'chosenFile',
message,
choices: ['all', prompt.separator(), ...candidateFiles]
}
const { chosenFile } = await prompt.ask(promptConfig)
return chosenFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment