Skip to content

Playbooks for g

Story-style workflows—solo, team, and on-call. Jump into the full Use cases page anytime.

cli

CLI argument definitions using `clap`.

auto-generated This page is built from //! comments in the Rust source. Edit the source and run npm run docs:extract to update it.

CLI argument definitions using clap.

Tutorial overview:

  • clap uses derive macros (#[derive(Parser)], #[derive(Subcommand)]) to turn Rust structs/enums into a command-line interface.
  • Struct fields become flags or positional args, based on #[arg(...)].
  • Enums represent subcommands, and nested enums represent sub-subcommands.

Folder layout

cli/
  mod.rs        ← this file: Cli + Commands + GitPassArgs +
                  print_completions + Commands::telemetry_names + re-exports
  styles.rs     ← help-output colour palette
  workspace.rs  ← WorkspaceCommands
  stack.rs      ← StackCommands
  commit.rs     ← CommitArgs
  compare.rs    ← CompareArgs
  branch.rs     ← BranchArgs + BranchSquashCmd
  config.rs     ← ConfigArgs
  stats.rs      ← StatsArgs
  developer.rs  ← DeveloperCommands
  notes.rs      ← NotesCommands

Every per-domain struct/enum is re-exported below so external call sites continue to write use crate::cli::CommitArgs; (etc.) without caring about the internal split.

Source: src/cli/mod.rs