Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
command-line-application
Advanced tools
A helpful wrapper around command-line-args and command-line-usage
A helpful wrapper around command-line-args and command-line-usage.
--help
flagcommand-line-application
commandsyarn add command-line-application
# or
npm i --save command-line-application
import { app, Command } from 'command-line-application';
const echo: Command = {
name: 'echo',
description: 'Print a string to the terminal',
examples: ['echo foo', 'echo "Intense message"'],
require: ['value'],
options: [
{
name: 'value',
type: String,
defaultOption: true,
description: 'The value to print'
}
]
};
const args = app(echo);
// $ echo foo
console.log(args);
// output: { value: "foo" }
import app, { Command } from 'command-line-application';
const echo: Command = {
examples: [{ example: 'echo foo', desc: 'The default use case' }],
...
};
You can even nest multi-commands!
import app, { Command } from 'command-line-application';
const test: Command = { ... };
const lint: Command = { ... };
const scripts: MultiCommand = {
name: 'scripts',
descriptions: 'my tools',
commands: [test, lint]
};
const args = app(scripts);
// $ scripts test --fix
console.log(args);
// output: { _command: 'test', fix: true }
Add additional docs to your commands with Footers.
const echo: Command = {
name: 'echo',
description: 'Print a string to the terminal',
examples: ['echo foo', 'echo "Intense message"'],
options: [
{
name: 'value',
type: String,
defaultOption: true,
description: 'The value to print'
}
],
footer: 'Only run this if you really need to',
// or
footer: {
header: 'Additional Info',
content: 'Only run this if you really need to'
},
// or
footer: [
{
header: 'Additional Info',
content: 'Only run this if you really need to'
}
]
};
To display code in a footer set code
to true.
const echo: Command = {
name: 'echo',
description: 'Print a string to the terminal',
examples: ['echo foo', 'echo "Intense message"'],
options: [
{
name: 'value',
type: String,
defaultOption: true,
description: 'The value to print'
}
],
footer: {
header: 'Additional Info',
code: true,
content: 'function foo (){\n return 1;\n}'
}
};
To require on of multiple flags simply make on of the items in the required array an array of n
options.
const echo: Command = {
name: 'one-or-another',
description: "Errors if one of the flags isn't provided",
examples: ['one-or-another --a', 'one-or-another --b'],
required: [['a', 'b']],
options: [
{
name: 'a',
type: Boolean,
description: 'One options'
},
{
name: 'b',
type: Boolean,
description: 'another option'
}
]
};
Provide argv
manually.
const args = app(echo, { argv: ['--help'] });
Whether to show the help dialog. Defaults to true
const args = app(echo, { showHelp: false });
Whether to camelCase the parsed options. Defaults to true
const args = app(echo, { camelCase: false });
Configure how command-line-application
reports errors.
error
FAQs
A helpful wrapper around command-line-args and command-line-usage
The npm package command-line-application receives a total of 35,158 weekly downloads. As such, command-line-application popularity was classified as popular.
We found that command-line-application demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.