FUNC - Tiny typed CLI framework

Parameters of Command

Add a parameter to the class where you build the command, and mark that parameter with its provider class. func injects it automatically:

import { Command, CommandArgsProvider, SubOptions } from 'func'

@Command({ name: 'test' })
@SubOptions([{ name: 'help' }])
export class Test {
  constructor(private arg: CommandArgsProvider) {
    console.log(arg.inputs) // ['tools']
    console.log(arg.option) // { help: true }
    console.log(arg.native) // original parse info
  }
}

When you run <command> test tools --help, the parameters match the values shown above. You can use any parameter name you like, as long as its class is CommandArgsProvider.

arg.native contains the raw command-line parsing data, which is useful when you are handling non-standard command-line parameters.

Parameters of Option

This is similar to Command, but OptionArgsProvider exposes one base value for the option. Specify the provider class in an Option command to access more information:

import { Option, OptionArgsProvider } from 'func'

@Option({ name: 'name', type: String })
export class Name {
  constructor(private arg: OptionArgsProvider) {
    console.log(arg.value)
    console.log(arg.native) // original parse info
  }
}

For --name func, arg.value is func. Repeated [String] options return an array of values.

All Registered Information

If you are writing a help command or matching possible user input, you may need all currently registered information. RegisterProvider carries all registered metadata for the current command-line project:

import { Option, RegisterProvider } from 'func'

@Option({ name: 'help' })
export class MyHelp {
  constructor(private arg: RegisterProvider) {
    console.log(arg.commands) // all commands
    console.log(arg.options) // all options
  }
}