Socket
Socket
Sign inDemoInstall

argi

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    argi

A simple args parser


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Install size
20.1 kB
Created
Weekly downloads
 

Readme

Source

argi Codestyle fyi Build Status Windows Build Status Coverage Status

A simple args parser

Install

$ npm install --save argi

Usage

const argi = require('argi');

// Options
argi.option('name', 'description', { default: 'bob', aliases: 'n', boolean: false, hidden: false });

// Commands
argi.command('sayhi', 'description', { hidden: false });

// Parse argv
const parsed = argi.parse(process.argv.slice(2));

if (parsed.sayhi) {
  console.log(`Hi ${ parsed.name }!`);
} else {
  console.log(args.help());
}

API

argi.options(name, description[, options])

name

Type: string

The option's name.

description

Type: string

What the option does. Will be used for help.

options

Type: object

default

Type: string

The options default value.

aliases

Type: string, array

Alias names for the option.

boolean

Type: boolean Default: false

Specifies whether the option is a boolean(true/false) or a string. If set to true arguments after the option will count as a command or as a separate option.

Example:

...

argi.option('boolean', 'description', { boolean: true });

const parsed = argi.parse(['--boolean', 'value'])
parsed.boolean // => true
parsed._ // => ['value']

...
hidden

Type: boolean Default: false

If option should be displayed in help.

argi.command(name, description[, options])

name

Type: string

The command's name.

description

Type: string

What the command does. Will be used for help.

options

Type: object

hidden

Type: boolean Default: false

If command should be displayed in help.

argi.help()

Returns a help string. Will throw an error if it's called before argi.parse()

argi.parse(argv)

argv

An array of cli options. You should probably set it to process.argv.slice(2)

Returns an object with the option's values and if commands should be executed.

Example:

...

const parsed = argi.parse(['--test', '--opt', 'yes', 'build']);
// => {
// =>   test: true,
// =>   opt: 'yes',
// =>   build: true
// => }

...

License

MIT © Tobias Herber

Keywords

FAQs

Last updated on 24 Aug 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc