Skip to content

Commit be6e7aa

Browse files
committed
PR feedback
1 parent f6e8702 commit be6e7aa

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

cmd/config/plugins/add.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ in the category, the command fails with an error. To update an existing plugin,
8585
&c.flows,
8686
flagFlow,
8787
nil,
88-
"Flow to execute plugin in: request, response (can be repeated)",
88+
fmt.Sprintf(
89+
"Flow during which, the plugin should execute (%s) (can be repeated)",
90+
strings.Join(OrderedFlowNames(), ", "),
91+
),
8992
)
9093
_ = cobraCmd.MarkFlagRequired(flagFlow)
9194

@@ -128,16 +131,14 @@ func (c *AddCmd) run(cmd *cobra.Command, args []string) error {
128131
)
129132
}
130133

131-
flowsMap := config.ParseFlows(c.flows)
132-
if len(flowsMap) == 0 {
133-
return fmt.Errorf("at least one valid flow is required (must be 'request' or 'response')")
134+
flows := config.ParseFlowsDistinct(c.flows)
135+
if len(flows) == 0 {
136+
return fmt.Errorf("at least one valid flow is required (%s)", strings.Join(OrderedFlowNames(), ", "))
134137
}
135138

136-
parsedFlows := slices.Sorted(maps.Keys(flowsMap))
137-
138139
entry := config.PluginEntry{
139140
Name: pluginName,
140-
Flows: parsedFlows,
141+
Flows: slices.Sorted(maps.Keys(flows)),
141142
}
142143

143144
// Set optional fields only if they were provided.
@@ -162,3 +163,15 @@ func (c *AddCmd) run(cmd *cobra.Command, args []string) error {
162163

163164
return nil
164165
}
166+
167+
// OrderedFlowNames returns the names of allowed flows in order.
168+
func OrderedFlowNames() []string {
169+
flows := slices.Sorted(maps.Keys(config.Flows()))
170+
171+
flowNames := make([]string, len(flows))
172+
for i, f := range flows {
173+
flowNames[i] = string(f)
174+
}
175+
176+
return flowNames
177+
}

cmd/config/plugins/add_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,10 @@ func TestAddCmd_RequiredFalseExplicitlySet(t *testing.T) {
358358
require.NotNil(t, authPlugins[0].Required)
359359
require.False(t, *authPlugins[0].Required)
360360
}
361+
362+
func TestAddCmd_OrderedFlowNames(t *testing.T) {
363+
flows := OrderedFlowNames()
364+
require.Len(t, flows, 2)
365+
require.Equal(t, "request", flows[0])
366+
require.Equal(t, "response", flows[1])
367+
}

internal/config/plugin_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ func (f Flow) IsValid() bool {
9999
return ok
100100
}
101101

102-
// ParseFlows validates and reduces flow strings to a distinct set.
102+
// ParseFlowsDistinct validates and reduces flow strings to a distinct set.
103103
// Flow strings are normalized before validation.
104104
// Invalid flows are silently ignored. Returns an empty map if no valid flows are found.
105-
func ParseFlows(flags []string) map[Flow]struct{} {
105+
func ParseFlowsDistinct(flags []string) map[Flow]struct{} {
106106
valid := make(map[Flow]struct{}, len(flows))
107107

108108
for _, s := range flags {

internal/config/plugin_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ func TestParseFlows(t *testing.T) {
866866
t.Run(tc.name, func(t *testing.T) {
867867
t.Parallel()
868868

869-
result := ParseFlows(tc.input)
869+
result := ParseFlowsDistinct(tc.input)
870870
require.Equal(t, tc.expected, result)
871871
})
872872
}

0 commit comments

Comments
 (0)