Skip to content

Document the show flags that exist, and fix what -top claims to do. - #80

Merged
xbmlz merged 1 commit into
mainfrom
docs/cli-flags-and-dead-code
Aug 25, 2026
Merged

xbmlz merged 1 commit into
mainfrom
docs/cli-flags-and-dead-code

Conversation

@xbmlz

@xbmlz xbmlz commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

printUsage listed only -debug. show had grown -no-meta, -top, -t and -tag since, and nothing tied the usage text to the flag set, so the text simply stopped being true. All five are documented now, in the usage text and in the README's CLI section.

Usage: godicom <command> [flags] [args...]
Commands:
  show [flags] <file>  - Display DICOM file (file meta + dataset)
  read [flags] <file>  - Alias for show
  readcopy <src> <dst> - Read then write DICOM file
Flags for show and read:
  -no-meta             - Skip file meta information
  -top                 - Restrict -t to the top level, skipping sequences
  -debug               - Emit reader debug logs to stderr
  -t <tag>             - Show only this tag; keyword or hex (repeatable)
  -tag <tag>           - Alias for -t

Keeping it true

TestPrintUsageMatchesShowFlags enumerates the real flag set — via a newShowFlagSet extracted from runShow, not a hand-maintained copy — and fails in both directions: a registered flag the text omits, and a documented flag that no longer exists. Both are the same bug.

Each direction was confirmed to fail rather than assumed:

Perturbation Result
Delete the -t line, keep -tag -t is registered but printUsage does not document it
Add a -nope line printUsage documents -nope but no such flag is registered

The first case is why the match uses \b: without it, the -tag line would count as documenting -t.

-top did not do what it said

Its description was "only show top-level elements", which reads as a change to the default output. It is not. Plain show lists the top level and reports a sequence by item count without descending into it either way. What -top does is narrow the -t search to the top level — and without -t it does nothing at all.

TestWriteShowTopLevel had been asserting the flag's behaviour against a nil tag filter, which takes the non-recursive path regardless. So it passed just as well with topLevel unset, and had never actually checked the flag. That is how the wrong description survived. It now contrasts a filtered search with and without -top across four cases, and the two filtered ones expect opposite results. Flipping one topLevel back to false fails it, so it is not vacuous.

Verified against pydicom's rtplan.dcm rather than reasoned about:

$ godicom show -no-meta -t TreatmentMachineName rtplan.dcm
(300A,00B2) Treatment Machine Name              SH: unit001
Matching elements: 1

$ godicom show -no-meta -t TreatmentMachineName -top rtplan.dcm
Matching elements: 0

The README's examples are commands that were actually run. An earlier draft used CodeValue, which that file does not contain at all — both halves returned zero matches and demonstrated nothing. Probing parseShowTags the same way also turned up something worth documenting: PatientName, 00080060 and "(0008,0060)" all parse, but a bare 0008,0060 does not, so the README now says the comma form needs the parentheses.

Also

Drops var _ = regexp.Compile from dictionary.go. Its comment claimed it forced an init for the regexp import, which regexp has no need of; nothing else in the file used the package, so the import went too.

Gate

go build, go vet, staticcheck -checks=all (the exact CI invocation), gofmt, go test -count=1 -p 4 ./... and GOARCH=386 CGO_ENABLED=0 go test ./... — all clean, 7 packages ok on both architectures.

🤖 Generated with Claude Code

printUsage listed only -debug. show had grown -no-meta, -top, -t and -tag
since, and nothing tied the usage text to the flag set, so the text simply
stopped being true. All five are documented now, in the usage text and in
the README's CLI section.

TestPrintUsageMatchesShowFlags keeps them in step. It enumerates the real
flag set via a newShowFlagSet extracted from runShow, and fails in both
directions: a registered flag the text omits, and a documented flag that no
longer exists. Both are the same bug. The \b in the match matters -- without
it the -tag line would count as documenting -t.

-top's description was also wrong, in a way worth naming. It said "only show
top-level elements", which reads as a change to the default output. It is
not: plain show lists the top level and reports a sequence by item count
without descending into it either way. What -top does is narrow the -t
search to the top level, and without -t it does nothing at all.

TestWriteShowTopLevel had been asserting the flag's behaviour against a nil
tag filter, which takes the non-recursive path regardless -- so it passed
just as well with topLevel unset, and had never checked the flag. That is
how the wrong description survived. It now contrasts a filtered search with
and without -top over four cases, and the two filtered ones expect opposite
results.

Verified against pydicom's rtplan.dcm rather than assumed: -t
TreatmentMachineName finds the element inside BeamSequence, and with -top
finds nothing. The README's examples are commands that were actually run;
an earlier draft used CodeValue, which that file does not contain at all, so
both halves returned zero matches and demonstrated nothing.

Also drops `var _ = regexp.Compile` from dictionary.go. Its comment claimed
it forced an init for the regexp import, which regexp has no need of;
nothing else in the file used the package, so the import went too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@xbmlz
xbmlz merged commit 27240a9 into main Aug 25, 2026
6 checks passed
@xbmlz
xbmlz deleted the docs/cli-flags-and-dead-code branch August 25, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant