Skip to content

Commit 6a3bdb1

Browse files
feat: Add support for using agent rel versions in CLI install cmds (#1721)
1 parent 8ed5330 commit 6a3bdb1

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

internal/install/command.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,54 @@ var (
2727
tags []string
2828
)
2929

30+
// processRecipeNames validates, extracts recipe names, and sets environment variables.
31+
func processRecipeNames(recipeNames []string) ([]string, error) {
32+
var extractedNames []string
33+
34+
for _, recipe := range recipeNames {
35+
parts := strings.Split(recipe, "@")
36+
37+
if len(parts) < 1 || len(parts) > 2 {
38+
return nil, fmt.Errorf("invalid recipe name format provided: %s", recipe)
39+
}
40+
41+
// Extract the base recipe name
42+
extractedNames = append(extractedNames, parts[0])
43+
44+
// If version is present, set the environment variable
45+
if len(parts) == 2 {
46+
recipeName := parts[0]
47+
version := parts[1]
48+
49+
envVarName := strings.ToUpper(strings.ReplaceAll(recipeName, "-", "_")) + "_VERSION"
50+
51+
err := os.Setenv(envVarName, version)
52+
if err != nil {
53+
return nil, fmt.Errorf("error setting recipe version to environment variable %s: %v", envVarName, err)
54+
}
55+
}
56+
}
57+
return extractedNames, nil
58+
}
59+
3060
// Command represents the install command.
3161
var Command = &cobra.Command{
3262
Use: "install",
3363
Short: "Install New Relic.",
3464
PreRun: client.RequireClient,
3565
RunE: func(cmd *cobra.Command, args []string) error {
66+
extractedRecipeNames, err := processRecipeNames(recipeNames)
67+
if err != nil {
68+
return types.NewDetailError(types.EventTypes.OtherError, err.Error())
69+
}
70+
3671
ic := types.InstallerContext{
3772
AssumeYes: assumeYes,
3873
LocalRecipes: localRecipes,
39-
RecipeNames: recipeNames,
74+
RecipeNames: extractedRecipeNames,
4075
RecipePaths: recipePaths,
4176
}
77+
4278
ic.SetTags(tags)
4379

4480
logLevel := configAPI.GetLogLevel()

0 commit comments

Comments
 (0)