From a98ee344edd5ed80c79c531fb3d5423a419d4473 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 24 Oct 2024 22:21:32 +0100 Subject: [PATCH] flag for user append agent --- internal/exec/utils.go | 16 ++++++++++++++++ pkg/config/const.go | 1 + pkg/schema/schema.go | 1 + 3 files changed, 18 insertions(+) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index 0a4b662c2..c6200682b 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -35,6 +35,7 @@ var ( cfg.DeployRunInitFlag, cfg.InitRunReconfigure, cfg.AutoGenerateBackendFileFlag, + cfg.AppendUserAgentFlag, cfg.FromPlanFlag, cfg.PlanFileFlag, cfg.HelpFlag1, @@ -668,6 +669,21 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche info.TerraformDir = terraformDirFlagParts[1] } + if arg == cfg.AppendUserAgentFlag { + if len(inputArgsAndFlags) <= (i + 1) { + return info, fmt.Errorf("invalid flag: %s requires a value", arg) + } + info.AppendUserAgent = inputArgsAndFlags[i+1] + indexesToRemove = append(indexesToRemove, i, i+1) + } else if strings.HasPrefix(arg+"=", cfg.AppendUserAgentFlag) { + parts := strings.SplitN(arg, "=", 2) + if len(parts) != 2 { + return info, fmt.Errorf("invalid flag: %s", arg) + } + info.AppendUserAgent = parts[1] + indexesToRemove = append(indexesToRemove, i) + } + if arg == cfg.HelmfileCommandFlag { if len(inputArgsAndFlags) <= (i + 1) { return info, fmt.Errorf("invalid flag: %s", arg) diff --git a/pkg/config/const.go b/pkg/config/const.go index 720f53507..924d97249 100644 --- a/pkg/config/const.go +++ b/pkg/config/const.go @@ -27,6 +27,7 @@ const ( DeployRunInitFlag = "--deploy-run-init" AutoGenerateBackendFileFlag = "--auto-generate-backend-file" + AppendUserAgentFlag = "--append-user-agent" InitRunReconfigure = "--init-run-reconfigure" FromPlanFlag = "--from-plan" diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 8c4a6dcbf..89e90b061 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -133,6 +133,7 @@ type ArgsAndFlagsInfo struct { DeployRunInit string InitRunReconfigure string AutoGenerateBackendFile string + AppendUserAgent string UseTerraformPlan bool PlanFile string DryRun bool