clite: A Lightweight CLI Framework

0.3.0 · abandoned · verified Sun Apr 19

clite is a lightweight command-line interface (CLI) framework for Node.js applications, designed to provide essential boilerplate functionality. Its current stable version is 0.3.0, last released in March 2016, indicating that the project is likely no longer actively maintained. The library focuses on automating common CLI tasks such as displaying version information from `package.json`, generating help documentation, handling `stdin` input, notifying users of updates via `update-notifier`, and managing exceptions with non-zero exit codes. It leverages `abbrev` for command/option aliasing and `yargs` for robust argument parsing, including booleans and options. Commands are promise-based and lazy-loaded to optimize boot times. A key differentiator is its minimal configuration approach, allowing developers to quickly scaffold CLI tools without extensive setup, though its age might pose compatibility challenges with modern Node.js environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a basic `clite` application with a default command, a named command (`greet`), and an asynchronous command (`delay`), including configuration for options, booleans, aliases, and a help file. The code shows how `clite` consumes a configuration object and how individual command modules are structured.

/* cli.js */
#!/usr/bin/env node
const clite = require('clite');
const path = require('path');

// Load configuration for the CLI application
clite(require('./config'));

/* config.js */
module.exports = {
  commands: {
    '_': path.join(__dirname, 'commands', 'default'), // Default command if no argument provided
    'greet': path.join(__dirname, 'commands', 'greet'),
    'delay': path.join(__dirname, 'commands', 'delay')
  },
  booleans: ['verbose', 'help'],
  options: ['name', 'message'],
  alias: {
    'v': 'verbose',
    'n': 'name'
  },
  help: path.join(__dirname, 'help', 'main.txt') // Path to a main help file
};

/* commands/default.js */
module.exports = function defaultCommand(args) {
  if (args.help) {
    return `Usage: my-cli [command] [--name <name>] [--message <message>] [--verbose]

Default command echoes arguments or shows a welcome message.
Try 'my-cli greet --name World' to greet someone.`;
  }
  if (args._.length > 0) {
    return `You ran the default command with arguments: ${args._.join(' ')}`;
  }
  return 'Welcome to the clite demo! Try `my-cli greet --name John`.';
};

/* commands/greet.js */
module.exports = function greetCommand(args) {
  const name = args.name || 'Stranger';
  const message = args.message || 'Hello';
  if (args.verbose) {
    return `Preparing to greet ${name} with message: "${message}"`;
  }
  return `${message}, ${name}!`;
};

/* commands/delay.js */
module.exports = function delayCommand(args) {
  const duration = parseInt(args._[0] || '1000', 10); // First argument is delay duration
  return new Promise(resolve => {
    setTimeout(() => resolve(`Delayed for ${duration}ms. All done!`), duration);
  });
};

/* help/main.txt */
// This is a simple help file for the 'my-cli' tool.
// Use 'my-cli --help' for general help.
// Use 'my-cli greet --help' for command specific help (if implemented).

view raw JSON →