Skip to content

Commit 450fbe7

Browse files
committed
small tweaks
1 parent 136945a commit 450fbe7

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

cmd/browsers.go

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/onkernel/kernel-go-sdk/shared"
2424
"github.com/pterm/pterm"
2525
"github.com/spf13/cobra"
26+
"github.com/spf13/pflag"
2627
)
2728

2829
// BrowsersService defines the subset of the Kernel SDK browser client that we use.
@@ -227,7 +228,7 @@ func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
227228
return nil
228229
}
229230

230-
if browsers == nil || len(browsers) == 0 {
231+
if len(browsers) == 0 {
231232
pterm.Info.Println("No running browsers found")
232233
return nil
233234
}
@@ -2100,33 +2101,39 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
21002101
}
21012102

21022103
if poolID != "" || poolName != "" {
2103-
conflictFlags := []string{
2104-
"persistent-id",
2105-
"stealth",
2106-
"headless",
2107-
"kiosk",
2108-
"timeout",
2109-
"profile-id",
2110-
"profile-name",
2111-
"save-changes",
2112-
"proxy-id",
2113-
"extension",
2114-
"viewport",
2115-
"viewport-interactive",
2104+
// When using a pool, configuration comes from the pool itself.
2105+
allowedFlags := map[string]bool{
2106+
"pool-id": true,
2107+
"pool-name": true,
2108+
"timeout": true,
2109+
// Global persistent flags that don't configure browsers
2110+
"no-color": true,
2111+
"log-level": true,
21162112
}
2113+
2114+
// Check if any browser configuration flags were set (which would conflict).
21172115
var conflicts []string
2118-
for _, name := range conflictFlags {
2119-
if cmd.Flags().Changed(name) {
2120-
conflicts = append(conflicts, "--"+name)
2116+
cmd.Flags().Visit(func(f *pflag.Flag) {
2117+
if !allowedFlags[f.Name] {
2118+
conflicts = append(conflicts, "--"+f.Name)
21212119
}
2122-
}
2120+
})
2121+
21232122
if len(conflicts) > 0 {
21242123
flagLabel := "--pool-id"
21252124
if poolName != "" {
21262125
flagLabel = "--pool-name"
21272126
}
2128-
pterm.Error.Printf("%s cannot be combined with %s\n", flagLabel, strings.Join(conflicts, ", "))
2129-
return nil
2127+
pterm.Warning.Printf("You specified %s, but also provided browser configuration flags: %s\n", flagLabel, strings.Join(conflicts, ", "))
2128+
pterm.Info.Println("When using a pool, all browser configuration comes from the pool itself.")
2129+
pterm.Info.Println("The conflicting flags will be ignored.")
2130+
2131+
result, _ := pterm.DefaultInteractiveConfirm.Show("Continue with pool configuration?")
2132+
if !result {
2133+
pterm.Info.Println("Cancelled. Remove conflicting flags or omit the pool flag.")
2134+
return nil
2135+
}
2136+
pterm.Success.Println("Proceeding with pool configuration...")
21302137
}
21312138

21322139
pool := poolID
@@ -2136,7 +2143,16 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
21362143

21372144
pterm.Info.Printf("Acquiring browser from pool %s...\n", pool)
21382145
poolSvc := client.BrowserPools
2139-
resp, err := (&poolSvc).Acquire(cmd.Context(), pool, kernel.BrowserPoolAcquireParams{})
2146+
2147+
req := kernel.BrowserPoolAcquireRequestParam{}
2148+
if cmd.Flags().Changed("timeout") && timeout > 0 {
2149+
req.AcquireTimeoutSeconds = kernel.Int(int64(timeout))
2150+
}
2151+
acquireParams := kernel.BrowserPoolAcquireParams{
2152+
BrowserPoolAcquireRequest: req,
2153+
}
2154+
2155+
resp, err := (&poolSvc).Acquire(cmd.Context(), pool, acquireParams)
21402156
if err != nil {
21412157
return util.CleanedUpSdkError{Err: err}
21422158
}

0 commit comments

Comments
 (0)