appo

command line solution

Usage no npm install needed!

<script type="module">
  import appo from 'https://cdn.skypack.dev/appo';
</script>

README

appo.js

A class based ES6 solution for node.js command-line interfaces.

Installation

$ npm install appo

Examples

Take a look at the examples folder.

CLI

Bootstrap a simple CLI, with one command, group and option.

This class is the root of your application and has to exist.

Note: this bootstrap requires you to create a command, group and an option (you can delete the methods, if you don't want to create them).

#!/usr/bin/env node

var Appo = require('appo');
class MyCLI extends Appo {

  constructor() {
    super();

    this
      .name('myCLI')
      .help(`my very first CLI`)
      .command(new YOURCOMMAND())
      .group(new YOURGROUP())
      .option(new YOURFLAG())
  }
}

var cli = new MyCLI();
cli.parse(process.argv);

Configuration

  • name (required) : The name of the CLI.
  • help : A short help text for the CLI.
  • command (can be invoked multiple times) : Adds a command to the CLI.
  • group (can be invoked multiple times) : Adds a group to the CLI.
  • option (can be invoked multiple times) : Adds a flag to the CLI.
  • description : Adds a description of the CLI.

Groups

Every appo CLI can have an unlimited number of groups. Groups can own other groups, commands and options.

Groups have to be passed to either the CLI or a group.

Note: this group requires you to create a group, command and an option (you can delete the methods, if you don't want to create them).

var Group = require('appo/lib/group');

class MyGroup extends Group {

  constructor() {
    super();

    this
      .name('myGroupName')
      .help('help text of my first group')
      .group(new YOURGROUP())
      .command(new YOURCOMMAND())
      .option(new YOURFLAG())
  }

}

Configuration

  • name (required): The name of the CLI.
  • help: A short help text for the CLI.
  • command (can be invoked multiple times): Adds a command to the CLI.
  • group (can be invoked multiple times): Adds a group to the CLI.
  • option (can be invoked multiple times): Adds a flag to the CLI.
  • description: Adds a description of the CLI.

Commands

Every appo CLI can ha an unlimited number of commands.

Every command can own options.

Commands have to be passed to either the CLI or a group. The commands action has to return a promise.

Note: this command requires you to create an action and an option (you can delete the methods, if you don't want to create them).

var Command = require('appo/lib/command');

var Q = require('q');

class MyCommand extends Command {

  constructor() {
    super();

    this
      .name('myCommandName')
      .action(this.myAction)
      .option(new YOUREXAMPLEFLAG())
      .help('make an http get request and print the result')
  }

  myAction(argv) {
    var deferred = Q.defer();

    console.log('log my action');
    deferred.resolve();

    return deferred.promise;
  }

}

Configuration

  • name (required): The name of the CLI.
  • help: A short help text for the CLI.
  • option (can be invoked multiple times): Adds a flag to the CLI.
  • description: Adds a description of the CLI.

Flags

A Flag has to be passed to either the root CLI, a group or a command.

Note: this flag requires you to create an argument (you can delete the method, if you don't want to create it).

var Flag = require('appo/lib/option/flag');

class MyFlag extends Flag {

  constructor() {
    super();

    this
      .name('myFlagName')
      .alias('m')
      .required(true)
      .argument(new MYARGUMENT())
  }
}

Configuration

  • name (required): The name of the CLI.
  • help: A short help text for the CLI.
  • alias (can be invoked multiple times): Adds an alias to the flag.
  • required: Tells appo, if the flag is required.
  • argument: Adds an argument to the flag.
  • description: Adds a description of the CLI.

Arguments

An Argument has to be passed to a Flag as a parameter.

var Argument = require('appo/lib/option/argument');

class MyArgument extends Argument {

  constructor() {
    super();
    this
      .name('myArgumentName')
  }
}

Configuration

  • name (required): The name of the CLI.
  • help: A short help text for the CLI.
  • description: Adds a description of the CLI. A short help text for the flag.

License

MIT