🎉 Hyperse Wizard has been published.
Hyperse Wizard
Core API

command

Command support

Command

The Command is the core mechanism within the @hyperse/wizard framework that enables definition, parsing, and execution of CLI commands. This system provides type-safe command creation, argument parsing, and process execution while integrating with the broader event-driven architecture.

CommandBuilder

Name

Prop

Type

Options

Prop

Type

Properties

Prop

Type

Command Properties

Prop

Type

Flags Configuration

Wizard's flag parsing is powered by type-flag and comes with many features:

  • Array & Custom types
  • Flag delimiters: --flag value, --flag=value, --flag:value, and --flag.value
  • Combined aliases: -abcd 2 → -a -b -c -d 2
  • End of flags: Pass in -- to end flag parsing
  • Unknown flags: Unexpected flags stored in unknownFlags

Read the type-flag docs to learn more.

Flags can be specified in the flags object-property, where the key is the flag name, and the value is a flag type function or an object that describes the flag.

The flag name is recommended to be in camelCase as it will be interpreted to parse kebab-case equivalents.

The flag type function can be any function that accepts a string and returns the parsed value. Default JavaScript constructors should cover most use-cases: String, Number, Boolean, etc.

The flag description object can be used to store additional information about the flag, such as alias, default, and description. To accept multiple values for a flag, wrap the type function in an array.

All of the provided information will be used to generate better help documentation.

Example:

// @filename: @hyperse/wizard/dist/index.d.ts
import {  } from '@hyperse/wizard';

const  = <
  'deploy',
  { : { : string; : string } }
>('deploy', {
  //locale message key
  : 'plugins.deploy.description',
  : true,
})
  .({
    : {
      : ,
      : 'f',
      //locale message key
      : 'plugins.deploy.flags.fileType',
      : 'js',
    },
    : {
      : ,
      : 'o',
      //locale message key
      : 'plugins.deploy.flags.ossType',
      : 'aliyun',
    },
    : {
      : 'i',
      : 'plugins.deploy.flags.ignore',
      // Array type
      // To accept multiple values of a flag, wrap the type with an array:
      : [],
      : [],
    },
    : {
      : [],
      // Use a function to return an object or array
      : () => [1, 2],
    },
  })
  .(() => {
    //do something
  });

// execute command
// node ./dist/cli.js deploy --fileType=ts --ossType=tencent --ignore=a --ignore=b --manyNumbers=1 --manyNumbers=2 --manyNumbers=3

Advanced Usage

To seperate handlers from the cli definition, you can use the defineCommand utility function:

Prop

Type

Example:

// @filename: @hyperse/wizard/dist/index.d.ts
import {  } from '@hyperse/wizard';

const  = <
  'deploy',
  { : { : string; : string } }
>('deploy', {
  //locale message key
  : 'plugins.deploy.description',
});

On this page