Skip to content

point-hub/express-cli

Repository files navigation

Express Cli

This is an Express ESM-only module library - you are not able to import it with require().

Install

npm install @point-hub/express-cli

Directory Example

•
├── bin
│   └── cli.js
├── lib
└── src
    ├── commands
    │   └── example-command.ts
    └── index.ts

Usage Example

  1. create command file src/commands/greet-command.ts
import { BaseCommand } from "@point-hub/express-cli";

export class GreetCommand extends BaseCommand {
  constructor() {
    super({
      name: "greet",
      summary: "Welcome someone",
      description: "Welcome someone with particular words",
      alias: ["gret", "say"],
      arguments: [
        {
          name: "name",
          description: "Your name",
        },
      ],
      options: [
        {
          type: "boolean",
          flag: "--smile",
          shorthand: "-s",
          description: "Add smiley :)",
        },
      ],
    });
  }
  handle() {
    // handle command here
  }
}
  1. create an entry point file src/ìndex.ts
import { ExpressCli } from "@point-hub/express-cli";
import { GreetCommand } from "./commands/greet.command.js";

/**
 * Register the commands for the application.
 *
 * @example
 * command.register(ExampleCommand);
 */
export function commands(command: ExpressCli): void {
  command.register(new GreetCommand());
}
  1. compile typescript to "lib" directory

  2. create an executeable file bin/cli.js and make it executeable chmod +x bin/cli.js

#!/usr/bin/env node

import { commands } from "../lib/index.js";
import { ExpressCli } from "@point-hub/express-cli";

const cli = new ExpressCli("cli");
commands(cli);
cli.run(process.argv);
  1. try your command using node bin/cli.js greet John

About

Express command line interface wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published