Print help that was asked for to stdout (closes #179)
check / check (push) Canceled after 0s

--help, -h and the help subcommand now print to stdout and exit 0, so
the help can be paged and searched. The usage text of a usage error
stays on stderr with exit 2, as does help for an unknown subcommand
("sfdupes help scna"). A failed write of the help exits 1.

Cobra prints help to the command's output writer, which stays stderr,
drops a failed write, and returns no error after help. So run replaces
the help function and the help subcommand: the help goes into a buffer,
then to stdout, and the error sets the exit code.

README "Settings" and goal 4 say so.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-13 20:00:04 +00:00
1 parent e16c46804d
commit bcea04ee4e
5 files changed
+170 -41

No files matched your search

+8 -6
View File
@@ -255,6 +255,7 @@ In order:
time, against what the database holds.
4. **Keep the streams apart.** Everything on stdout is machine-readable data.
Everything for a human reader, such as progress and warnings, goes to stderr.
The one exception is help that was asked for, which goes to stdout.
### Subcommands
@@ -324,12 +325,13 @@ The reference below is also the program's specification.
"Operands").
- `--version`, `-v` prints `sfdupes VERSION` (see "Install") to stdout and
exits 0. It writes nothing to stderr.
- `--help`, `-h`, alone or after a subcommand, prints the help text to stderr
and exits 0. It writes nothing to stdout. The help of `sfdupes` and of `scan`
names the database. The help of `report`, `trees`, `info` and `dwim` says what
each prints. `sfdupes scan --help` and `sfdupes dwim --help` also list the
default excludes of the system they run on, and the filesystem types the walk
never records anything on.
- `--help`, `-h`, alone or after a subcommand, prints the help text to stdout
and exits 0. It writes nothing to stderr. `sfdupes help` and
`sfdupes help COMMAND` do the same. The help of `sfdupes` and of `scan` names
the database. The help of `report`, `trees`, `info` and `dwim` says what each
prints. `sfdupes scan --help` and `sfdupes dwim --help` also list the default
excludes of the system they run on, and the filesystem types the walk never
records anything on.
### Duplicate detection