Skip to content
Simple, Express-style CLI framework for Node.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
.gitignore
DOCUMENTATION.md Fix DOCUMENTATION.md formatting May 21, 2019
LICENSE
README.md
_config.yml Set theme jekyll-theme-cayman Jan 25, 2019
jest.config.js
kuman.ts Fix formatting in api docs May 10, 2019
package.json
tsconfig.json
yarn.lock

README.md

Kuman (Alpha)

Simple, Express-style CLI framework for Node. Create CLI programs written in Typescript or in Javascript with no additional dependencies.

Install

NPM

$ npm install --save kuman@0.0.6

Yarn

$ yarn add kuman@0.0.6

Usage

  • Import first the module
// For Typescript
import { CLI } from "kuman";
const cli = CLI();

// For NodeJS
const kuman = require("kuman/dist/kuman");
const cli = kuman.CLI();
  • Start using it by adding commands and options.
// Adds "yolo" option
cli.option("yolo", () => {
    console.log("You only live once.");
}, {
    description: "Prints the meaning of YOLO.",
    asCommand: true // treats the option as a command.
})

// Adds "name" option
cli.option("age", (value) => {
    return value;
}, {
    description: "Age option", // Describe the name option
    shorthand: ["A"] // Shortcut for the option ("-A")
});

cli.command("print", ({ options, _args }) => {
    console.log(`Hello my name is ${_args[0]}`);
    if (options.age) {
        console.log(`I'm ${options.age} years old.`)
    }
}, {
    arguments: 1, // Defines how many arguments to be used.
    description: "Prints a name" // Describe the command
});

cli.run(process.argv.slice(2)); // Runs the CLI with the ARGV array;
  • Run the program
$ node test.js print Joe --age=20
Hello my name is Joe
I\'m 20 years old.

$ node test.js --yolo
You only live once.

Events (new in 0.0.6)

Events is a new feature in Kuman in which you can trigger certain events everytime your CLI app will launch, display version, and etc. It replaces the get() and set() functions that manipulate few instance settings and values like cli_version and cli_name.

// This outputs the following information when you type `--help` 
cli.on("showHelp", () => {
    console.log("My App");
    console.log("This is a sample CLI app");
    console.log("\nUsage: my_app [options]");
});

// This event triggers when you check the version of your CLI app.
cli.on("showVersion", () => {
    console.log("1.0");
});

Documentation

Visit the new docs here.

Development

Build

Kuman is written on Typescript from the ground-up and must install the tsc compiler first before you start building this module. After that, you can start building it by executing:

$ npm build-dev

Roadmap

  • Command argument support
  • Shorthand option support
  • Middleware / Plugin Support(?)
  • JSDoc comments
  • --help generation
  • Error handling
  • Tests

Contribute

  1. Fork / Clone this repo. (git clone https://github.com/nedpals/kuman.git)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Copyright

  • © 2018-2019 Ned Palacios (nedpals)
You can’t perform that action at this time.