(deps commandDeps)
| 11 | ) |
| 12 | |
| 13 | func newOpenCommand(deps commandDeps) *cobra.Command { |
| 14 | return &cobra.Command{ |
| 15 | Use: "open", |
| 16 | Short: "Open the AGH web UI in the default browser", |
| 17 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 18 | ctx := cmd.Context() |
| 19 | |
| 20 | client, err := clientFromDeps(deps) |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | status, err := client.DaemonStatus(ctx) |
| 26 | if err != nil { |
| 27 | return fmt.Errorf("open: daemon is not running: %w", err) |
| 28 | } |
| 29 | if status.HTTPHost == "" || status.HTTPPort == 0 { |
| 30 | return errors.New("open: daemon did not report a valid HTTP address") |
| 31 | } |
| 32 | |
| 33 | url := fmt.Sprintf("http://%s:%d", status.HTTPHost, status.HTTPPort) |
| 34 | return openBrowser(ctx, url) |
| 35 | }, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func openBrowser(ctx context.Context, url string) error { |
| 40 | var cmd *exec.Cmd |
no test coverage detected