‚̧Native Package Manager

    cleanquirer

    0.1.1¬†‚Äʬ†Public¬†‚Äʬ†Published

    Cleanquirer

    experimental

    Branch : release version npm version

    Build Status Coverage Status

    Dependency Status devDependency Status

    Create a cli tool from a documented javascript API ūüíĽ

    Introduction

    This module provides a way to easily generate node CLI modules, eventually using files documented with documentation.js.

    Get started

    Create and use a simple CLI

    First, implement one or more commands with documentation using the following pattern (one file for each command):

    // path/to/command/file.js
     
    /**
     * @name my-cli-command
     */
    function cliCommand({
        option,
        option2 = 'default-value'
    } = {}){
        // do some asynchronous stuffs
    }
     
    module.exports = cliCommand

    Now, you have to create a cli function using cleanquirer:

    // path/to/cli-function.js
     
    const path = require('path');
     
    const cleanquirer = require('cleanquirer');
     
    module.exports = cleanquirer({
        name: 'cli-name',
        commands: [
            path.join(__dirname, 'path/to/command/file.js'),
            path.join(__dirname, 'path/to/other/command/file.js'),
            path.join(__dirname, 'glob/matching/multiple/commands/file/*.js')
        ]
    })

    You can use the exported function to call methods of the cli api directly in javascript

    // path/to/a/file.js
     
    const myCli = require('path/to/cli-function.js');
     
    myCli(['my-cli-command']).then(()=>{
        // do stuffs after the command was executed
    })

    Then you just have to create a bin file which will do the link between myCli and the terminal input

    path/to/bin/myCli
    #!/usr/bin/env node
     
    'use strict';
     
    require('path/to/cli-function.js')(process.argv.slice(2));

    And fill the bin field in your module package.json

    // package.json
    "bin": {
      "cli-name": "path/to/bin/myCli"
    }
    

    Roadmap

    • command options support (automaticaly deduced from files comments and/or function signature)

    • provide a prompt method (like inquirer) in order to allow easy user interactions

    • automaticaly prompt the missing options when user uses a command

    • help command/flag support

    • options aliases support

    • global options support

    • commands aliases support

    Documentation

    License

    cleanquirer is released under MIT. Copyright (c) 2017-present Alexis Tessier

    Install

    npm i cleanquirer

    DownloadsWeekly Downloads

    3

    Version

    0.1.1

    License

    MIT

    Last publish

    Collaborators

    • alexistessier