From 2408d5b71d32c235d5be3daf36bb517d08e5d4f1 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 13 May 2024 23:04:57 -0700 Subject: [PATCH 1/2] add local.Config --- internal/cmd/cmd.go | 2 +- internal/cmd/local/local.go | 14 +++++++++----- internal/cmd/local/local_install.go | 3 ++- internal/cmd/local/local_uninstall.go | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 97ae51c..ec1226a 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -92,7 +92,7 @@ func NewCmd() *cobra.Command { cmd.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "enable verbose output") cmd.AddCommand(version.NewCmdVersion()) - cmd.AddCommand(local.NewCmdLocal(k8s.DefaultProvider)) + cmd.AddCommand(local.NewCmdLocal(&local.Config{Provider: k8s.DefaultProvider})) return cmd } diff --git a/internal/cmd/local/local.go b/internal/cmd/local/local.go index 1c7288d..eaf045c 100644 --- a/internal/cmd/local/local.go +++ b/internal/cmd/local/local.go @@ -11,8 +11,13 @@ import ( var telClient telemetry.Client +type Config struct { + Provider k8s.Provider + TelClient telemetry.Client +} + // NewCmdLocal represents the local command. -func NewCmdLocal(provider k8s.Provider) *cobra.Command { +func NewCmdLocal(cfg *Config) *cobra.Command { cmd := &cobra.Command{ Use: "local", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { @@ -24,17 +29,16 @@ func NewCmdLocal(provider k8s.Provider) *cobra.Command { if dnt { telOpts = append(telOpts, telemetry.WithDnt()) } - - telClient = telemetry.Get(telOpts...) + cfg.TelClient = telemetry.Get(telOpts...) } - printProviderDetails(provider) + printProviderDetails(cfg.Provider) return nil }, Short: "Manages local Airbyte installations", } - cmd.AddCommand(NewCmdInstall(provider), NewCmdUninstall(provider)) + cmd.AddCommand(newCmdInstall(cfg), newCmdUninstall(cfg)) return cmd } diff --git a/internal/cmd/local/local_install.go b/internal/cmd/local/local_install.go index 2d76af4..940945d 100644 --- a/internal/cmd/local/local_install.go +++ b/internal/cmd/local/local_install.go @@ -18,8 +18,9 @@ const ( envBasicAuthPass = "ABCTL_LOCAL_INSTALL_PASSWORD" ) -func NewCmdInstall(provider k8s.Provider) *cobra.Command { +func newCmdInstall(cfg *Config) *cobra.Command { spinner := &pterm.DefaultSpinner + provider := cfg.Provider var ( flagChartVersion string diff --git a/internal/cmd/local/local_uninstall.go b/internal/cmd/local/local_uninstall.go index 7cfc648..4f50501 100644 --- a/internal/cmd/local/local_uninstall.go +++ b/internal/cmd/local/local_uninstall.go @@ -2,15 +2,15 @@ package local import ( "fmt" - "github.com/airbytehq/abctl/internal/cmd/local/k8s" "github.com/airbytehq/abctl/internal/cmd/local/local" "github.com/airbytehq/abctl/internal/telemetry" "github.com/pterm/pterm" "github.com/spf13/cobra" ) -func NewCmdUninstall(provider k8s.Provider) *cobra.Command { +func newCmdUninstall(cfg *Config) *cobra.Command { spinner := &pterm.DefaultSpinner + provider := cfg.Provider cmd := &cobra.Command{ Use: "uninstall", From ae62801ef32d2c9d7aebe701f5f7683500b76372 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 13 May 2024 23:06:50 -0700 Subject: [PATCH 2/2] remove telClient global variable --- internal/cmd/local/local.go | 2 -- internal/cmd/local/local_install.go | 8 ++++---- internal/cmd/local/local_uninstall.go | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/cmd/local/local.go b/internal/cmd/local/local.go index eaf045c..d879966 100644 --- a/internal/cmd/local/local.go +++ b/internal/cmd/local/local.go @@ -9,8 +9,6 @@ import ( "path/filepath" ) -var telClient telemetry.Client - type Config struct { Provider k8s.Provider TelClient telemetry.Client diff --git a/internal/cmd/local/local_install.go b/internal/cmd/local/local_install.go index 940945d..0a1e895 100644 --- a/internal/cmd/local/local_install.go +++ b/internal/cmd/local/local_install.go @@ -42,9 +42,9 @@ func newCmdInstall(cfg *Config) *cobra.Command { return fmt.Errorf("could not determine docker installation status: %w", err) } - telClient.Attr("docker_version", dockerVersion.Version) - telClient.Attr("docker_arch", dockerVersion.Arch) - telClient.Attr("docker_platform", dockerVersion.Platform) + cfg.TelClient.Attr("docker_version", dockerVersion.Version) + cfg.TelClient.Attr("docker_arch", dockerVersion.Arch) + cfg.TelClient.Attr("docker_platform", dockerVersion.Platform) spinner.UpdateText(fmt.Sprintf("Checking if port %d is available", flagPort)) if err := portAvailable(cmd.Context(), flagPort); err != nil { @@ -105,7 +105,7 @@ func newCmdInstall(cfg *Config) *cobra.Command { lc, err := local.New(provider, local.WithPortHTTP(flagPort), - local.WithTelemetryClient(telClient), + local.WithTelemetryClient(cfg.TelClient), local.WithSpinner(spinner), local.WithHelmChartVersion(flagChartVersion), ) diff --git a/internal/cmd/local/local_uninstall.go b/internal/cmd/local/local_uninstall.go index 4f50501..2a702e0 100644 --- a/internal/cmd/local/local_uninstall.go +++ b/internal/cmd/local/local_uninstall.go @@ -25,9 +25,9 @@ func newCmdUninstall(cfg *Config) *cobra.Command { return fmt.Errorf("could not determine docker installation status: %w", err) } - telClient.Attr("docker_version", dockerVersion.Version) - telClient.Attr("docker_arch", dockerVersion.Arch) - telClient.Attr("docker_platform", dockerVersion.Platform) + cfg.TelClient.Attr("docker_version", dockerVersion.Version) + cfg.TelClient.Attr("docker_arch", dockerVersion.Arch) + cfg.TelClient.Attr("docker_platform", dockerVersion.Platform) return nil }, @@ -49,7 +49,7 @@ func newCmdUninstall(cfg *Config) *cobra.Command { pterm.Success.Printfln("Existing cluster '%s' found", provider.ClusterName) - lc, err := local.New(provider, local.WithTelemetryClient(telClient), local.WithSpinner(spinner)) + lc, err := local.New(provider, local.WithTelemetryClient(cfg.TelClient), local.WithSpinner(spinner)) if err != nil { pterm.Warning.Printfln("Failed to initialize 'local' command\nUninstallation attempt will continue") pterm.Debug.Printfln("Initialization of 'local' failed with %s", err.Error())