Created
July 10, 2017 20:39
-
-
Save jdx/302fb55816430bb2c2f53c8a7437dc02 to your computer and use it in GitHub Desktop.
required resuable flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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