UNPKG

1.59 kBMarkdownView Raw
1@oclif/parser
2=============
3
4arg and flag parser for oclif
5
6[![Version](https://img.shields.io/npm/v/@oclif/parser.svg)](https://npmjs.org/package/@oclif/parser)
7[![CircleCI](https://circleci.com/gh/oclif/parser/tree/master.svg?style=svg)](https://circleci.com/gh/oclif/parser/tree/master)
8[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/parser?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/parser/branch/master)
9[![Codecov](https://codecov.io/gh/oclif/parser/branch/master/graph/badge.svg)](https://codecov.io/gh/oclif/parser)
10[![Greenkeeper](https://badges.greenkeeper.io/oclif/parser.svg)](https://greenkeeper.io/)
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/master/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```