MCPcopy Index your code
hub / github.com/docker/docker-agent / Open

Function Open

pkg/browser/browser.go:13–41  ·  view source on GitHub ↗
(ctx context.Context, urlToOpen string)

Source from the content-addressed store, hash-verified

11)
12
13func Open(ctx context.Context, urlToOpen string) error {
14 if err := validate(urlToOpen); err != nil {
15 return err
16 }
17
18 var cmd string
19 var args []string
20
21 switch runtime.GOOS {
22 case "windows":
23 cmd = "rundll32"
24 args = []string{"url.dll,FileProtocolHandler", urlToOpen}
25 case "darwin":
26 cmd = "open"
27 args = []string{urlToOpen}
28 case "linux":
29 cmd = "xdg-open"
30 args = []string{urlToOpen}
31 default:
32 return fmt.Errorf("unsupported platform: %s", runtime.GOOS)
33 }
34
35 err := exec.CommandContext(ctx, cmd, args...).Start()
36 if err != nil {
37 return fmt.Errorf("failed to open browser: %w", err)
38 }
39
40 return nil
41}
42
43// validate rejects inputs that are unsafe to hand to the platform "open"
44// helper (open, xdg-open, rundll32). Those helpers receive the URL as a

Callers 3

RequestAuthorizationCodeFunction · 0.92
handleOpenURLMethod · 0.92
openURLInBrowserMethod · 0.92

Calls 2

validateFunction · 0.85
StartMethod · 0.65

Tested by

no test coverage detected