DocsAutocompleteSchemasSubcommand

Used to define subcommands under a main command. For example, within git commit, commit is a subcommand of git.

Subcommand Objects are recursive by nature.

Properties

name

Type: string

Required:

Description:

The exact name of the subcommand. It is important to get this right for parsing purposes.

Example:

For npm, the subcommand is npm install would have "name: install" (no extra spaces or characters, exactly like this)


subcommands

Type: Subcommand[]

Required:

Description:

A list of subcommands for this spec. Subcommands can be nested within subcommands.


options

Type: Option[]

Required:

Description:

A list of option objects for this subcommand.


args

Type: SingleOrArray\<Arg>

Required:

Description:

An array of args or a single arg.

Important If a subcommand takes an argument, please at least include an empty Arg Object (e.g. {}). If you don't, Fig will assume the subcommand does not take an argument and we will present the wrong suggestions.

Example:

git push takes two arguments. The most basic representation of this is args: [{}, {}]


additionalSuggestions

Type: Suggestion[]

Required:

Description:

A list of Suggestion objects that are appended to a specific subcommand. Often these are shortcuts

Example:

commit -m '{cursor}' is a shortcut for git


loadSpec

Type: string

Required:

Description:

Allows Fig to refer to another completion spec in the ~/.fig/autocomplete folder. Specify the spec name without js. This is simiar but different to isCommand in the Arg object so read both carefully

Example:

aws-s3 refer to the ~/.fig/autocomplete/aws-s3 spec.

When is this used? The aws spec is so large that it is slow to load. It needs to be brokenup into a separate spec for each subcommand.

If your CLI tool takes another CLI command (e.g. time , builtin... ) or a script (e.g. python, node) and you would like Fig to continue to provide completions for this script, see isCommand and isScript in {Arg.


generateSpec

Type: ( context?: string[], executeShellCommand?: ExecuteShellCommandFunction ) => Promise\<Spec>

Required:

Description:

Dynamically generate a completion spec to be merged in at the same level as the current subcommand. This is useful when a CLI is generated dynamically. This function takes two params:

  1. Context: an array of strings (the tokens the user has typed)
  2. executeShellCommand: a function that takes a string as input. It executes this string as a shell command on the user's device from the same current working directory as their terminal. It outputs a text blob. It is also async.

It outputs a completion spec object

Example:

Laravel artisan has its own subcommands but also lets you define your own completion spec.


displayName

Type: string

Required:

Description:

See Suggestion

Example:

For the npm CLI we have a subcommand called install. If we wanted to display some custom text like Install an NPM package 📦 we would set name: "install" and displayName: "Install an NPM package 📦"


insertValue

Type: string

Required:

Description:

See Suggestion

Example:

For git commit the -m option has an insert value of -m '{cursor}'


description

Type: string

Required:

Description:

See Suggestion


icon

Type: string

Required:

Description:

See Suggestion

Example:

A, 😊 https://www.herokucdn.com/favicon.ico fig://icon?type=file


isDangerous

Type: boolean

Required:

Description:

See Suggestion

Remark:

This is used in specs like rm and trash.


priority

Type: number

Required:

Description:

See Suggestion

Examples:

If you want your suggestions to always be at the top order regardless of whether they have been selected before or not, rank them 76 or above If you want your suggestions to always be at the bottom regardless of whether they have been selected before or not, rank them 49 or below


hidden

Type: boolean

Required:

Description:

See Suggestion

Example:

The "-" suggestion is hidden in the cd spec. You will only see it if you type cd -

On this page