From 7236f6558e88d23fd5bb8ba6129688cea1b5ad81 Mon Sep 17 00:00:00 2001 From: Brandt Keller <43887158+brandtkeller@users.noreply.github.com> Date: Wed, 12 Feb 2025 08:38:56 -0800 Subject: [PATCH] feat(connect): update default behavior to be cli-only (#3487) Signed-off-by: Brandt Keller Signed-off-by: Austin Abro Signed-off-by: dependabot[bot] Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- site/src/content/docs/commands/zarf_connect.md | 2 +- src/cmd/connect.go | 15 ++++++++------- src/config/lang/english.go | 2 +- src/test/e2e/09_component_compose_test.go | 12 +++++++++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/site/src/content/docs/commands/zarf_connect.md b/site/src/content/docs/commands/zarf_connect.md index 42df6defd6..49b8eff6ee 100644 --- a/site/src/content/docs/commands/zarf_connect.md +++ b/site/src/content/docs/commands/zarf_connect.md @@ -27,11 +27,11 @@ zarf connect { REGISTRY | GIT | connect-name } [flags] ### Options ``` - --cli-only Disable browser auto-open -h, --help help for connect --local-port int (Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000. --name string Specify the resource name. E.g. name=unicorns or name=unicorn-pod-7448499f4d-b5bk6. Ignored if connect-name is supplied. --namespace string Specify the namespace. E.g. namespace=default. Ignored if connect-name is supplied. (default "zarf") + --open Enable browser auto-open --remote-port int Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if connect-name is supplied. --type string Specify the resource type. E.g. type=svc or type=pod. Ignored if connect-name is supplied. (default "svc") ``` diff --git a/src/cmd/connect.go b/src/cmd/connect.go index 57ca3d0479..83ed0584dc 100644 --- a/src/cmd/connect.go +++ b/src/cmd/connect.go @@ -17,8 +17,8 @@ import ( ) type connectOptions struct { - cliOnly bool - zt cluster.TunnelInfo + open bool + zt cluster.TunnelInfo } func newConnectCommand() *cobra.Command { @@ -37,7 +37,7 @@ func newConnectCommand() *cobra.Command { cmd.Flags().StringVar(&o.zt.ResourceType, "type", cluster.SvcResource, lang.CmdConnectFlagType) cmd.Flags().IntVar(&o.zt.LocalPort, "local-port", 0, lang.CmdConnectFlagLocalPort) cmd.Flags().IntVar(&o.zt.RemotePort, "remote-port", 0, lang.CmdConnectFlagRemotePort) - cmd.Flags().BoolVar(&o.cliOnly, "cli-only", false, lang.CmdConnectFlagCliOnly) + cmd.Flags().BoolVar(&o.open, "open", false, lang.CmdConnectFlagOpen) // TODO(soltysh): consider splitting sub-commands into separate files cmd.AddCommand(newConnectListCommand()) @@ -49,6 +49,7 @@ func (o *connectOptions) run(cmd *cobra.Command, args []string) error { ctx := cmd.Context() l := logger.From(ctx) target := "" + // TODO: this leaves room for ignoring potential misuse if len(args) > 0 { target = args[0] } @@ -82,15 +83,15 @@ func (o *connectOptions) run(cmd *cobra.Command, args []string) error { defer tunnel.Close() - if o.cliOnly { - spinner.Updatef(lang.CmdConnectEstablishedCLI, tunnel.FullURL()) - l.Info("Tunnel established, waiting for user to interrupt (ctrl-c to end)", "url", tunnel.FullURL()) - } else { + if o.open { spinner.Updatef(lang.CmdConnectEstablishedWeb, tunnel.FullURL()) l.Info("Tunnel established, opening your default web browser (ctrl-c to end)", "url", tunnel.FullURL()) if err := exec.LaunchURL(tunnel.FullURL()); err != nil { return err } + } else { + spinner.Updatef(lang.CmdConnectEstablishedCLI, tunnel.FullURL()) + l.Info("Tunnel established, waiting for user to interrupt (ctrl-c to end)", "url", tunnel.FullURL()) } // Wait for the interrupt signal or an error. diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 8ee7edaa88..34905a7428 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -76,7 +76,7 @@ const ( CmdConnectFlagType = "Specify the resource type. E.g. type=svc or type=pod. Ignored if connect-name is supplied." CmdConnectFlagLocalPort = "(Optional, autogenerated if not provided) Specify the local port to bind to. E.g. local-port=42000." CmdConnectFlagRemotePort = "Specify the remote port of the resource to bind to. E.g. remote-port=8080. Ignored if connect-name is supplied." - CmdConnectFlagCliOnly = "Disable browser auto-open" + CmdConnectFlagOpen = "Enable browser auto-open" CmdConnectPreparingTunnel = "Preparing a tunnel to connect to %s" CmdConnectEstablishedCLI = "Tunnel established at %s, waiting for user to interrupt (ctrl-c to end)" diff --git a/src/test/e2e/09_component_compose_test.go b/src/test/e2e/09_component_compose_test.go index da654362cc..1ddc87d346 100644 --- a/src/test/e2e/09_component_compose_test.go +++ b/src/test/e2e/09_component_compose_test.go @@ -38,6 +38,12 @@ func TestComposabilityExample(t *testing.T) { b, err := goyaml.Marshal(pkgLayout.Pkg.Components) require.NoError(t, err) + absComposeExample, err := filepath.Abs(composeExample) + require.NoError(t, err) + + rel, err := filepath.Rel(absComposeExample, tmpDir) + require.NoError(t, err) + expectedYaml := fmt.Sprintf(`- name: local-games-path description: Example of a local composed package with a unique description for this component required: true @@ -55,8 +61,8 @@ func TestComposabilityExample(t *testing.T) { - name: multi-games namespace: dos-games files: - - ../../../../../../..%s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-0.yaml - - ../../../../../../..%s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-1.yaml + - %s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-0.yaml + - %s/oci/dirs/9ece174e362633b637e3c6b554b70f7d009d0a27107bee822336fdf2ce9a9def/manifests/multi-games-1.yaml images: - ghcr.io/zarf-dev/doom-game:0.0.1 actions: @@ -70,7 +76,7 @@ func TestComposabilityExample(t *testing.T) { name: game namespace: dos-games condition: available -`, tmpDir, tmpDir) +`, rel, rel) require.YAMLEq(t, expectedYaml, string(b)) }