Skip to content

Commit 1b7fd75

Browse files
Hide flag placeholder annotation key (#508)
This introduces `setFlagPlaceholder` and replaces all direct calls to `setAnnotationBestEffort`. It bugged me that _every_ call site of `setAnnotationBestEffort` needs to know about the `flagPlaceholderAnnotation` constant. I wanted that constant to instead be an implementation detail of a more ergonomic, semanitcally-named function that does one thing. GitOrigin-RevId: d6d62968500d7a06c97b7ce5564d94b606ae7f08
1 parent 5f18e09 commit 1b7fd75

27 files changed

Lines changed: 99 additions & 103 deletions

cmd/blueprintvalidate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Validates:
4646
func init() {
4747
blueprintsCmd.AddCommand(blueprintValidateCmd)
4848
blueprintValidateCmd.Flags().StringP("workspace", "w", "", "Validate against the specified workspace ID (defaults to current workspace)")
49-
setAnnotationBestEffort(blueprintValidateCmd.Flags(), "workspace", command.FlagPlaceholderAnnotation, []string{"WORKSPACE_ID"})
49+
setFlagPlaceholder(blueprintValidateCmd.Flags(), "workspace", "WORKSPACE_ID")
5050
}
5151

5252
func runBlueprintValidate(ctx context.Context, cmd *cobra.Command, args []string) error {

cmd/deploycreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ func init() {
105105
deployCreateCmd.Flags().String("commit", "", "Deploy the specified commit ID")
106106
deployCreateCmd.Flags().String("image", "", "Deploy the specified Docker image URL")
107107
deployCreateCmd.Flags().Bool("wait", false, "Wait for deploy completion and exit non-zero if deploy fails")
108-
setAnnotationBestEffort(deployCreateCmd.Flags(), "commit", command.FlagPlaceholderAnnotation, []string{"COMMIT_ID"})
109-
setAnnotationBestEffort(deployCreateCmd.Flags(), "image", command.FlagPlaceholderAnnotation, []string{"IMAGE_URL"})
108+
setFlagPlaceholder(deployCreateCmd.Flags(), "commit", "COMMIT_ID")
109+
setFlagPlaceholder(deployCreateCmd.Flags(), "image", "IMAGE_URL")
110110

111111
deployCmd.AddCommand(deployCreateCmd)
112112
rootCmd.AddCommand(deployCmd)

cmd/flagusages.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"strings"
77

88
"github.com/charmbracelet/lipgloss"
9-
"github.com/render-oss/cli/pkg/command"
109
"github.com/render-oss/cli/pkg/style"
1110
"github.com/spf13/pflag"
1211
)
1312

1413
const (
1514
placeholderEnvIDs = "ENV_IDS"
15+
16+
flagPlaceholderAnnotation = "render.placeholder"
1617
)
1718

1819
// setAnnotationBestEffort applies annotation metadata without failing command initialization.
@@ -27,11 +28,17 @@ func setAnnotationBestEffort(flags *pflag.FlagSet, flagName, key string, values
2728
return flags.SetAnnotation(flagName, key, values) == nil
2829
}
2930

31+
// setFlagPlaceholder applies help-output placeholder metadata to a flag.
32+
// Returns true when the placeholder was applied successfully, false otherwise.
33+
func setFlagPlaceholder(flags *pflag.FlagSet, flagName, placeholder string) bool {
34+
return setAnnotationBestEffort(flags, flagName, flagPlaceholderAnnotation, []string{placeholder})
35+
}
36+
3037
func placeholderFromAnnotation(flag *pflag.Flag) (string, bool) {
3138
if flag == nil || flag.Annotations == nil {
3239
return "", false
3340
}
34-
values, ok := flag.Annotations[command.FlagPlaceholderAnnotation]
41+
values, ok := flag.Annotations[flagPlaceholderAnnotation]
3542
if !ok || len(values) == 0 || values[0] == "" {
3643
return "", false
3744
}

cmd/jobcreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ func init() {
9797

9898
JobCreateCmd.Flags().String("start-command", "", "Set the job start command")
9999
JobCreateCmd.Flags().String("plan-id", "", "Set the plan ID for the job (Optional)")
100-
setAnnotationBestEffort(JobCreateCmd.Flags(), "start-command", command.FlagPlaceholderAnnotation, []string{"COMMAND"})
101-
setAnnotationBestEffort(JobCreateCmd.Flags(), "plan-id", command.FlagPlaceholderAnnotation, []string{"PLAN_ID"})
100+
setFlagPlaceholder(JobCreateCmd.Flags(), "start-command", "COMMAND")
101+
setFlagPlaceholder(JobCreateCmd.Flags(), "plan-id", "PLAN_ID")
102102
}

cmd/logs.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ In interactive mode you can update the filters and view logs in real time, or se
8787
logCmd.Flags().Bool("tail", false, "Stream new logs")
8888
logCmd.Flags().StringSlice("task-id", []string{}, "Filter logs by comma-separated task IDs")
8989
logCmd.Flags().StringSlice("task-run-id", []string{}, "Filter logs by comma-separated task run IDs")
90-
setAnnotationBestEffort(logCmd.Flags(), "resources", command.FlagPlaceholderAnnotation, []string{"RESOURCE_IDS"})
91-
setAnnotationBestEffort(logCmd.Flags(), "start", command.FlagPlaceholderAnnotation, []string{"TIME"})
92-
setAnnotationBestEffort(logCmd.Flags(), "end", command.FlagPlaceholderAnnotation, []string{"TIME"})
93-
setAnnotationBestEffort(logCmd.Flags(), "text", command.FlagPlaceholderAnnotation, []string{"QUERY_TEXT"})
94-
setAnnotationBestEffort(logCmd.Flags(), "level", command.FlagPlaceholderAnnotation, []string{"LOG_LEVEL"})
95-
setAnnotationBestEffort(logCmd.Flags(), "type", command.FlagPlaceholderAnnotation, []string{"LOG_TYPE"})
96-
setAnnotationBestEffort(logCmd.Flags(), "instance", command.FlagPlaceholderAnnotation, []string{"INSTANCE_IDS"})
97-
setAnnotationBestEffort(logCmd.Flags(), "host", command.FlagPlaceholderAnnotation, []string{"HOSTS"})
98-
setAnnotationBestEffort(logCmd.Flags(), "status-code", command.FlagPlaceholderAnnotation, []string{"STATUS_CODES"})
99-
setAnnotationBestEffort(logCmd.Flags(), "method", command.FlagPlaceholderAnnotation, []string{"HTTP_METHOD"})
100-
setAnnotationBestEffort(logCmd.Flags(), "path", command.FlagPlaceholderAnnotation, []string{"PATHS"})
101-
setAnnotationBestEffort(logCmd.Flags(), "limit", command.FlagPlaceholderAnnotation, []string{"COUNT"})
102-
setAnnotationBestEffort(logCmd.Flags(), "direction", command.FlagPlaceholderAnnotation, []string{"LOG_DIRECTION"})
103-
setAnnotationBestEffort(logCmd.Flags(), "task-id", command.FlagPlaceholderAnnotation, []string{"TASK_IDS"})
104-
setAnnotationBestEffort(logCmd.Flags(), "task-run-id", command.FlagPlaceholderAnnotation, []string{"TASK_RUN_IDS"})
90+
setFlagPlaceholder(logCmd.Flags(), "resources", "RESOURCE_IDS")
91+
setFlagPlaceholder(logCmd.Flags(), "start", "TIME")
92+
setFlagPlaceholder(logCmd.Flags(), "end", "TIME")
93+
setFlagPlaceholder(logCmd.Flags(), "text", "QUERY_TEXT")
94+
setFlagPlaceholder(logCmd.Flags(), "level", "LOG_LEVEL")
95+
setFlagPlaceholder(logCmd.Flags(), "type", "LOG_TYPE")
96+
setFlagPlaceholder(logCmd.Flags(), "instance", "INSTANCE_IDS")
97+
setFlagPlaceholder(logCmd.Flags(), "host", "HOSTS")
98+
setFlagPlaceholder(logCmd.Flags(), "status-code", "STATUS_CODES")
99+
setFlagPlaceholder(logCmd.Flags(), "method", "HTTP_METHOD")
100+
setFlagPlaceholder(logCmd.Flags(), "path", "PATHS")
101+
setFlagPlaceholder(logCmd.Flags(), "limit", "COUNT")
102+
setFlagPlaceholder(logCmd.Flags(), "direction", "LOG_DIRECTION")
103+
setFlagPlaceholder(logCmd.Flags(), "task-id", "TASK_IDS")
104+
setFlagPlaceholder(logCmd.Flags(), "task-run-id", "TASK_RUN_IDS")
105105

106106
return logCmd
107107
}

cmd/object.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cmd
22

3-
import (
4-
"github.com/render-oss/cli/pkg/command"
5-
"github.com/spf13/cobra"
6-
)
3+
import "github.com/spf13/cobra"
74

85
var objectCmd = &cobra.Command{
96
Use: "objects",
@@ -32,7 +29,7 @@ func init() {
3229
// Add persistent flags shared by all object commands
3330
objectCmd.PersistentFlags().String("region", "", "Set target region (or set the RENDER_REGION env var)")
3431
objectCmd.PersistentFlags().Bool("local", false, "Use local storage (.render/objects/) instead of cloud storage")
35-
setAnnotationBestEffort(objectCmd.PersistentFlags(), "region", command.FlagPlaceholderAnnotation, []string{"REGION"})
32+
setFlagPlaceholder(objectCmd.PersistentFlags(), "region", "REGION")
3633

3734
EarlyAccessCmd.AddCommand(objectCmd)
3835
}

cmd/objectlist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func listObjects(cmd *cobra.Command, input ObjectListInput) ([]storage.ObjectInf
9595

9696
func init() {
9797
objectListCmd.Flags().Int("limit", 100, "Limit the number of objects returned")
98-
setAnnotationBestEffort(objectListCmd.Flags(), "limit", command.FlagPlaceholderAnnotation, []string{"COUNT"})
98+
setFlagPlaceholder(objectListCmd.Flags(), "limit", "COUNT")
9999

100100
objectCmd.AddCommand(objectListCmd)
101101
}

cmd/objectput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func init() {
108108
objectPutCmd.Flags().StringP("file", "f", "", "Path to the local file to upload (Required)")
109109
objectPutCmd.MarkFlagRequired("file")
110110
objectPutCmd.MarkFlagFilename("file")
111-
setAnnotationBestEffort(objectPutCmd.Flags(), "file", command.FlagPlaceholderAnnotation, []string{"PATH"})
111+
setFlagPlaceholder(objectPutCmd.Flags(), "file", "PATH")
112112

113113
objectCmd.AddCommand(objectPutCmd)
114114
}

cmd/psql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func init() {
7070
rootCmd.AddCommand(psqlCmd)
7171

7272
psqlCmd.Flags().StringP("command", "c", "", "Execute a SQL command in non-interactive mode")
73-
setAnnotationBestEffort(psqlCmd.Flags(), "command", command.FlagPlaceholderAnnotation, []string{"SQL"})
73+
setFlagPlaceholder(psqlCmd.Flags(), "command", "SQL")
7474

7575
psqlCmd.RunE = func(cmd *cobra.Command, args []string) error {
7676
ctx := cmd.Context()

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func newRootCmd() *cobra.Command {
8585
root.Version = cfg.Version
8686
root.CompletionOptions.DisableDefaultCmd = true
8787
root.PersistentFlags().StringP("output", "o", "interactive", "Set output format to interactive, json, yaml, or text. Auto-switches to text on non-TTY")
88-
setAnnotationBestEffort(root.PersistentFlags(), "output", command.FlagPlaceholderAnnotation, []string{command.OutputPlaceholder})
88+
setFlagPlaceholder(root.PersistentFlags(), "output", command.OutputPlaceholder)
8989
root.PersistentFlags().Bool(command.ConfirmFlag, false, "Skip all confirmation prompts")
9090

9191
// Flags from the old CLI that we error with a helpful message.

0 commit comments

Comments
 (0)