@@ -17,13 +17,15 @@ import (
1717 "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1818 "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1919 "github.com/jfrog/jfrog-cli-security/utils/techutils"
20+ "github.com/jfrog/jfrog-cli/docs/buildtools/helmcommand"
2021 "github.com/jfrog/jfrog-cli/docs/buildtools/rubyconfig"
2122 setupdocs "github.com/jfrog/jfrog-cli/docs/buildtools/setup"
2223
2324 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container"
2425 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/dotnet"
2526 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/golang"
2627 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/gradle"
28+ helmcmd "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/helm"
2729 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/mvn"
2830 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/npm"
2931 containerutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/ocicontainer"
@@ -340,6 +342,19 @@ func GetCommands() []cli.Command {
340342 Category : buildToolsCategory ,
341343 Action : PoetryCmd ,
342344 },
345+ {
346+ Name : "helm" ,
347+ Flags : cliutils .GetCommandFlags (cliutils .Helm ),
348+ Usage : helmcommand .GetDescription (),
349+ HelpName : corecommon .CreateUsage ("helm" , helmcommand .GetDescription (), helmcommand .Usage ),
350+ UsageText : helmcommand .GetArguments (),
351+ ArgsUsage : common .CreateEnvVars (),
352+ SkipFlagParsing : true ,
353+ HideHelp : true ,
354+ BashComplete : corecommon .CreateBashCompletionFunc (),
355+ Category : buildToolsCategory ,
356+ Action : HelmCmd ,
357+ },
343358 {
344359 Name : "conan" ,
345360 Flags : cliutils .GetCommandFlags (cliutils .Conan ),
@@ -1356,6 +1371,108 @@ func PoetryCmd(c *cli.Context) error {
13561371 return pythonCmd (c , project .Poetry )
13571372}
13581373
1374+ // HelmCmd executes Helm commands with build info collection support
1375+ func HelmCmd (c * cli.Context ) error {
1376+ if show , err := cliutils .ShowCmdHelpIfNeeded (c , c .Args ()); show || err != nil {
1377+ return err
1378+ }
1379+ if c .NArg () < 1 {
1380+ return cliutils .WrongNumberOfArgumentsHandler (c )
1381+ }
1382+
1383+ args := cliutils .ExtractCommand (c )
1384+ cmdName , helmArgs := getCommandName (args )
1385+
1386+ helmArgs , buildConfiguration , err := build .ExtractBuildDetailsFromArgs (helmArgs )
1387+ if err != nil {
1388+ return err
1389+ }
1390+
1391+ helmArgs , serverDetails , err := extractHelmServerDetails (helmArgs )
1392+ if err != nil {
1393+ return err
1394+ }
1395+
1396+ helmArgs , repositoryCachePath := extractRepositoryCacheFromArgs (helmArgs )
1397+
1398+ restoreEnv , err := setHelmRepositoryCache (repositoryCachePath )
1399+ if err != nil {
1400+ return err
1401+ }
1402+ defer restoreEnv ()
1403+
1404+ workingDir , err := os .Getwd ()
1405+ if err != nil {
1406+ return fmt .Errorf ("failed to get working directory: %w" , err )
1407+ }
1408+
1409+ helmCmd := helmcmd .NewHelmCommand ().
1410+ SetHelmArgs (helmArgs ).
1411+ SetBuildConfiguration (buildConfiguration ).
1412+ SetServerDetails (serverDetails ).
1413+ SetWorkingDirectory (workingDir ).
1414+ SetHelmCmdName (cmdName )
1415+
1416+ return commands .Exec (helmCmd )
1417+ }
1418+
1419+ // extractRepositoryCacheFromArgs extracts the --repository-cache flag value from Helm command arguments
1420+ func extractRepositoryCacheFromArgs (args []string ) ([]string , string ) {
1421+ cleanedArgs , repositoryCachePath , err := coreutils .ExtractStringOptionFromArgs (args , "repository-cache" )
1422+ if err != nil {
1423+ return args , ""
1424+ }
1425+ return cleanedArgs , repositoryCachePath
1426+ }
1427+
1428+ // extractHelmServerDetails extracts server ID from arguments and retrieves server details.
1429+ func extractHelmServerDetails (args []string ) ([]string , * coreConfig.ServerDetails , error ) {
1430+ cleanedArgs , serverID , err := coreutils .ExtractServerIdFromCommand (args )
1431+ if err != nil {
1432+ return nil , nil , fmt .Errorf ("failed to extract server ID: %w" , err )
1433+ }
1434+
1435+ if serverID == "" {
1436+ serverDetails , err := coreConfig .GetDefaultServerConf ()
1437+ if err != nil {
1438+ return cleanedArgs , nil , err
1439+ }
1440+ return cleanedArgs , serverDetails , nil
1441+ }
1442+
1443+ serverDetails , err := coreConfig .GetSpecificConfig (serverID , true , true )
1444+ if err != nil {
1445+ return nil , nil , fmt .Errorf ("failed to get server configuration for ID '%s': %w" , serverID , err )
1446+ }
1447+
1448+ return cleanedArgs , serverDetails , nil
1449+ }
1450+
1451+ // setHelmRepositoryCache sets or unsets HELM_REPOSITORY_CACHE environment variable.
1452+ func setHelmRepositoryCache (cachePath string ) (func (), error ) {
1453+ const envVarName = "HELM_REPOSITORY_CACHE"
1454+ originalValue := os .Getenv (envVarName )
1455+
1456+ if cachePath != "" {
1457+ if err := os .Setenv (envVarName , cachePath ); err != nil {
1458+ return nil , fmt .Errorf ("failed to set %s environment variable: %w" , envVarName , err )
1459+ }
1460+ } else {
1461+ if err := os .Unsetenv (envVarName ); err != nil {
1462+ return nil , fmt .Errorf ("failed to unset %s environment variable: %w" , envVarName , err )
1463+ }
1464+ }
1465+ restoreFunc := func () {
1466+ if originalValue != "" {
1467+ _ = os .Setenv (envVarName , originalValue )
1468+ } else {
1469+ _ = os .Unsetenv (envVarName )
1470+ }
1471+ }
1472+
1473+ return restoreFunc , nil
1474+ }
1475+
13591476func ConanCmd (c * cli.Context ) error {
13601477 if show , err := cliutils .ShowCmdHelpIfNeeded (c , c .Args ()); show || err != nil {
13611478 return err
0 commit comments