diff --git a/README.md b/README.md index ea37d3f..98c379c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ dependencies. | `talk test` | speak a test sentence; shows provider and timings (`--lang`, `--provider`, `--voice`); `--toast` sends a test notification instead | | `talk doctor` | self-diagnosis: config, daemon, audio, providers, notifications, mute, laws (`--probe`, `--json`) | | `talk setup` | first-time setup in a few questions: language, voices with preview, quiet hours, config.toml | +| `talk version` | version and commit (also `talk --version`) | Say flags (also for `talk "text"`): `--wait`, `--now`, `--priority`, `--voice`, `--lang`, `--provider`. diff --git a/cmd/talk/cli.go b/cmd/talk/cli.go index dca823b..a61230d 100644 --- a/cmd/talk/cli.go +++ b/cmd/talk/cli.go @@ -112,6 +112,15 @@ var commands = []command{ detail: "Asks a few questions for what talk needs to get going: keys (optional; without a key the free Edge voice speaks), a voice per language with preview, quiet hours, and writes config.toml (an existing file is merged, backup .bak). Without a terminal: only shows the effective configuration.", handler: runSetup, }, + { + name: "version", + short: "show the version", + detail: "Prints the version and, when built from git, the commit. Same as `talk --version`; exists so that a bare `talk version` is not spoken as an announcement.", + handler: func(_ []string, _ *sayOptions, _ io.Reader, stdout, _ io.Writer) int { + fmt.Fprintln(stdout, versionString()) + return exitOK + }, + }, } // addSayFlags registers the say flags and binds them to the returned options diff --git a/cmd/talk/cli_test.go b/cmd/talk/cli_test.go index 32d7875..2cd0563 100644 --- a/cmd/talk/cli_test.go +++ b/cmd/talk/cli_test.go @@ -52,6 +52,18 @@ func TestVersionDefault(t *testing.T) { } } +// TestVersionSubcommand: `talk version` prints the version instead of +// speaking the word. +func TestVersionSubcommand(t *testing.T) { + var out, errBuf bytes.Buffer + if code := runCLI([]string{"version"}, &out, &errBuf); code != exitOK { + t.Fatalf("version: exit code = %d, stderr %q", code, errBuf.String()) + } + if got, want := out.String(), versionString()+"\n"; got != want { + t.Errorf("version output = %q, want %q", got, want) + } +} + func TestVersionStringWithCommit(t *testing.T) { oldCommit := commit commit = "c0ffee1"