Drop chcat/chtail/chgrep symlink entrypoints; ship chlog subcommands only
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

The RPM's /usr/bin/chcat conflicts with SELinux's
policycoreutils-python-utils on Fedora. Per Ben: remove the symlink
entrypoints entirely and ship only the chlog binary with cat/tail/grep
subcommands.

- Remove chcat/chtail/chgrep symlinks and their completions from
  nfpm.yaml, build-rpm.sh and the Makefile
- Remove the argv[0] dispatch in main.go; subcommands are unchanged
- Update the completion test to cover chlog only
- Update README usage to chlog cat|tail|grep
This commit is contained in:
2026-08-23 21:39:17 +10:00
parent dfd4efd782
commit ee2f270abc
8 changed files with 60 additions and 145 deletions
+21 -28
View File
@@ -1,7 +1,6 @@
package main
import (
"os"
"strings"
"testing"
"time"
@@ -41,7 +40,7 @@ func TestCommonFlagsFilterDefaults(t *testing.T) {
}
func TestGrepGuardBlocksWideUnfilteredSearch(t *testing.T) {
cmd := newGrepCmd("chgrep")
cmd := newGrepCmd()
cmd.SetArgs([]string{"--since", "24h", "needle"})
var out strings.Builder
cmd.SetOut(&out)
@@ -56,7 +55,7 @@ func TestGrepGuardAllowsFilteredSearch(t *testing.T) {
// A namespace filter disables the guard; the query then fails on the
// unreachable server rather than the guard, proving the guard passed.
t.Setenv("CH_URL", "http://127.0.0.1:1")
cmd := newGrepCmd("chgrep")
cmd := newGrepCmd()
cmd.SetArgs([]string{"--since", "24h", "--namespace", "logging", "needle"})
var out strings.Builder
cmd.SetOut(&out)
@@ -72,7 +71,7 @@ func TestGrepGuardAllowsFilteredSearch(t *testing.T) {
func TestGrepGuardAllowsShortWindow(t *testing.T) {
t.Setenv("CH_URL", "http://127.0.0.1:1")
cmd := newGrepCmd("chgrep")
cmd := newGrepCmd()
cmd.SetArgs([]string{"--since", "1h", "needle"})
err := cmd.Execute()
if err == nil {
@@ -83,33 +82,27 @@ func TestGrepGuardAllowsShortWindow(t *testing.T) {
}
}
func TestCompletionAllEntrypointsAndShells(t *testing.T) {
// scripts/build-rpm.sh runs "<name> completion <shell>" for every
// entrypoint; guard that each argv[0]-dispatched command tree exposes a
// working completion subcommand for all three packaged shells.
for _, name := range []string{"chlog", "chcat", "chtail", "chgrep"} {
for _, shell := range []string{"bash", "zsh", "fish"} {
t.Run(name+"/"+shell, func(t *testing.T) {
orig := os.Args
os.Args = []string{name}
defer func() { os.Args = orig }()
cmd := entrypoint()
var out strings.Builder
cmd.SetOut(&out)
cmd.SetErr(&out)
cmd.SetArgs([]string{"completion", shell})
if err := cmd.Execute(); err != nil {
t.Fatalf("%s completion %s: %v", name, shell, err)
}
if !strings.Contains(out.String(), name) {
t.Fatalf("%s completion %s output does not mention %q", name, shell, name)
}
})
}
func TestCompletionAllShells(t *testing.T) {
// scripts/build-rpm.sh runs "chlog completion <shell>"; guard that a
// working completion subcommand exists for all three packaged shells.
for _, shell := range []string{"bash", "zsh", "fish"} {
t.Run(shell, func(t *testing.T) {
cmd := newRootCmd()
var out strings.Builder
cmd.SetOut(&out)
cmd.SetErr(&out)
cmd.SetArgs([]string{"completion", shell})
if err := cmd.Execute(); err != nil {
t.Fatalf("chlog completion %s: %v", shell, err)
}
if !strings.Contains(out.String(), "chlog") {
t.Fatalf("chlog completion %s output does not mention chlog", shell)
}
})
}
}
func TestEntrypointDispatch(t *testing.T) {
func TestRootSubcommands(t *testing.T) {
root := newRootCmd()
names := map[string]bool{}
for _, c := range root.Commands() {