@@ -3,21 +3,25 @@ package buildtools
3
3
import (
4
4
"errors"
5
5
"fmt"
6
+ "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
7
+ "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
8
+ "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
9
+ "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
6
10
"github.com/jfrog/jfrog-cli-security/utils/techutils"
11
+ setupdocs "github.com/jfrog/jfrog-cli/docs/buildtools/setup"
7
12
"os"
8
13
"strconv"
9
14
"strings"
10
15
11
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/container"
12
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/dotnet"
13
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/golang"
14
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/gradle"
15
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/mvn"
16
- "github.com/jfrog/jfrog-cli-core/v2 /artifactory/commands/npm"
17
- "github.com/jfrog/jfrog-cli-core/v2/ artifactory/commands/python "
18
- "github.com/jfrog/jfrog-cli-core/v2/ artifactory/commands/terraform "
16
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/container"
17
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/dotnet"
18
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/golang"
19
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/gradle"
20
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/mvn"
21
+ "github.com/jfrog/jfrog-cli-artifactory /artifactory/commands/npm"
22
+ "github.com/jfrog/jfrog-cli-artifactory/ artifactory/commands/terraform "
23
+ "github.com/jfrog/jfrog-cli-artifactory/ artifactory/commands/yarn "
19
24
commandsUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
20
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/yarn"
21
25
containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
22
26
"github.com/jfrog/jfrog-cli-core/v2/common/build"
23
27
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
@@ -65,11 +69,23 @@ import (
65
69
)
66
70
67
71
const (
68
- buildToolsCategory = "Build Tools "
72
+ buildToolsCategory = "Package Managers: "
69
73
)
70
74
71
75
func GetCommands () []cli.Command {
72
76
return cliutils .GetSortedCommands (cli.CommandsByName {
77
+ {
78
+ // Currently, the setup command is hidden from the help menu, till it will be released as GA.
79
+ Hidden : true ,
80
+ Name : "setup" ,
81
+ Flags : cliutils .GetCommandFlags (cliutils .Setup ),
82
+ Usage : setupdocs .GetDescription (),
83
+ HelpName : corecommon .CreateUsage ("setup" , setupdocs .GetDescription (), setupdocs .Usage ),
84
+ ArgsUsage : common .CreateEnvVars (),
85
+ UsageText : setupdocs .GetArguments (),
86
+ BashComplete : corecommon .CreateBashCompletionFunc (setup .GetSupportedPackageManagersList ()... ),
87
+ Action : setupCmd ,
88
+ },
73
89
{
74
90
Name : "mvn-config" ,
75
91
Aliases : []string {"mvnc" },
@@ -929,6 +945,63 @@ func NpmPublishCmd(c *cli.Context) (err error) {
929
945
return
930
946
}
931
947
948
+ func setupCmd (c * cli.Context ) (err error ) {
949
+ if c .NArg () > 1 {
950
+ return cliutils .WrongNumberOfArgumentsHandler (c )
951
+ }
952
+ var packageManager project.ProjectType
953
+ packageManagerStr := c .Args ().Get (0 )
954
+ // If the package manager was provided as an argument, validate it.
955
+ if packageManagerStr != "" {
956
+ packageManager = project .FromString (packageManagerStr )
957
+ if ! setup .IsSupportedPackageManager (packageManager ) {
958
+ return cliutils .PrintHelpAndReturnError (fmt .Sprintf ("The package manager %s is not supported" , packageManagerStr ), c )
959
+ }
960
+ } else {
961
+ // If the package manager wasn't provided as an argument, select it interactively.
962
+ packageManager , err = selectPackageManagerInteractively ()
963
+ if err != nil {
964
+ return
965
+ }
966
+ }
967
+ setupCmd := setup .NewSetupCommand (packageManager )
968
+ artDetails , err := cliutils .CreateArtifactoryDetailsByFlags (c )
969
+ if err != nil {
970
+ return err
971
+ }
972
+ repoName := c .String ("repo" )
973
+ if repoName != "" {
974
+ // If a repository was provided, validate it exists in Artifactory.
975
+ if err = validateRepoExists (repoName , artDetails ); err != nil {
976
+ return err
977
+ }
978
+ }
979
+ setupCmd .SetServerDetails (artDetails ).SetRepoName (repoName ).SetProjectKey (cliutils .GetProject (c ))
980
+ return commands .Exec (setupCmd )
981
+ }
982
+
983
+ // validateRepoExists checks if the specified repository exists in Artifactory.
984
+ func validateRepoExists (repoName string , artDetails * coreConfig.ServerDetails ) error {
985
+ serviceDetails , err := artDetails .CreateArtAuthConfig ()
986
+ if err != nil {
987
+ return err
988
+ }
989
+ return utils .ValidateRepoExists (repoName , serviceDetails )
990
+ }
991
+
992
+ func selectPackageManagerInteractively () (selectedPackageManager project.ProjectType , err error ) {
993
+ var selected string
994
+ var selectableItems []ioutils.PromptItem
995
+ for _ , packageManager := range setup .GetSupportedPackageManagersList () {
996
+ selectableItems = append (selectableItems , ioutils.PromptItem {Option : packageManager , TargetValue : & selected })
997
+ }
998
+ err = ioutils .SelectString (selectableItems , "Please select a package manager to set up:" , false , func (item ioutils.PromptItem ) {
999
+ * item .TargetValue = item .Option
1000
+ selectedPackageManager = project .FromString (* item .TargetValue )
1001
+ })
1002
+ return
1003
+ }
1004
+
932
1005
func GetNpmConfigAndArgs (c * cli.Context ) (configFilePath string , args []string , err error ) {
933
1006
configFilePath , err = getProjectConfigPathOrThrow (project .Npm , "npm" , "npm-config" )
934
1007
if err != nil {
0 commit comments