@@ -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.
3161var 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