Problem
Today tracebloc cluster info redeclares --kubeconfig, --context, and --namespace as local flags. As we add more cluster-talking subcommands (dataset push, dataset list, future ingest status), each one will need the same three flags. Redeclaring per-command means:
- The same flag-declaration code gets copy-pasted 4+ times
- Help text drifts as docs are tweaked per command instead of in one place
- Default values can silently diverge
Fix
Promote --kubeconfig, --context, --namespace to persistent flags on either the root command or a clusterFlags middleware. Subcommands inherit them automatically.
Implementation sketch (internal/cli/root.go):
type GlobalFlags struct {
Kubeconfig string
Context string
Namespace string
}
func NewRootCmd(info BuildInfo) (*cobra.Command, *GlobalFlags) {
flags := &GlobalFlags{}
root := &cobra.Command{...}
root.PersistentFlags().StringVar(&flags.Kubeconfig, "kubeconfig", "", "...")
root.PersistentFlags().StringVar(&flags.Context, "context", "", "...")
root.PersistentFlags().StringVarP(&flags.Namespace, "namespace", "n", "", "...")
// Subcommands read flags via the struct rather than redeclaring.
root.AddCommand(newClusterCmd(flags))
...
return root, flags
}
Pass the flags struct through subcommand constructors so each can call cluster.Load(cluster.KubeconfigOptions{Path: flags.Kubeconfig, ...}) consistently.
Acceptance criteria
tracebloc --kubeconfig X cluster info and tracebloc cluster info --kubeconfig X both work
- Same for
--context and --namespace / -n
- Adding a new subcommand that talks to the cluster (Phase 3's
dataset push) requires zero per-command flag-declaration
- Existing
cluster info unit tests still pass
Found by
Self-review of PR #2 (Phase 2 cluster discovery). Filed as v0.2 polish so it doesn't gate the v0.1 push-only MVP.
Problem
Today
tracebloc cluster inforedeclares--kubeconfig,--context, and--namespaceas local flags. As we add more cluster-talking subcommands (dataset push,dataset list, futureingest status), each one will need the same three flags. Redeclaring per-command means:Fix
Promote
--kubeconfig,--context,--namespaceto persistent flags on either the root command or aclusterFlagsmiddleware. Subcommands inherit them automatically.Implementation sketch (internal/cli/root.go):
Pass the flags struct through subcommand constructors so each can call
cluster.Load(cluster.KubeconfigOptions{Path: flags.Kubeconfig, ...})consistently.Acceptance criteria
tracebloc --kubeconfig X cluster infoandtracebloc cluster info --kubeconfig Xboth work--contextand--namespace/-ndataset push) requires zero per-command flag-declarationcluster infounit tests still passFound by
Self-review of PR #2 (Phase 2 cluster discovery). Filed as v0.2 polish so it doesn't gate the v0.1 push-only MVP.