Skip to content

Quickly Start

axios edited this page Feb 17, 2022 · 3 revisions

Start application

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

const app = new App({
  name: 'cli',
  version: '1.0.0',
  desc: 'cli app description',
  commands_sort: ['help']
});

Object.values(commands).forEach((item) => {
  app.register(item);
});

app.start();

Run single command

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

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

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

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

Use locales

The "desc" will be automatically translated by using the locales json file.

locales example json file : locales

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