Skip to content

Commit

Permalink
Add parseStringArg to simplify parseArgs
Browse files Browse the repository at this point in the history
Resolves: #1386 (comment)
  • Loading branch information
inancgumus committed Jun 13, 2024
1 parent 08a2f02 commit 0fb3063
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,7 @@ func parseArgs(flags map[string]any) ([]string, error) {
for name, value := range flags {
switch value := value.(type) {
case string:
var arg string
if strings.TrimSpace(value) != "" {
arg = fmt.Sprintf("--%s=%s", name, value)
} else {
// If the value is empty, we don't include it in the args list.
// Otherwise, it will produce "--name=" which is invalid.
arg = fmt.Sprintf("--%s", name)
}
args = append(args, arg)
args = append(args, parseStringArg(name, value))
case bool:
if value {
args = append(args, fmt.Sprintf("--%s", name))
Expand All @@ -332,6 +324,15 @@ func parseArgs(flags map[string]any) ([]string, error) {
return args, nil
}

func parseStringArg(flag string, value string) string {
if strings.TrimSpace(value) == "" {
// If the value is empty, we don't include it in the args list.
// Otherwise, it will produce "--name=" which is invalid.
return fmt.Sprintf("--%s", flag)
}
return fmt.Sprintf("--%s=%s", flag, value)
}

func prepareFlags(lopts *common.BrowserOptions, k6opts *k6lib.Options) (map[string]any, error) {
// After Puppeteer's and Playwright's default behavior.
f := map[string]any{
Expand Down

0 comments on commit 0fb3063

Please sign in to comment.