hide policy command during development · Entire

hide policy command during development

99336ff·

pfleidi·3w ago·2 files·+25 added/-2 removed

Keep the repo policy command invokable while removing it from help output until the surface is ready.

Add command-tree coverage so the hidden group remains callable through its checkpoint subcommand.

Sessions

99b815203b44View transcript

Changes

2

8 unmodified lines

9
10
11
12
13
12
13
14
15
16
17

8 unmodified lines

func newPolicyCmd() *cobra.Command {
    cmd := &cobra.Command{
        Use:   "policy",
        Short: "Manage repo-wide Entire policies",
        Use:    "policy",
        Short:  "Manage repo-wide Entire policies",
        Hidden: true,
        PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
            if _, err := paths.WorktreeRoot(cmd.Context()); err != nil {
                return errors.New("not a git repository")
            }

Mcmd/entire/cli/policy_group.go+3/-2

233 unmodified lines

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261

233 unmodified lines

}
}

func TestPolicyCommandIsHiddenDuringDevelopment(t *testing.T) {

t.Parallel()

root := NewRootCmd()

policy, _, err := root.Find([]string{"policy"})
    if err != nil {
        t.Fatalf("find policy command: %v", err)
    }
    if !policy.Hidden {
        t.Fatal("policy command should be hidden while it is in active development")
    }

checkpointPolicy, _, err := root.Find([]string{"policy", "checkpoint"})
    if err != nil {
        t.Fatalf("find policy checkpoint command: %v", err)
    }
    if checkpointPolicy.Hidden {
        t.Fatal("policy checkpoint should remain invokable through the hidden policy group")
    }
}

func containsString(values []string, want string) bool {
    for _, value := range values {
        if value == want {