UNPKG

1.55 kBMarkdownView Raw
1@oclif/parser
2=============
3
4**This library has been replaced by [@oclif/core](https://github.com/oclif/core) and is now in maintenance mode. We will only consider PRs that address security concerns.**
5
6arg and flag parser for oclif
7
8[![Version](https://img.shields.io/npm/v/@oclif/parser.svg)](https://npmjs.org/package/@oclif/parser)
9[![CircleCI](https://circleci.com/gh/oclif/parser/tree/main.svg?style=svg)](https://circleci.com/gh/oclif/parser/tree/main)
10[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/parser?branch=main&svg=true)](https://ci.appveyor.com/project/heroku/parser/branch/main)
11[![Known Vulnerabilities](https://snyk.io/test/npm/@oclif/parser/badge.svg)](https://snyk.io/test/npm/@oclif/parser)
12[![Downloads/week](https://img.shields.io/npm/dw/@oclif/parser.svg)](https://npmjs.org/package/@oclif/parser)
13[![License](https://img.shields.io/npm/l/@oclif/parser.svg)](https://github.com/oclif/parser/blob/main/package.json)
14
15CLI flag parser.
16
17Usage:
18
19```js
20const CLI = require('cli-flags')
21
22const {flags, args} = CLI.parse({
23 flags: {
24 'output-file': CLI.flags.string({char: 'o'}),
25 force: CLI.flags.boolean({char: 'f'})
26 },
27 args: [
28 {name: 'input', required: true}
29 ]
30})
31
32if (flags.force) {
33 console.log('--force was set')
34}
35
36if (flags['output-file']) {
37 console.log(`output file is: ${flags['output-file']}`)
38}
39
40console.log(`input arg: ${args.input}`)
41
42// $ node example.js -f myinput --output-file=myexample.txt
43// --force was set
44// output file is: myexample.txt
45// input arg: myinput
46```