项目作者: GCSBOSS

项目描述 :
A complete library to develop complete CLI programs.
高级语言: JavaScript
项目地址: git://github.com/GCSBOSS/eclipt.git
创建时间: 2019-07-15T16:42:15Z
项目社区:https://github.com/GCSBOSS/eclipt

开源协议:MIT License

下载


Eclipt

A complete library to quickly develop CLI programs. Check out the features:

  • Process ARGV
  • Custom args array
  • Shorthand options (Eg.: -f, -g)
  • Array options (Eg.: -a foo -a bar)
  • Default values for options
  • Flag options (that don’t receive any value)
  • Grouped flag shorthands (Eg.: -abc)
  • Commands
  • Help flag and output
  • Version flag to execute custom version output
  • Callback for commands
  • Read modules in a directory as commands

Get Started

Install with: npm i -P eclipt

  1. const Eclipt = require('eclipt');
  2. // The first temp session is started automatically here,
  3. // A diretory will be creted inside your OS's temp dir.
  4. let cli = new Eclipt(
  5. 'my-cli-tool', // your tool's command name
  6. { // Available options object
  7. 'opt-1': [ false, 'A cool options', 'string' ], // A regular option with a value
  8. 'flag-1': [ false, 'A cool flag' ], // An option that doesn't receive a value
  9. 'flag-2': [ 'f', 'A flag with a shorthand notation' ], // You may use -f
  10. 'opt-2': [ false , 'An option with a default value', 'string', 'my-default' ]
  11. }
  12. );
  13. // Read process argv and generate the cli data.
  14. let input = cli.execute();
  15. console.log(input);

Reporting Bugs

If you have found any problems with this module, please:

  1. Open an issue.
  2. Describe what happened and how.
  3. Also in the issue text, reference the label ~bug.

We will make sure to take a look when time allows us.

Proposing Features

If you wish to get that awesome feature or have some advice for us, please:

  1. Open an issue.
  2. Describe your ideas.
  3. Also in the issue text, reference the label ~proposal.

Contributing

If you have spotted any enhancements to be made and is willing to get your hands
dirty about it, fork us and
submit your merge request
so we can collaborate effectively.

Reference

Options Object

An object containing CLI options definition. Each key in the object is the name
of an option and has assigned to it an array with the following data:

  1. string: [ // Option name
  2. false || character // Define a property shorthand form if needed.
  3. string // Describes the option (used in help output).
  4. null || string // Name of the expected option value. Leave it blank to define a flag.
  5. null || string // A default value for the option.
  6. ]

Constructor

To create a new CLI, use the Eclipt constructor with the following arguments:

  1. let cli = new Eclipt(
  2. 'my-tool', // Your tool's command name
  3. options, // The available options object
  4. settings // General settings for your CLI
  5. );

These are the settings supported by the constructor:

  1. {
  2. expectedArgs: array, // Names to describe the expect positional arguments
  3. noArgs: boolean, // Whether positional arguments are supported or not
  4. requireCommand: boolean, // Whether a command is required or not
  5. getVersion: aFunction, // Function that retrieves the version for your tool
  6. onOutput: aFunction // To be executed whenever the cli means to output. Ex.: help or version output. Defaults to `console.log`
  7. }

Commands

You can add commands to your tool with cli.setCommand as follows:

  1. cli.setCommand(name, { // The command name and settings object
  2. expectedArgs: array, // Names to describe the expect positional arguments
  3. options: options, // The options object for the command
  4. summary: string, // A brief explanation of the command
  5. callback: aFunction, // Function to be executed if the command is called
  6. noArgs: boolean // Whether positional arguments are supported or not
  7. });