Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@oclif/parser
Advanced tools
@oclif/parser is a command-line argument parser designed for use with the Oclif framework. It helps in parsing command-line arguments, flags, and options in a structured and efficient manner.
Parsing Arguments
This feature allows you to parse positional arguments from the command line. The code sample demonstrates how to define and parse two positional arguments.
const { parse } = require('@oclif/parser');
const argv = ['arg1', 'arg2'];
const options = { args: [{ name: 'firstArg' }, { name: 'secondArg' }] };
const result = parse(argv, options);
console.log(result.args); // { firstArg: 'arg1', secondArg: 'arg2' }
Parsing Flags
This feature allows you to parse flags from the command line. The code sample demonstrates how to define and parse two string flags.
const { parse } = require('@oclif/parser');
const argv = ['--flag1', 'value1', '--flag2', 'value2'];
const options = { flags: { flag1: { type: 'string' }, flag2: { type: 'string' } } };
const result = parse(argv, options);
console.log(result.flags); // { flag1: 'value1', flag2: 'value2' }
Parsing Boolean Flags
This feature allows you to parse boolean flags from the command line. The code sample demonstrates how to define and parse two boolean flags.
const { parse } = require('@oclif/parser');
const argv = ['--flag1', '--no-flag2'];
const options = { flags: { flag1: { type: 'boolean' }, flag2: { type: 'boolean' } } };
const result = parse(argv, options);
console.log(result.flags); // { flag1: true, flag2: false }
Parsing Options with Default Values
This feature allows you to define default values for flags. The code sample demonstrates how to set and retrieve a default value for a flag.
const { parse } = require('@oclif/parser');
const argv = [];
const options = { flags: { flag1: { type: 'string', default: 'defaultValue' } } };
const result = parse(argv, options);
console.log(result.flags); // { flag1: 'defaultValue' }
Yargs is a popular command-line argument parser that provides a rich set of features for parsing arguments, flags, and options. It offers a more extensive API compared to @oclif/parser and is widely used in the Node.js community.
Commander is another widely-used command-line argument parser that provides a simple and intuitive API for defining commands, arguments, and options. It is known for its ease of use and flexibility, making it a good alternative to @oclif/parser.
Minimist is a lightweight command-line argument parser that focuses on simplicity and minimalism. It is suitable for projects that require basic argument parsing without the overhead of more feature-rich libraries like @oclif/parser.
This library has been replaced by @oclif/core and is now in maintenance mode. We will only consider PRs that address security concerns.
arg and flag parser for oclif
CLI flag parser.
Usage:
const CLI = require('cli-flags')
const {flags, args} = CLI.parse({
flags: {
'output-file': CLI.flags.string({char: 'o'}),
force: CLI.flags.boolean({char: 'f'})
},
args: [
{name: 'input', required: true}
]
})
if (flags.force) {
console.log('--force was set')
}
if (flags['output-file']) {
console.log(`output file is: ${flags['output-file']}`)
}
console.log(`input arg: ${args.input}`)
// $ node example.js -f myinput --output-file=myexample.txt
// --force was set
// output file is: myexample.txt
// input arg: myinput
FAQs
arg and flag parser for oclif
The npm package @oclif/parser receives a total of 462,112 weekly downloads. As such, @oclif/parser popularity was classified as popular.
We found that @oclif/parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.