New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

promisify-cli

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promisify-cli

Promsifiy-cli is just a cli parser following *nix common line arguments conventions, used by promising way.

latest
Source
npmnpm
Version
3.0.9
Version published
Maintainers
1
Created
Source

promisify-cli

promsifiy-cli is just a cli parser following *nix common line arguments conventions, used by promising way. but it is different.

CLI is just a piece of program, we can just think of it as a function, function requires input and give out results. that's all.

promisify-cli is trying to make cli more intuitive, using it just like invoking a function.

promsifiy-cli converts all command line flags switches and arguments into function params and options.

You can use it building efficient cli tools.

Usage

CLI Files

/*
In package.json adding a new Field `cli`
*/

//WARNING: '-h', '--help', '-v', '--version' are preserved. They are used to print out  Usage or Version information.
{
 ......
  cli:[{
      "flag": "-p"
      //or "flag": "-p --port"              specify multiple flags, short/long flags
      //or "flag": "-p, --port <port>"      indicats *required* param
      //or "flag": "-p --port [port]"       indicats [optional] param
      //"name": "alias name of port"        explicitly to customize its name
      //"required" : true / false           explicitly to specify whether it's optional or must required
      //"value": "defaultValue"             explicitly assign a default value
      //"desc": "description message"       descriptin message
  },
    {
      "flag": "--host"
  }]
......
}

/*

./index.js

*/

var cli = require('../promisify-cli');

//eg cli: startserver -p 80 --host 192.168.28.3 ./www

cli()
  .then(function (cli) {
    console.log('data->', cli.params, cli.options);

    /*  params
      [
        './www'
      ]
    */

    /*  options
    {
      p: '80',
      host: '192.168.28.3'
    }
    */
  }
  })
  .catch(function (e) {
    console.error('catch->', e.message);
  })

API

WARNING: -h, --help, -v, --version are preserved. They are used to print out Help,Usage,Version information.

  • cli([flags[,options]]) function get cli object

    • [flags]

      eg: ['-p',80,'--host','localhost'] to test you  funcationality. 		default get from `process.argv`   automatically. you don't need 		to specify it probably.
      
    • [options] * enableUnkownOptions if it allows unknown options from command line.

  • cli.params [] parsed arguments from command line

  • cli.options {} parsed flags from command line

  • cli.help function print out all usage and help information and exit.

Inspired

specially thanks to commander

Good Library Companions

Keywords

cli

FAQs

Package last updated on 13 Jul 2016

Did you know?

Socket

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