Skip to content

Commit fafa52e

Browse files
authored
Merge pull request #433 from gman0/bind-skip-browser
kubectl-bind: added --skip-browser flag
2 parents 0d49a65 + d196d14 commit fafa52e

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

cli/pkg/kubectl/bind/plugin/bind.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type BindOptions struct {
7979
// clusterIdentityNamespaceName is the namespace name from which the cluster identity will be generated.
8080
clusterIdentityNamespaceName string
8181

82+
// SkipBrowser skips opening the browser automatically.
83+
SkipBrowser bool
84+
8285
// Runner is runs the command. It can be replaced in tests.
8386
Runner func(cmd *exec.Cmd) error
8487

@@ -119,6 +122,7 @@ func (b *BindOptions) AddCmdFlags(cmd *cobra.Command) {
119122
cmd.Flags().MarkHidden("konnector-host-alias") //nolint:errcheck
120123
cmd.Flags().StringVarP(&b.ClusterIdentity, "cluster-identity", "", b.ClusterIdentity, "A unique identity for the cluster. If not provided, it will be generated based on the local cluster information. ")
121124
cmd.Flags().StringVarP(&b.clusterIdentityNamespaceName, "cluster-identity-namespace", "", b.clusterIdentityNamespaceName, "The namespace name from which the cluster identity will be generated. Only used if cluster-identity is not provided.")
125+
cmd.Flags().BoolVarP(&b.SkipBrowser, "skip-browser", "", false, "Skip opening the browser automatically")
122126
}
123127

124128
// Complete ensures all fields are initialized.
@@ -213,15 +217,19 @@ func (b *BindOptions) runWithCallback(ctx context.Context, _ chan<- string) erro
213217
return fmt.Errorf("failed to build UI URL: %w", err)
214218
}
215219

216-
fmt.Fprintf(b.Options.IOStreams.ErrOut, "🌐 Opening kube-bind UI in your browser...\n")
217-
fmt.Fprintf(b.Options.IOStreams.ErrOut, " %s\n\n", uiURL)
220+
if !b.SkipBrowser {
221+
fmt.Fprintf(b.Options.IOStreams.ErrOut, "🌐 Opening kube-bind UI in your browser...\n")
222+
fmt.Fprintf(b.Options.IOStreams.ErrOut, " %s\n\n", uiURL)
218223

219-
// Open browser
220-
if err := base.OpenBrowser(uiURL); err != nil {
221-
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Failed to open browser automatically: %v\n", err)
222-
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Please manually open: %s\n\n", uiURL)
224+
// Open browser
225+
if err := base.OpenBrowser(uiURL); err != nil {
226+
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Failed to open browser automatically: %v\n", err)
227+
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Please manually open: %s\n\n", uiURL)
228+
} else {
229+
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Browser opened successfully\n")
230+
}
223231
} else {
224-
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Browser opened successfully\n")
232+
fmt.Fprintf(b.Options.IOStreams.ErrOut, "\n\n🌐 Please manually open: %s\n\n", uiURL)
225233
}
226234

227235
fmt.Fprintf(b.Options.IOStreams.ErrOut, "Waiting for binding completion from UI...\n")

0 commit comments

Comments
 (0)