Fig Autocomplete & clap

This tutorial will walk you through setting up Fig's integration with the Rust CLI framework, clap.

Add clap_complete_fig to your project

Ensure the following dependencies are in your Cargo.toml.

clap = { version = "3.1", features = ["derive"] }
clap_complete = "3.1"
clap_complete_fig = "3.1"

Generate the spec

There are two ways to generate the spec using clap_complete_fig, you can create the spec at runtime or at build.

Generate spec at runtime (Easy)

Using the

use clap::{IntoApp, Parser, Subcommand};

struct Cli {
    command: Commands,

enum Commands {

fn main() {
    let cli = Cli::parse();

    match &cli.command {
        Commands::GenerateFigSpec => clap_complete::generate(
            &mut Cli::command(),
            &mut std::io::stdout(),

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

Generate spec at build (Advanced)

In your file, which should be a top level file in the same directory as you Cargo.toml you can generate the spec using the following format. You must ensure that your

use your_app::App;
use clap::IntoApp;
use ;

fn main() {
        &mut App::into_app(),
    .expect("Unable to generate Fig 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.