中文

API Reference

Reference the current func decorators, runtime types, module APIs, and funcgo commands.

Updated 2 weeks ago
src/commands/deploy.command.ts
import { Command, Handler, Required, Value } from 'func'

@Command({ name: 'deploy' })
export class DeployCommand {
  @Required()
  @Value()
  env?: string

  @Handler()
  run() {
    console.log(`Deploying to ${this.env}`)
  }
}
API familyReturnsFailure contract
Command and module decoratorsClassDecoratorInvalid definitions are F_SYSTEM errors and stop dispatch.
Handler and catch decoratorsMethodDecoratorInvalid targets or incompatible parameters are F_SYSTEM errors.
Field option decoratorsPropertyDecoratorInvalid definitions are F_SYSTEM; invalid user values are F_RUNTIME_PRINT.
Runtime injection decoratorsParameterDecoratorUnsupported injection positions are F_SYSTEM errors.
run(input, options?)Promise<void>Routes runtime failures through local and global handlers.
createApp(input, options?)ContainerDefinition validation occurs when the container resolves and runs.

Use this page when you already know which func concept you need and want its exact signature. For behavior and design guidance, see Core Concepts, Field Options, Parameters, and Error Handling for behavior details.

Commands

SignatureStructureDescription
@Command(params: CommandParams)CommandParams = { name: string, description?: string, alias?: string }Register a named command. The name or alias is matched against the first input token.
@Handler(params?: HandlerParams)HandlerParams = { flag?: string, alias?: string, description?: string, path?: string[] }Register a default handler, flag handler, or path handler. path cannot be combined with flag or alias.
@SubOptions(params: Array<OptionParams>)OptionParams = { name: string, type?: Boolean | String | Number | [String], description?: string, alias?: string }Add parse-only options for the current command scope. Field options are preferred for values read from the command instance.
@CommandMissing()-Register a fallback command for bare input whose first token is not a known command. It can define handlers and field options like a normal command.
@CommandMajor()-Register the major command for empty invocation and top-level options.
@Catch()-Register a local command error method. Normal completion consumes the failure before global error handlers.
@CatchAll() / @CommandError()-Register a global error handler class. CommandError is an alias for CatchAll.

Field Options and Validators

SignatureStructureDescription
@Flag(params?)params = { name?: string, alias?: string, description?: string }Declare a boolean option assigned to the decorated property.
@Value(params?)params = { name?: string, alias?: string, description?: string, type?: Boolean | String | Number | [String], required?: boolean }Declare a scalar value option. The type is inferred from design metadata when possible.
@ArrayValue(params?)params = { name?: string, alias?: string, description?: string }Declare a repeated string option assigned as a string array.
@Required()-Require the option to be provided explicitly or have a defined value.
@Enum(values)values = Array<boolean | string | number>Validate that a scalar value, or every array item, is one of the allowed values.
@DependsOn(options)options = string[]Require other options when this option is explicitly provided.
@Exclusive(options)options = string[]Reject combinations where this option and one of the listed options are both explicit.
@ValueValidate(fn)fn(value, options) => boolean | string | voidRun a custom validator. Return false or a string to create a validation error.

Context Injection

SignatureDescription
@Args()Inject FuncArgs: command metadata, selected handler, inputs, path, normalized option, and native parse data.
@Regs()Inject CommandRegistry for registered command metadata.
@Exception()Inject FuncException into local catch methods and global error handlers.

Application

SignatureStructureDescription
@FuncModule(params)params = { commands?: Class[], imports?: FuncModuleInput[], services?: Class[] }Create an application or feature module.
@Service()-Mark a service class that can be injected into commands or other registered services.
run(input, options?)options = { argv?: string[], services?: Class[] }Create an app and execute it.
createApp(input, options?)options = { argv?: string[], services?: Class[] }Create the low-level Container without running it.

Runtime Types

SignatureStructureDescription
FuncArgs{ command?, handler?, inputs: string[], native, option: UserOption, path: string[] }Normalized runtime context injected by Args.
FuncExceptioncode, details, error, level, message, type, preventDefaultPrint()Wrapper around FuncError used by catch and error handlers.
CommandRegistry{ commands: RegisterCommandParams[] }Read-only registry context injected by Regs.

Support

funcgo provides the standard development and build commands for func projects. The full workflow is documented in Tooling.

SignatureStructureDescription
funcgo setup--fix?Inspect package.json and suggest missing func.entry, func.outDir, bin, dev script, and build script configuration.
funcgo dev-f, --file <entry>; -- <args>Run the project entry with a local TypeScript runtime and pass arguments through to the command.
funcgo build-f, --file <entry>; -o, --out <dir>; -e, --external <package>; -w, --watch; --watch-path <target>Bundle the project entry, create executable bin.js, and optionally rebuild when files, directories, or positive globs change.
funcgo --help / --version-h; -vPrint funcgo command discovery or the installed funcgo version.

Configuration

SignatureDescription
package.json#func.entryDefault TypeScript entry file used by funcgo dev and funcgo build when —file is not provided.
package.json#func.outDirDefault build output directory used by funcgo build when —out is not provided.
package.json#binMap the installed executable name to the generated bin.js inside func.outDir.