Flags for Choices

Flags for Choices

To add an options menu to your choices, you must provide a flags object. If one of the keyboard shortcuts are hit, or the user selects the option, then the flag global will have the matching key from your flags set to true:

let urls = [
"https://scriptkit.com",
"https://egghead.io",
"https://johnlindquist.com",
]
let flags = {
open: {
name: "Open",
shortcut: "cmd+o",
},
copy: {
name: "Copy",
shortcut: "cmd+c",
},
}
let url = await arg(
{ placeholder: `Press 'right' to see menu`, flags },
urls
)
if (flag?.open) {
$`open ${url}`
} else if (flag?.copy) {
copy(url)
} else {
console.log(url)
}

Using the same script above, In the terminal, you would pass an open flag like so:

my-sites --open
Discuss Post