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
+8 -27
View File
@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
@@ -88,10 +87,10 @@ func (cf *commonFlags) formatter() (chlog.Formatter, error) {
return chlog.NewFormatter(cf.format, color)
}
func newCatCmd(use string) *cobra.Command {
func newCatCmd() *cobra.Command {
cf := &commonFlags{}
cmd := &cobra.Command{
Use: use,
Use: "cat",
Short: "Print logs from the ClickHouse log store, oldest first",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
@@ -114,10 +113,10 @@ func newCatCmd(use string) *cobra.Command {
return cmd
}
func newTailCmd(use string) *cobra.Command {
func newTailCmd() *cobra.Command {
cf := &commonFlags{}
cmd := &cobra.Command{
Use: use,
Use: "tail",
Short: "Follow logs from the ClickHouse log store",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
@@ -146,7 +145,7 @@ func newTailCmd(use string) *cobra.Command {
return cmd
}
func newGrepCmd(use string) *cobra.Command {
func newGrepCmd() *cobra.Command {
cf := &commonFlags{}
var (
regex bool
@@ -155,7 +154,7 @@ func newGrepCmd(use string) *cobra.Command {
force bool
)
cmd := &cobra.Command{
Use: use + " <pattern>",
Use: "grep <pattern>",
Short: "Search log messages in the ClickHouse log store",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -217,32 +216,14 @@ func newRootCmd() *cobra.Command {
SilenceUsage: true,
SilenceErrors: true,
}
root.AddCommand(newCatCmd("cat"), newTailCmd("tail"), newGrepCmd("grep"))
root.AddCommand(newCatCmd(), newTailCmd(), newGrepCmd())
return root
}
func entrypoint() *cobra.Command {
var cmd *cobra.Command
switch filepath.Base(os.Args[0]) {
case "chcat":
cmd = newCatCmd("chcat")
case "chtail":
cmd = newTailCmd("chtail")
case "chgrep":
cmd = newGrepCmd("chgrep")
default:
return newRootCmd()
}
cmd.Version = version
cmd.SilenceUsage = true
cmd.SilenceErrors = true
return cmd
}
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
if err := entrypoint().ExecuteContext(ctx); err != nil {
if err := newRootCmd().ExecuteContext(ctx); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}