Skip to content

feat: wire the cdd CLI (cdd, init, scan, version) - #41

Merged
hammadmajid merged 6 commits into
mainfrom
feat/cli
Sep 16, 2026
Merged

hammadmajid merged 6 commits into
mainfrom
feat/cli

Conversation

@hammadmajid

Copy link
Copy Markdown
Contributor

What

Wires internal/cli to github.com/spf13/cobra: the root cdd command
(bare behaves as pick), pick [query], init <shell>, scan,
version, plus cobra's own help and completion commands. Flags
--help/-h and --version/-V (the latter prints the same output as
cdd version).

  • pick loads config, opens History at its default path, and resolves the
    query via jump.Resolve + picker.Run, printing only the chosen
    Project's absolute path (plus newline) to stdout. A cancelled Picker
    exits 130 silently; any other error exits 1 with a stderr message. When
    stdout is a terminal, a stderr hint suggests installing the Wrapper via
    cdd init <shell> | source.
  • init requires exactly one shell argument (fish, bash, zsh),
    otherwise exits 2 listing them. The Wrapper's pass-through list is
    derived from the cobra command tree (every command name except pick),
    so help and completion forward without hand maintenance.
  • scan prints Seeded N Visits across M Projects and exits 0.
  • version formats version/commit/date (same var names the scaffold
    and .goreleaser.yaml already reference via ldflags), falling back to
    cdd dev (dev) for local builds.
  • Usage errors (unknown command/flag, wrong argument count, unsupported
    shell) exit 2; runtime errors exit 1 with a stderr message; a cancelled
    Picker exits 130 with no message.

internal/cli.Run(args, stdout, stderr) int is exported alongside
Execute() so tests drive the command tree in-process with cobra's
SetArgs and captured buffers, rather than exec'ing a built binary.

Testing

go build ./... && go vet ./... && go test ./... all pass. Table-driven
tests in internal/cli/cli_test.go cover version formatting and its
flag aliases, unknown command/flag exit codes, init's usage errors and
tree-derived passthrough list, pick/scan arg-count usage errors, and
help output.

Closes #21

🤖 Generated with Claude Code

hammadmajid and others added 6 commits September 17, 2026 01:16
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Builds the cobra command tree, an exported Run(args, stdout, stderr)
so tests can drive it in-process, and exit-code classification
(0/130/1/2) per the command surface decision. version/commit/date
stay the ldflags var names the scaffold and .goreleaser.yaml expect.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pick loads config, opens History at its default path, and resolves
the query to a Project via jump.Resolve and picker.Run, printing
only the absolute path to stdout. The bare root command shares this
RunE. A cancelled Picker is reported by Run as a silent exit 130.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Prints "Seeded N Visits across M Projects" from scan.Run's Summary.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Requires exactly one shell argument in fish, bash, zsh (usage error
otherwise) and renders the Wrapper via shell.Script, passing a
pass-through list built from the cobra command tree so help and
completion forward without hand maintenance.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Drives cli.Run in-process with cobra's SetArgs and captured
stdout/stderr: version formatting and its --version/-V aliases,
unknown command/flag exit 2, init's usage errors and tree-derived
passthrough list, pick/scan arg-count usage errors, and help.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@hammadmajid
hammadmajid merged commit 5ce0209 into main Sep 16, 2026
2 of 3 checks passed
@hammadmajid
hammadmajid deleted the feat/cli branch September 16, 2026 20:27
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.

Wire the CLI: cdd, init, scan, version

1 participant