Lesson 9 of 9 · 27m
Completions, Diagnostics, Upgrades, and Compatibility
Finish the product with shell completions, manpages, structured diagnostics, update strategy, telemetry boundaries, and compatibility discipline.
The last 10 percent of a CLI is where professional tools separate themselves from weekend binaries. Users expect completion to know subcommands, --help to answer real questions, logs to reveal what happened, upgrades to be boring, and old scripts not to explode because someone renamed a flag for aesthetic reasons. Maintenance is part of interface design.
Generate completions from the same source of truth
Hand-written completions rot immediately. Generate them from clap metadata with clap_complete:
use clap_complete::{generate, shells::Bash};
use std::io;
fn print_bash_completion(mut cli: clap::Command) {
generate(Bash, &mut cli, "deployctl", &mut io::stdout());
}Ship them in release packages and test them in golden output. Completion is not cosmetic; it teaches users the interface and prevents misspelled commands.
Manpages still matter in operational environments
Many Linux administrators expect man deployctl-publish, especially for infrastructure tools. Generate manpages with clap_mangen or maintain a deliberate alternative such as --help plus online documentation. If you generate them, treat examples, exit codes, files, environment variables, and precedence as required sections.
Diagnostics should be safe to share
Provide one command or flag that collects version, platform, config sources, and relevant runtime state:
deployctl doctor
deployctl doctor --output json{
"version": "1.4.0",
"target": "x86_64-unknown-linux-musl",
"config_sources": ["/etc/deployctl/config.toml", "environment"],
"registry_reachable": true,
"token_present": true
}Never include raw tokens, private keys, command history, full environment dumps, or request bodies. The purpose of diagnostics is to shorten support loops, not create incident reports.
Be explicit about update mechanics
Self-updating binaries are convenient and dangerous. If you implement self-update, verify signed metadata and artifacts, write atomically, preserve the old binary until success, and support rollback. If package managers own updates, do not fight them with a hidden self-updater.
A safer compromise is update awareness:
deployctl 1.4.0 is 2 releases behind; 1.5.1 is available.
Upgrade with your package manager or see https://sudosecurity.org/docs/deployctl/upgrade.Checks must be opt-in or clearly documented, time out quickly, and never block critical operations when the network is unavailable.
Telemetry requires a trust budget
Most CLIs do not need telemetry. If you collect it, make it opt-in, document exact fields, provide an inspect command, and avoid identifiers by default. Invocation counts can still become sensitive when they reveal infrastructure names or operational timing. The safest telemetry is often transparent release download metrics plus user-submitted diagnostics.
Compatibility is a product decision
Define a public surface: commands, flags, exit codes, stdout schemas, config keys, environment variables, and file formats. Then decide what semantic versioning means for the CLI. A human-help wording change is not the same compatibility risk as changing JSON keys consumed by CI.
Deprecation works when users can see it:
warning: --registry-host is deprecated; use --registry-url. Support ends in deployctl 2.0.Keep the migration path mechanical and documented. Automated rewrites of user config should preserve backups and explain themselves.
Field notes
- Completion generation must include dynamic values only when runtime lookup is fast and failure-safe.
doctoroutput should distinguish "not configured" from "configured incorrectly"; those are different fixes.- Do not perform network update checks in commands that users rely on for offline recovery.
- Compatibility promises mean nothing unless tests encode old flags, old config files, and old output schemas.
- A changelog written for users lists behavior changes and migrations, not commit noise.
Was this lesson helpful?