Fig Autocomplete & Cobra

This tutorial will walk you through setting up Fig's integration with golang CLI framework, Cobra.

Create the generate-fig-spec subcommand

# Go to your CLI's project
cd path/to/my/project

# Create a new subcommand called generate-fig-spec
cobra add generate-fig-spec

# Install Fig's prebuilt cobracompletefig module
go get

The steps above should have created a generate-fig-spec.go file in your cmd/ directory.

Update this file so it looks like this:

package cmd

import (

func init() {

Compile your changes to your CLI.

go install my-cli

Now if you run my-cli generate-fig-spec you'll see it output a Fig completion spec!

Next Steps: now that you have successfully configured the integration you can either push the spec to the autocomplete repo or push it to Fig's cloud.