From a27d651532db5f4785ea5e04791fb0869f8d2c25 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Wed, 11 Nov 2026 05:37:23 +0100 Subject: [PATCH] scan: drop the stray [flags] from the usage line (closes #169) (#187) --- TODO.md | 3 +++ internal/sfdupes/cli.go | 11 +++++++---- internal/sfdupes/cli_test.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index e0cee09..94e5c67 100644 --- a/TODO.md +++ b/TODO.md @@ -29,6 +29,9 @@ Newest first. An entry ends with its date and its issue or branch, where those are known. +- The usage line of `scan` no longer ends in `[flags]`. It is the line + `README.md` shows under "Subcommands" (2026-11-11, + https://git.eeqj.de/sneak/sfdupes/issues/169) - `report` and `trees` leave out empty files. `report` writes no group of size 0, and `trees` writes no group whose trees hold 0 bytes. An empty file still counts toward a tree's digest (2026-11-11, diff --git a/internal/sfdupes/cli.go b/internal/sfdupes/cli.go index bc0539f..387a0b5 100644 --- a/internal/sfdupes/cli.go +++ b/internal/sfdupes/cli.go @@ -215,10 +215,13 @@ func newScanCommand() *cobra.Command { short := "Walk trees and synchronize the scan database" scanCmd := &cobra.Command{ - Use: cmdScan + " [--workers N] [-x] [--no-default-excludes] PATH...", - Short: short, - Long: short + ".\n\n" + defaultExcludesHelp(runtime.GOOS), - Args: cobra.MinimumNArgs(1), + Use: cmdScan + " [--workers N] [-x] [--no-default-excludes] PATH...", + // The Use line already names every flag, so cobra must not + // append its generic "[flags]" to it. + DisableFlagsInUseLine: true, + Short: short, + Long: short + ".\n\n" + defaultExcludesHelp(runtime.GOOS), + Args: cobra.MinimumNArgs(1), PreRunE: func(cmd *cobra.Command, _ []string) error { return checkScanWorkers(cmd, scanWorkers) }, diff --git a/internal/sfdupes/cli_test.go b/internal/sfdupes/cli_test.go index 6e65e7f..a56321e 100644 --- a/internal/sfdupes/cli_test.go +++ b/internal/sfdupes/cli_test.go @@ -714,6 +714,34 @@ func TestRunHelp(t *testing.T) { } } +func TestRunScanUsageLine(t *testing.T) { + t.Parallel() + + // README §Subcommands shows this usage line for scan, and the help + // and the usage error both print it. + const want = "\n sfdupes scan [--workers N] [-x] [--no-default-excludes] PATH...\n" + + cases := map[string][]string{ + "help": {cmdScan, "-h"}, + "missing paths": {cmdScan}, + } + + for name, args := range cases { + t.Run(name, func(t *testing.T) { + t.Parallel() + + var stdout, stderr bytes.Buffer + + run(args, &stdout, &stderr) + + if !strings.Contains(stderr.String(), want) { + t.Errorf("run(%v) stderr = %q, want the usage line %q", + args, stderr.String(), want) + } + }) + } +} + func TestRunVersion(t *testing.T) { t.Parallel()