Skip to content

Latest commit

 

History

History
175 lines (118 loc) · 4.22 KB

README.md

File metadata and controls

175 lines (118 loc) · 4.22 KB

clito

Simple and well written command line applications helper

NPM version Build Status Coverage percentage Project License

What is clito?

Clito, pronounced as in "clitoris", stands for cli-tools and it's a well written command line application helper. It will become your best friend when dealing with cli applications, once you start play with it you will like it more than any other tool. 😏

southpark-chef

Oops.. move along children, you are holding up the line, let see some features now..

Features

  • Parses arguments respecting types
  • Boolean defaults to false
  • Support required options
  • Support multiple option arguments
  • Support for option value validation
  • Negates flags when using the --no- prefix
  • Outputs version when --version
  • Build help string from options when called with --help
  • Customizable help usage and command examples

Getting started

Install the module using your favourite package manager:

npm install clito

Load it in your application code and set it up:

#!/usr/bin/env node

const clito = require('clito');
const cli = clito({
  usage: 'askme <question>',
  flags: {
    person: {
      type: 'string',
      alias: 'p',
      default: 'chef'
    }
  },
  examples: [
    'askme -p "ghandi" "Do you ever got angry?"'
  ]
})

const {input, flags} = cli
const [question] = input
if (!question || question === '') {
  console.error('You must ask a question first!');
  process.exit(1);
}

if (flags.person === 'chef') {
  console.log('> You gotta find the clitoris children.');
} else {
  // evaluate question and answer it
}

Than run it with some input and options:

$ node ./index.js "How do you make a girl love you more than other people?"
> You gotta find the clitoris children.

Options

The module can accept various options to customize the behavior or help string output.

flags

Type: Object
Required: true

An object of name paired flags that are going to be used as command options and parsed.

A flag itself it's an object than can take various properties to describe how the flag should be parsed and outputted in help message:

  • type: The flag type that should be returned from parsing (this field is required)
  • alias: An alias for the flag (dashes are added automatically)
  • description: The flag description used in the help message
  • default: The flag default value in case not specified
  • validation: A validation function for the flag parsed value
  • required: Identify the flag as required, will throw an error if flag is missing
  • multiple: specify that the flag accept multiple arguments and should be parsed as array

Example flag:

{
  foo: {
    type: 'string',
    alias: 'f',
    description: 'A foo option',
    default: 'bar',
    validation: (v) => true,
    required: false,
    multiple: false
  }
}

banner

Type: String

Add a custom banner string to be printed on top of --help message.

usage

Type: String
Default: $ {pkg.name} <input>

Set a custom usage string to be used in --help message.

examples

Type: String, String[]

Add custom command usage examples to be appended on bottom of --help message.

indentation

Type: Number
Default: 0

Set the indentation size used in the built-in help message.

showVersion

Type: Boolean
Default: true

Shows the command version when called with --version.

showHelp

Type: Boolean
Default: true

Shows the built-in command help when called with --help.


License

This package is under MIT license and its made with love by Filippo Conti