Skip to content

Instantly share code, notes, and snippets.

@jdx
Created July 10, 2017 20:39
Show Gist options
  • Save jdx/302fb55816430bb2c2f53c8a7437dc02 to your computer and use it in GitHub Desktop.
Save jdx/302fb55816430bb2c2f53c8a7437dc02 to your computer and use it in GitHub Desktop.
required resuable flag
// flag.js
import { merge, type Flag } from 'cli-engine-command/lib/flags'
type Options = $Shape<Flag<boolean>>
export default function ResetFlag (options: Options = {}, env: typeof process.env = process.env): Flag<string> {
const defaultOptions: Options = {
char: 'r',
parse: (input, cmd) => {
if (options.required) throw new Error('you should have set --reset')
}
}
return merge(defaultOptions, options)
}
// v6 command
class MyCommand extends Command {
static flags = {
reset: flags.reset()
}
async run() {
// guaranteed to have this.flags.reset === true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment