Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 0fb3063

Browse files
committed
Add parseStringArg to simplify parseArgs
Resolves: #1386 (comment)
1 parent 08a2f02 commit 0fb3063

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

chromium/browser_type.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,7 @@ func parseArgs(flags map[string]any) ([]string, error) {
304304
for name, value := range flags {
305305
switch value := value.(type) {
306306
case string:
307-
var arg string
308-
if strings.TrimSpace(value) != "" {
309-
arg = fmt.Sprintf("--%s=%s", name, value)
310-
} else {
311-
// If the value is empty, we don't include it in the args list.
312-
// Otherwise, it will produce "--name=" which is invalid.
313-
arg = fmt.Sprintf("--%s", name)
314-
}
315-
args = append(args, arg)
307+
args = append(args, parseStringArg(name, value))
316308
case bool:
317309
if value {
318310
args = append(args, fmt.Sprintf("--%s", name))
@@ -332,6 +324,15 @@ func parseArgs(flags map[string]any) ([]string, error) {
332324
return args, nil
333325
}
334326

327+
func parseStringArg(flag string, value string) string {
328+
if strings.TrimSpace(value) == "" {
329+
// If the value is empty, we don't include it in the args list.
330+
// Otherwise, it will produce "--name=" which is invalid.
331+
return fmt.Sprintf("--%s", flag)
332+
}
333+
return fmt.Sprintf("--%s=%s", flag, value)
334+
}
335+
335336
func prepareFlags(lopts *common.BrowserOptions, k6opts *k6lib.Options) (map[string]any, error) {
336337
// After Puppeteer's and Playwright's default behavior.
337338
f := map[string]any{

0 commit comments

Comments
 (0)