feat: migrate from docopt to cobra for CLI argument parsing

Replace docopt-go with spf13/cobra, giving cheat a built-in
`--completion` flag that dynamically generates shell completions for
bash, zsh, fish, and powershell. This replaces the manually-maintained
static completion scripts and resolves the root cause of multiple
completion issues (#768, #705, #633, #632, #476).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christopher Allen Lane
2026-02-15 17:33:47 -05:00
parent ca1ec0e38d
commit 9b92261604
119 changed files with 14204 additions and 3127 deletions

View File

@@ -58,6 +58,11 @@ Print the version number.
.TP
\[en]rm=\f[I]CHEATSHEET\f[R]
Remove (deletes) \f[I]CHEATSHEET\f[R].
.TP
\[en]completion=\f[I]SHELL\f[R]
Generate a shell completion script.
\f[I]SHELL\f[R] must be one of: \f[B]bash\f[R], \f[B]zsh\f[R],
\f[B]fish\f[R], \f[B]powershell\f[R].
.SH EXAMPLES
.TP
To view the foo cheatsheet:
@@ -135,37 +140,52 @@ Cheatpaths may be configured in \f[I]conf.yaml\f[R], and viewed via
For detailed instructions on how to configure cheatpaths, please refer
to the comments in conf.yml.
.SS Autocompletion
Autocompletion scripts for \f[B]bash\f[R], \f[B]zsh\f[R], and
\f[B]fish\f[R] are available for download:
.IP \[bu] 2
\c
.UR https://github.com/cheat/cheat/blob/master/scripts/cheat.bash
.UE \c
.IP \[bu] 2
\c
.UR https://github.com/cheat/cheat/blob/master/scripts/cheat.fish
.UE \c
.IP \[bu] 2
\c
.UR https://github.com/cheat/cheat/blob/master/scripts/cheat.zsh
.UE \c
\f[B]cheat\f[R] can generate shell completion scripts for
\f[B]bash\f[R], \f[B]zsh\f[R], \f[B]fish\f[R], and \f[B]powershell\f[R]
via the \f[B]\[en]completion\f[R] flag:
.IP
.EX
cheat \-\-completion bash
cheat \-\-completion zsh
cheat \-\-completion fish
cheat \-\-completion powershell
.EE
.PP
The \f[B]bash\f[R] and \f[B]zsh\f[R] scripts provide optional
integration with \f[B]fzf\f[R], if the latter is available on your
\f[B]PATH\f[R].
Completions are dynamically generated and include cheatsheet names,
tags, and cheatpath names.
.PP
The installation process will vary per system and shell configuration,
and thus will not be discussed here.
To install completions, pipe the output to the appropriate location for
your shell.
For example, on \f[B]bash\f[R]:
.IP
.EX
cheat \-\-completion bash > /etc/bash_completion.d/cheat
.EE
.PP
Or for the current user only:
.IP
.EX
cheat \-\-completion bash > \[ti]/.local/share/bash\-completion/completions/cheat
.EE
.PP
For \f[B]zsh\f[R], you may need to add the completions directory to your
\f[B]fpath\f[R]:
.IP
.EX
cheat \-\-completion zsh > \[dq]${fpath[1]}/_cheat\[dq]
.EE
.PP
For \f[B]fish\f[R]:
.IP
.EX
cheat \-\-completion fish > \[ti]/.config/fish/completions/cheat.fish
.EE
.SH ENVIRONMENT
.TP
\f[B]CHEAT_CONFIG_PATH\f[R]
The path at which the config file is available.
If \f[B]CHEAT_CONFIG_PATH\f[R] is set, all other config paths will be
ignored.
.TP
\f[B]CHEAT_USE_FZF\f[R]
If set, autocompletion scripts will attempt to integrate with
\f[B]fzf\f[R].
.SH RETURN VALUES
.IP "0." 3
Successful termination

View File

@@ -65,6 +65,10 @@ OPTIONS
--rm=_CHEATSHEET_
: Remove (deletes) _CHEATSHEET_.
--completion=_SHELL_
: Generate a shell completion script. _SHELL_ must be one of: **bash**,
**zsh**, **fish**, **powershell**.
EXAMPLES
========
@@ -149,18 +153,33 @@ comments in conf.yml.
Autocompletion
--------------
Autocompletion scripts for **bash**, **zsh**, and **fish** are available for
download:
**cheat** can generate shell completion scripts for **bash**, **zsh**,
**fish**, and **powershell** via the **--completion** flag:
- <https://github.com/cheat/cheat/blob/master/scripts/cheat.bash>
- <https://github.com/cheat/cheat/blob/master/scripts/cheat.fish>
- <https://github.com/cheat/cheat/blob/master/scripts/cheat.zsh>
cheat --completion bash
cheat --completion zsh
cheat --completion fish
cheat --completion powershell
The **bash** and **zsh** scripts provide optional integration with **fzf**, if
the latter is available on your **PATH**.
Completions are dynamically generated and include cheatsheet names, tags, and
cheatpath names.
The installation process will vary per system and shell configuration, and thus
will not be discussed here.
To install completions, pipe the output to the appropriate location for your
shell. For example, on **bash**:
cheat --completion bash > /etc/bash_completion.d/cheat
Or for the current user only:
cheat --completion bash > ~/.local/share/bash-completion/completions/cheat
For **zsh**, you may need to add the completions directory to your **fpath**:
cheat --completion zsh > "${fpath[1]}/_cheat"
For **fish**:
cheat --completion fish > ~/.config/fish/completions/cheat.fish
ENVIRONMENT
@@ -171,10 +190,6 @@ ENVIRONMENT
: The path at which the config file is available. If **CHEAT_CONFIG_PATH** is
set, all other config paths will be ignored.
**CHEAT_USE_FZF**
: If set, autocompletion scripts will attempt to integrate with **fzf**.
RETURN VALUES
=============