From 7243e201ab0521ebf9d29a87ce2e58d75952bbc4 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Wed, 24 Nov 2021 12:28:19 +0200 Subject: [PATCH 1/3] Fix npm NPE --- artifactory/cli.go | 7 ++++++- go.mod | 2 +- go.sum | 4 ++-- npm_test.go | 46 ++++++++++++++++++++++++++--------------- pip_test.go | 27 +++++++++++++++++------- utils/cliutils/utils.go | 6 +++--- 6 files changed, 61 insertions(+), 31 deletions(-) diff --git a/artifactory/cli.go b/artifactory/cli.go index ab1e82ca0..480759e85 100644 --- a/artifactory/cli.go +++ b/artifactory/cli.go @@ -534,7 +534,7 @@ func GetCommands() []cli.Command { SkipFlagParsing: true, BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return npmPublishCmd(c) + return cliutils.RunNativeCmdWithDeprecationWarning("npm p", utils.Npm, c, npmPublishCmd) }, }, { @@ -1179,6 +1179,7 @@ func npmDeprecatedInstallCiCmd(c *cli.Context, npmCmd *npm.NpmInstallOrCiCommand return commands.Exec(npmCmd) } +// Deprecated func npmPublishCmd(c *cli.Context) error { if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil { return err @@ -1194,6 +1195,10 @@ func npmPublishCmd(c *cli.Context) error { args := cliutils.ExtractCommand(c) npmCmd := npm.NewNpmPublishCommand() npmCmd.SetConfigFilePath(configFilePath).SetArgs(args) + err = npmCmd.Init() + if err != nil { + return err + } err = commands.Exec(npmCmd) if err != nil { return err diff --git a/go.mod b/go.mod index 297210f94..298b28ab1 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( //replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.6.1-0.20211118142316-d9a261c51de9 -//replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.4.3-0.20211118181121-5137c711021e +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327 //replace github.com/jfrog/gocmd => github.com/jfrog/gocmd v0.5.4-0.20211116142418-92ddf344a6a4 diff --git a/go.sum b/go.sum index 4cd0a9b69..0c032eb3a 100644 --- a/go.sum +++ b/go.sum @@ -44,6 +44,8 @@ github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= +github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327 h1:8L6Lcrgzg1p8qabtO01Byx43guE4aPR5C1lOuoW/0/4= +github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327/go.mod h1:DTkvS806Vn2aF23ng/ZcEXFpL0rIsVN6AMNsXY3nr0A= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= @@ -229,8 +231,6 @@ github.com/jfrog/gocmd v0.5.4 h1:+yrZ6e3HZXJf6knORZxfbF/LCsK7FTdzmxHPbAaJtQk= github.com/jfrog/gocmd v0.5.4/go.mod h1:nASNY/3Rv7M9VHjim+pIowo0I/fd38SJJm/Bxcp/Tww= github.com/jfrog/gofrog v1.1.0 h1:nhbfSVUYWRxKHeU0RsPAUQeo1suc4oAcEttIKQRvWhs= github.com/jfrog/gofrog v1.1.0/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4= -github.com/jfrog/jfrog-cli-core/v2 v2.5.0 h1:s3/Lzm4NScRgStkdohC+FMcmPeBrm2GFgdIl+Q2QNsQ= -github.com/jfrog/jfrog-cli-core/v2 v2.5.0/go.mod h1:DTkvS806Vn2aF23ng/ZcEXFpL0rIsVN6AMNsXY3nr0A= github.com/jfrog/jfrog-client-go v1.6.1 h1:uu1kr1pOHb0NmT+Equm+FwOOoksWCeSqBOdhmd+60HY= github.com/jfrog/jfrog-client-go v1.6.1/go.mod h1:oR5emUgDSN+T8jNXqimKy9VxszQQuWumv1bst8od3vU= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= diff --git a/npm_test.go b/npm_test.go index 369baef1e..436f67075 100644 --- a/npm_test.go +++ b/npm_test.go @@ -31,7 +31,8 @@ import ( type npmTestParams struct { testName string - command string + nativeCommand string + legacyCommand string repo string npmArgs string wd string @@ -47,7 +48,15 @@ func cleanNpmTest() { tests.CleanFileSystem() } -func TestNpm(t *testing.T) { +func TestNpmNativeSyntax(t *testing.T) { + testNpm(t, false) +} + +func TestNpmLegacy(t *testing.T) { + testNpm(t, true) +} + +func testNpm(t *testing.T, isLegacy bool) { initNpmTest(t) defer cleanNpmTest() wd, err := os.Getwd() @@ -67,20 +76,24 @@ func TestNpm(t *testing.T) { npmProjectPath, npmScopedProjectPath, npmNpmrcProjectPath, npmProjectCi := initNpmFilesTest(t) var npmTests = []npmTestParams{ - {testName: "npm ci", command: "npm ci", repo: tests.NpmRemoteRepo, wd: npmProjectCi, validationFunc: validateNpmInstall}, - {testName: "npm ci with module", command: "npm ci", repo: tests.NpmRemoteRepo, wd: npmProjectCi, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmInstall}, - {testName: "npm i with module", command: "npm install", repo: tests.NpmRemoteRepo, wd: npmProjectPath, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmInstall}, - {testName: "npm i with scoped project", command: "npm install", repo: tests.NpmRemoteRepo, wd: npmScopedProjectPath, validationFunc: validateNpmInstall}, - {testName: "npm i with npmrc project", command: "npm install", repo: tests.NpmRemoteRepo, wd: npmNpmrcProjectPath, validationFunc: validateNpmInstall}, - {testName: "npm i with production", command: "npm install", repo: tests.NpmRemoteRepo, wd: npmProjectPath, validationFunc: validateNpmInstall, npmArgs: "--production"}, - {testName: "npm i with npmrc project", command: "npm i", repo: tests.NpmRemoteRepo, wd: npmNpmrcProjectPath, validationFunc: validateNpmPackInstall, npmArgs: "yaml"}, - {testName: "npmp with module", command: "npm p", repo: tests.NpmRepo, wd: npmScopedProjectPath, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmScopedPublish}, - {testName: "npmp", command: "npm publish", repo: tests.NpmRepo, wd: npmProjectPath, validationFunc: validateNpmPublish}, - {testName: "npm conditional publish", command: "npm publish --scan", repo: tests.NpmRepo, wd: npmProjectPath, validationFunc: validateNpmPublish}, + {testName: "npm ci", nativeCommand: "npm ci", legacyCommand: "rt npmci", repo: tests.NpmRemoteRepo, wd: npmProjectCi, validationFunc: validateNpmInstall}, + {testName: "npm ci with module", nativeCommand: "npm ci", legacyCommand: "rt npmci", repo: tests.NpmRemoteRepo, wd: npmProjectCi, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmInstall}, + {testName: "npm i with module", nativeCommand: "npm install", legacyCommand: "rt npm-install", repo: tests.NpmRemoteRepo, wd: npmProjectPath, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmInstall}, + {testName: "npm i with scoped project", nativeCommand: "npm install", legacyCommand: "rt npm-install", repo: tests.NpmRemoteRepo, wd: npmScopedProjectPath, validationFunc: validateNpmInstall}, + {testName: "npm i with npmrc project", nativeCommand: "npm install", legacyCommand: "rt npm-install", repo: tests.NpmRemoteRepo, wd: npmNpmrcProjectPath, validationFunc: validateNpmInstall}, + {testName: "npm i with production", nativeCommand: "npm install", legacyCommand: "rt npm-install", repo: tests.NpmRemoteRepo, wd: npmProjectPath, validationFunc: validateNpmInstall, npmArgs: "--production"}, + {testName: "npm i with npmrc project", nativeCommand: "npm i", legacyCommand: "rt npmi", repo: tests.NpmRemoteRepo, wd: npmNpmrcProjectPath, validationFunc: validateNpmPackInstall, npmArgs: "yaml"}, + {testName: "npm p with module", nativeCommand: "npm p", legacyCommand: "rt npmp", repo: tests.NpmRepo, wd: npmScopedProjectPath, moduleName: ModuleNameJFrogTest, validationFunc: validateNpmScopedPublish}, + {testName: "npm p", nativeCommand: "npm publish", legacyCommand: "rt npm-publish", repo: tests.NpmRepo, wd: npmProjectPath, validationFunc: validateNpmPublish}, + {testName: "npm conditional publish", nativeCommand: "npm publish --scan", legacyCommand: "rt npm-publish --scan", repo: tests.NpmRepo, wd: npmProjectPath, validationFunc: validateNpmPublish}, } for i, npmTest := range npmTests { t.Run(npmTest.testName, func(t *testing.T) { + npmCmd := npmTest.nativeCommand + if isLegacy { + npmCmd = npmTest.legacyCommand + } err = os.Chdir(filepath.Dir(npmTest.wd)) assert.NoError(t, err) npmrcFileInfo, err := os.Stat(".npmrc") @@ -88,7 +101,7 @@ func TestNpm(t *testing.T) { assert.Fail(t, err.Error()) } var buildNumber string - commandArgs := strings.Split(npmTest.command, " ") + commandArgs := strings.Split(npmCmd, " ") buildNumber = strconv.Itoa(i + 100) commandArgs = append(commandArgs, npmTest.npmArgs) @@ -231,12 +244,11 @@ func validateNpmInstall(t *testing.T, npmTestParams npmTestParams, isNpm7 bool) return } buildInfo := publishedBuildInfo.BuildInfo - if buildInfo.Modules == nil || len(buildInfo.Modules) == 0 { - // Case no module was created - t.Error(fmt.Sprintf("npm install test with command '%s' and repo '%s' failed", npmTestParams.command, npmTestParams.repo)) + if buildInfo.Modules == nil { + assert.NotNil(t, buildInfo.Modules) return } - + assert.NotEmpty(t, buildInfo.Modules) equalDependenciesSlices(t, expectedDependencies, buildInfo.Modules[0].Dependencies) } diff --git a/pip_test.go b/pip_test.go index 6078ebd63..1ad028b52 100644 --- a/pip_test.go +++ b/pip_test.go @@ -24,7 +24,15 @@ type PipCmd struct { Options []string } -func TestPipInstall(t *testing.T) { +func TestPipInstallNativeSyntax(t *testing.T) { + testPipInstall(t, false) +} + +func TestPipInstallLegacy(t *testing.T) { + testPipInstall(t, true) +} + +func testPipInstall(t *testing.T, isLegacy bool) { // Init pip. initPipTest(t) @@ -53,17 +61,22 @@ func TestPipInstall(t *testing.T) { expectedDependencies int cleanAfterExecution bool }{ - {"setuppy", "setuppyproject", "setuppy", "jfrog-python-example", []string{"pip", "install", ".", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName}, 3, true}, - {"setuppy-verbose", "setuppyproject", "setuppy-verbose", "jfrog-python-example", []string{"pip", "install", ".", "--no-cache-dir", "--force-reinstall", "-v", "--build-name=" + tests.PipBuildName}, 3, true}, - {"setuppy-with-module", "setuppyproject", "setuppy-with-module", "setuppy-with-module", []string{"pip", "install", ".", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName, "--module=setuppy-with-module"}, 3, true}, - {"requirements", "requirementsproject", "requirements", tests.PipBuildName, []string{"pip", "install", "-r", "requirements.txt", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName}, 5, true}, - {"requirements-verbose", "requirementsproject", "requirements-verbose", tests.PipBuildName, []string{"pip", "install", "-r", "requirements.txt", "--no-cache-dir", "--force-reinstall", "-v", "--build-name=" + tests.PipBuildName}, 5, false}, - {"requirements-use-cache", "requirementsproject", "requirements-verbose", "requirements-verbose-use-cache", []string{"pip", "install", "-r", "requirements.txt", "--module=requirements-verbose-use-cache", "--build-name=" + tests.PipBuildName}, 5, true}, + {"setuppy", "setuppyproject", "setuppy", "jfrog-python-example", []string{".", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName}, 3, true}, + {"setuppy-verbose", "setuppyproject", "setuppy-verbose", "jfrog-python-example", []string{".", "--no-cache-dir", "--force-reinstall", "-v", "--build-name=" + tests.PipBuildName}, 3, true}, + {"setuppy-with-module", "setuppyproject", "setuppy-with-module", "setuppy-with-module", []string{".", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName, "--module=setuppy-with-module"}, 3, true}, + {"requirements", "requirementsproject", "requirements", tests.PipBuildName, []string{"-r", "requirements.txt", "--no-cache-dir", "--force-reinstall", "--build-name=" + tests.PipBuildName}, 5, true}, + {"requirements-verbose", "requirementsproject", "requirements-verbose", tests.PipBuildName, []string{"-r", "requirements.txt", "--no-cache-dir", "--force-reinstall", "-v", "--build-name=" + tests.PipBuildName}, 5, false}, + {"requirements-use-cache", "requirementsproject", "requirements-verbose", "requirements-verbose-use-cache", []string{"-r", "requirements.txt", "--module=requirements-verbose-use-cache", "--build-name=" + tests.PipBuildName}, 5, true}, } // Run test cases. for buildNumber, test := range allTests { t.Run(test.name, func(t *testing.T) { + if isLegacy { + test.args = append([]string{"rt", "pip-install"}, test.args...) + } else { + test.args = append([]string{"pip", "install"}, test.args...) + } testPipCmd(t, test.name, createPipProject(t, test.outputFolder, test.project), strconv.Itoa(buildNumber), test.moduleId, test.expectedDependencies, test.args) if test.cleanAfterExecution { // cleanup diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index caf29d545..1f300394f 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -517,8 +517,8 @@ func CreateConfigCmd(c *cli.Context, confType artifactoryUtils.ProjectType) erro func RunNativeCmdWithDeprecationWarning(cmdName string, projectType artifactoryUtils.ProjectType, c *cli.Context, cmd func(c *cli.Context) error) error { if shouldLogWarning() { log.Warn(`You are using a deprecated syntax of the command. - The new command syntax is quite similar to the current syntax, and is similar to the ` + projectType.String() + ` CLI command, with the addition of a prefix of the 'jf' executable name, i.e.: - $ jf ` + cmdName + ` [` + projectType.String() + ` args and option] --build-name=*BUILD_NAME* --build-number=*BUILD_NUMBER*`) + The new command syntax is quite similar to the current syntax, and is similar to the ` + projectType.String() + ` CLI command, with the addition of a prefix of the '` + coreutils.GetCliExecutableName() + `' executable name, i.e.: + $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` [` + projectType.String() + ` args and option] --build-name=*BUILD_NAME* --build-number=*BUILD_NUMBER*`) } return cmd(c) } @@ -539,7 +539,7 @@ func logNonNativeCommandDeprecation(cmdName string) { if shouldLogWarning() { log.Warn(`You are using a deprecated syntax of the command. The new command syntax is similar to the current syntax, without the subcommand, i.e.: - $ jf ` + cmdName + ` [args and option]`) + $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` [args and option]`) } } From 895714ba227f8c9795ac3311a12ea9a795abe918 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Wed, 24 Nov 2021 12:52:58 +0200 Subject: [PATCH 2/3] Update deprecated warning syntax --- artifactory/cli.go | 18 +++++++++--------- utils/cliutils/utils.go | 29 ++++++++++++++++++----------- xray/cli.go | 12 ++++++------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/artifactory/cli.go b/artifactory/cli.go index 480759e85..36f2f6f38 100644 --- a/artifactory/cli.go +++ b/artifactory/cli.go @@ -352,7 +352,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", utils.Maven, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", "rt", utils.Maven, c, cliutils.CreateConfigCmd) }, }, { @@ -377,7 +377,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", utils.Gradle, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", "rt", utils.Gradle, c, cliutils.CreateConfigCmd) }, }, { @@ -493,7 +493,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("npmc", utils.Npm, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("npmc", "rt", utils.Npm, c, cliutils.CreateConfigCmd) }, }, { @@ -546,7 +546,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", utils.Yarn, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", "rt", utils.Yarn, c, cliutils.CreateConfigCmd) }, }, { @@ -570,7 +570,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", utils.Nuget, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", "rt", utils.Nuget, c, cliutils.CreateConfigCmd) }, }, { @@ -606,7 +606,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", utils.Dotnet, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", "rt", utils.Dotnet, c, cliutils.CreateConfigCmd) }, }, { @@ -630,7 +630,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("go-config", utils.Go, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("go-config", "rt", utils.Go, c, cliutils.CreateConfigCmd) }, }, { @@ -643,7 +643,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("gp", c, buildtools.GoPublishCmd) + return cliutils.RunCmdWithDeprecationWarning("gp", "rt", c, buildtools.GoPublishCmd) }, }, { @@ -695,7 +695,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommon.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunConfigCmdWithDeprecationWarning("pipc", utils.Pip, c, cliutils.CreateConfigCmd) + return cliutils.RunConfigCmdWithDeprecationWarning("pipc", "rt", utils.Pip, c, cliutils.CreateConfigCmd) }, }, { diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index 1f300394f..e311db9a1 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -516,30 +516,37 @@ func CreateConfigCmd(c *cli.Context, confType artifactoryUtils.ProjectType) erro func RunNativeCmdWithDeprecationWarning(cmdName string, projectType artifactoryUtils.ProjectType, c *cli.Context, cmd func(c *cli.Context) error) error { if shouldLogWarning() { - log.Warn(`You are using a deprecated syntax of the command. - The new command syntax is quite similar to the current syntax, and is similar to the ` + projectType.String() + ` CLI command, with the addition of a prefix of the '` + coreutils.GetCliExecutableName() + `' executable name, i.e.: - $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` [` + projectType.String() + ` args and option] --build-name=*BUILD_NAME* --build-number=*BUILD_NUMBER*`) + log.Warn( + `You are using a deprecated syntax of the command. + The new command syntax is quite similar to the syntax used by the native ` + projectType.String() + ` client. + All you need to do is to add '` + coreutils.GetCliExecutableName() + `' as a prefix to the command. + For example: + $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` ... + The --build-name and --build-number options are still supported.`) } return cmd(c) } -func RunConfigCmdWithDeprecationWarning(cmdName string, confType artifactoryUtils.ProjectType, c *cli.Context, +func RunConfigCmdWithDeprecationWarning(cmdName, oldSubcommand string, confType artifactoryUtils.ProjectType, c *cli.Context, cmd func(c *cli.Context, confType artifactoryUtils.ProjectType) error) error { - logNonNativeCommandDeprecation(cmdName) + logNonNativeCommandDeprecation(cmdName, oldSubcommand) return cmd(c, confType) } -func RunCmdWithDeprecationWarning(cmdName string, c *cli.Context, +func RunCmdWithDeprecationWarning(cmdName, oldSubcommand string, c *cli.Context, cmd func(c *cli.Context) error) error { - logNonNativeCommandDeprecation(cmdName) + logNonNativeCommandDeprecation(cmdName, oldSubcommand) return cmd(c) } -func logNonNativeCommandDeprecation(cmdName string) { +func logNonNativeCommandDeprecation(cmdName, oldSubcommand string) { if shouldLogWarning() { - log.Warn(`You are using a deprecated syntax of the command. - The new command syntax is similar to the current syntax, without the subcommand, i.e.: - $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` [args and option]`) + log.Warn( + `You are using a deprecated syntax of the command. + Instead of: + $ ` + coreutils.GetCliExecutableName() + ` ` + oldSubcommand + ` ` + cmdName + ` ... + Use: + $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` ...`) } } diff --git a/xray/cli.go b/xray/cli.go index 6decd8bc8..a44a64236 100644 --- a/xray/cli.go +++ b/xray/cli.go @@ -49,7 +49,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("audit-mvn", c, scan.AuditMvnCmd) + return cliutils.RunCmdWithDeprecationWarning("audit-mvn", "xr", c, scan.AuditMvnCmd) }, }, { @@ -61,7 +61,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("audit-gradle", c, scan.AuditGradleCmd) + return cliutils.RunCmdWithDeprecationWarning("audit-gradle", "xr", c, scan.AuditGradleCmd) }, }, { @@ -73,7 +73,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("audit-npm", c, scan.AuditNpmCmd) + return cliutils.RunCmdWithDeprecationWarning("audit-npm", "xr", c, scan.AuditNpmCmd) }, }, { @@ -85,7 +85,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("audit-go", c, scan.AuditGoCmd) + return cliutils.RunCmdWithDeprecationWarning("audit-go", "xr", c, scan.AuditGoCmd) }, }, { @@ -97,7 +97,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("audit-pip", c, scan.AuditPipCmd) + return cliutils.RunCmdWithDeprecationWarning("audit-pip", "xr", c, scan.AuditPipCmd) }, }, { @@ -110,7 +110,7 @@ func GetCommands() []cli.Command { ArgsUsage: common.CreateEnvVars(), BashComplete: corecommondocs.CreateBashCompletionFunc(), Action: func(c *cli.Context) error { - return cliutils.RunCmdWithDeprecationWarning("scan", c, scan.ScanCmd) + return cliutils.RunCmdWithDeprecationWarning("scan", "xr", c, scan.ScanCmd) }, }, { From 1065d838bfa37e2f9c41183c52ffe09b54b140b0 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Wed, 24 Nov 2021 17:54:34 +0200 Subject: [PATCH 3/3] CR comments --- go.mod | 2 +- go.sum | 4 ++-- npm_test.go | 6 ++++-- pip_test.go | 1 + utils/cliutils/utils.go | 14 +++++++++----- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 298b28ab1..fe2c05808 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( //replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.6.1-0.20211118142316-d9a261c51de9 -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.5.1-0.20211124154851-a2da7a5e9dc4 //replace github.com/jfrog/gocmd => github.com/jfrog/gocmd v0.5.4-0.20211116142418-92ddf344a6a4 diff --git a/go.sum b/go.sum index 0c032eb3a..6090c2ae0 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,6 @@ github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= -github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327 h1:8L6Lcrgzg1p8qabtO01Byx43guE4aPR5C1lOuoW/0/4= -github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20211124102537-7c0290295327/go.mod h1:DTkvS806Vn2aF23ng/ZcEXFpL0rIsVN6AMNsXY3nr0A= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= @@ -231,6 +229,8 @@ github.com/jfrog/gocmd v0.5.4 h1:+yrZ6e3HZXJf6knORZxfbF/LCsK7FTdzmxHPbAaJtQk= github.com/jfrog/gocmd v0.5.4/go.mod h1:nASNY/3Rv7M9VHjim+pIowo0I/fd38SJJm/Bxcp/Tww= github.com/jfrog/gofrog v1.1.0 h1:nhbfSVUYWRxKHeU0RsPAUQeo1suc4oAcEttIKQRvWhs= github.com/jfrog/gofrog v1.1.0/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4= +github.com/jfrog/jfrog-cli-core/v2 v2.5.1-0.20211124154851-a2da7a5e9dc4 h1:LzgAlm6OIiSKqJjOa3BJAg709/L/8HG/3NHBu48qK7c= +github.com/jfrog/jfrog-cli-core/v2 v2.5.1-0.20211124154851-a2da7a5e9dc4/go.mod h1:DTkvS806Vn2aF23ng/ZcEXFpL0rIsVN6AMNsXY3nr0A= github.com/jfrog/jfrog-client-go v1.6.1 h1:uu1kr1pOHb0NmT+Equm+FwOOoksWCeSqBOdhmd+60HY= github.com/jfrog/jfrog-client-go v1.6.1/go.mod h1:oR5emUgDSN+T8jNXqimKy9VxszQQuWumv1bst8od3vU= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= diff --git a/npm_test.go b/npm_test.go index 436f67075..2143ecd31 100644 --- a/npm_test.go +++ b/npm_test.go @@ -30,8 +30,9 @@ import ( ) type npmTestParams struct { - testName string - nativeCommand string + testName string + nativeCommand string + // Deprecated legacyCommand string repo string npmArgs string @@ -52,6 +53,7 @@ func TestNpmNativeSyntax(t *testing.T) { testNpm(t, false) } +// Deprecated func TestNpmLegacy(t *testing.T) { testNpm(t, true) } diff --git a/pip_test.go b/pip_test.go index 1ad028b52..db2a0fdeb 100644 --- a/pip_test.go +++ b/pip_test.go @@ -28,6 +28,7 @@ func TestPipInstallNativeSyntax(t *testing.T) { testPipInstall(t, false) } +// Deprecated func TestPipInstallLegacy(t *testing.T) { testPipInstall(t, true) } diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index e311db9a1..aaf32e296 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -516,15 +516,19 @@ func CreateConfigCmd(c *cli.Context, confType artifactoryUtils.ProjectType) erro func RunNativeCmdWithDeprecationWarning(cmdName string, projectType artifactoryUtils.ProjectType, c *cli.Context, cmd func(c *cli.Context) error) error { if shouldLogWarning() { - log.Warn( - `You are using a deprecated syntax of the command. - The new command syntax is quite similar to the syntax used by the native ` + projectType.String() + ` client. + logNativeCommandDeprecation(cmdName, projectType.String()) + } + return cmd(c) +} + +func logNativeCommandDeprecation(cmdName, projectType string) { + log.Warn( + `You are using a deprecated syntax of the command. + The new command syntax is quite similar to the syntax used by the native ` + projectType + ` client. All you need to do is to add '` + coreutils.GetCliExecutableName() + `' as a prefix to the command. For example: $ ` + coreutils.GetCliExecutableName() + ` ` + cmdName + ` ... The --build-name and --build-number options are still supported.`) - } - return cmd(c) } func RunConfigCmdWithDeprecationWarning(cmdName, oldSubcommand string, confType artifactoryUtils.ProjectType, c *cli.Context,