npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@axiosleo/cli-tool

v1.6.4

Published

Design for quickly developing CLI applications using Node.js.

Downloads

402

Readme

@axiosleo/cli-tool

English | 简体中文

NPM version npm download CI Build Status License FOSSA Status

Design for quickly developing CLI applications using Node.js

See detail usage from wiki

Installation

npm install @axiosleo/cli-tool

Quickly initialize application

npm install @axiosleo/cli-tool -g

cli-tool init <app-name>

# make command file
cli-tool make <command-name> <commands-dir-path>
# for example
cli-tool make test ./commands/ # will generate command file on ./commands/test.js

# run command js script
cli-tool exec ./command/test.js

Usage

Start application

const { App } = require('@axiosleo/cli-tool');
const app = new App({
  name: 'cli-tool',      // cli app command name, required
  version: '1.0.0',      // cli app version, required
  desc: 'cli app description',
  commands_dir: '/path/to/commands/dir/', // will auto load command files
  commands_sort: ['help', ... ],
  commands_group: {
    'group description': ['command_name', ...],
  }
});
app.start();

Run single command

  • register with command class
const CommandExample = require('/path/to/your/command/file');
app.register(CommandExample);

app.exec("<command-name>");
  • register with command object
const CommandExample = require('/path/to/your/command/file');
const command = new CommandExample();
app.register(command);

app.exec("<command-name>");
  • register with command file path
app.register('/path/to/your/command/file');

app.exec("<command-name>");

Use locales

The "desc" of CLI Application and Command will be automatically translated by using the locales json file.

locales example json file : locales

see detail from locales wiki

const path = require('path');
app.locale({
  dir: path.join(__dirname, '../locales'), // /path/to/app/locales/dir
  sets: ['en-US', 'zh-CN'],                // cannot be empty, the first set as default.
});
app.start(); // set locale before start app

Command Class Example

'use strict';

const { Command } = require('@axiosleo/cli-tool');

class CommandExample extends Command {
  constructor() {
    super({
      name: 'command-name',
      desc: 'command desc',
      alias: ['command-alia1', 'command-alia2'],
    });

    /**
     * add argument of current command
     * @param name argument name
     * @param desc argument description
     * @param mode argument mode : required | optional
     * @param default_value only supported on optional mode
     */
    this.addArgument('arg-name', 'desc', 'required', null);

    /**
     * add option of current command
     * @param name option name
     * @param short option short name
     * @param desc option description
     * @param mode option mode : required | optional
     * @param default_value only supported on optional mode
     */
    this.addOption('test', 't', 'desc', 'required', null);
  }

  async exec(args, options, argList, app) {
      // do something in here

      // get arg&option by name
      const arg1 = args.argName;
      const option1 = options.optionName;

      // get arg by index
      const index = 0;
      const arg2 = argList[index];

      // ask for answer
      const answer = await this.ask('Please input your answer');

      // ask for confirm, default value is 'false'
      const confirm = await this.confirm('Confirm do this now?', false);

      // select action
      const action = await this.select('Select an action', ['info', 'update']);

      // print table
      const rows = [
        ['Bob', 2]
      ];
      const head = ['Name', 'Score'];
      this.table(rows, head);
  }
}

module.exports = CommandExample;

License

This project is open-sourced software licensed under the MIT.

FOSSA Status