@@ -33,6 +33,7 @@ import (
33
33
"github.com/jfrog/jfrog-cli-security/commands/scan"
34
34
terraformdocs "github.com/jfrog/jfrog-cli/docs/artifactory/terraform"
35
35
"github.com/jfrog/jfrog-cli/docs/artifactory/terraformconfig"
36
+ twinedocs "github.com/jfrog/jfrog-cli/docs/artifactory/twine"
36
37
"github.com/jfrog/jfrog-cli/docs/buildtools/docker"
37
38
dotnetdocs "github.com/jfrog/jfrog-cli/docs/buildtools/dotnet"
38
39
"github.com/jfrog/jfrog-cli/docs/buildtools/dotnetconfig"
@@ -402,6 +403,18 @@ func GetCommands() []cli.Command {
402
403
Category : buildToolsCategory ,
403
404
Action : terraformCmd ,
404
405
},
406
+ {
407
+ Name : "twine" ,
408
+ Flags : cliutils .GetCommandFlags (cliutils .Twine ),
409
+ Usage : twinedocs .GetDescription (),
410
+ HelpName : corecommon .CreateUsage ("twine" , twinedocs .GetDescription (), twinedocs .Usage ),
411
+ UsageText : twinedocs .GetArguments (),
412
+ ArgsUsage : common .CreateEnvVars (),
413
+ SkipFlagParsing : true ,
414
+ BashComplete : corecommon .CreateBashCompletionFunc (),
415
+ Category : buildToolsCategory ,
416
+ Action : twineCmd ,
417
+ },
405
418
})
406
419
}
407
420
@@ -410,13 +423,11 @@ func MvnCmd(c *cli.Context) (err error) {
410
423
return err
411
424
}
412
425
413
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Maven )
426
+ configFilePath , err := getProjectConfigPathOrThrow (project .Maven , "mvn" , "mvn-config" )
414
427
if err != nil {
415
428
return err
416
429
}
417
- if ! exists {
418
- return errors .New ("no config file was found! Before running the mvn command on a project for the first time, the project should be configured with the mvn-config command" )
419
- }
430
+
420
431
if c .NArg () < 1 {
421
432
return cliutils .WrongNumberOfArgumentsHandler (c )
422
433
}
@@ -469,13 +480,11 @@ func GradleCmd(c *cli.Context) (err error) {
469
480
return err
470
481
}
471
482
472
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Gradle )
483
+ configFilePath , err := getProjectConfigPathOrThrow (project .Gradle , "gradle" , "gradle-config" )
473
484
if err != nil {
474
485
return err
475
486
}
476
- if ! exists {
477
- return errors .New ("no config file was found! Before running the gradle command on a project for the first time, the project should be configured with the gradle-config command" )
478
- }
487
+
479
488
// Found a config file. Continue as native command.
480
489
if c .NArg () < 1 {
481
490
return cliutils .WrongNumberOfArgumentsHandler (c )
@@ -525,13 +534,10 @@ func YarnCmd(c *cli.Context) error {
525
534
return err
526
535
}
527
536
528
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Yarn )
537
+ configFilePath , err := getProjectConfigPathOrThrow (project .Yarn , "yarn" , "yarn-config" )
529
538
if err != nil {
530
539
return err
531
540
}
532
- if ! exists {
533
- return fmt .Errorf ("no config file was found! Before running the yarn command on a project for the first time, the project should be configured using the yarn-config command" )
534
- }
535
541
536
542
yarnCmd := yarn .NewYarnCommand ().SetConfigFilePath (configFilePath ).SetArgs (c .Args ())
537
543
return commands .Exec (yarnCmd )
@@ -544,15 +550,12 @@ func NugetCmd(c *cli.Context) error {
544
550
if c .NArg () < 1 {
545
551
return cliutils .WrongNumberOfArgumentsHandler (c )
546
552
}
547
- configFilePath , exists , err := project .GetProjectConfFilePath (project .Nuget )
553
+
554
+ configFilePath , err := getProjectConfigPathOrThrow (project .Nuget , "nuget" , "nuget-config" )
548
555
if err != nil {
549
556
return err
550
557
}
551
558
552
- if ! exists {
553
- return fmt .Errorf ("no config file was found! Before running the nuget command on a project for the first time, the project should be configured using the nuget-config command" )
554
- }
555
-
556
559
rtDetails , targetRepo , useNugetV2 , err := getNugetAndDotnetConfigFields (configFilePath )
557
560
if err != nil {
558
561
return err
@@ -584,13 +587,10 @@ func DotnetCmd(c *cli.Context) error {
584
587
}
585
588
586
589
// Get configuration file path.
587
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Dotnet )
590
+ configFilePath , err := getProjectConfigPathOrThrow (project .Dotnet , "dotnet" , "dotnet-config" )
588
591
if err != nil {
589
592
return err
590
593
}
591
- if ! exists {
592
- return fmt .Errorf ("no config file was found! Before running the dotnet command on a project for the first time, the project should be configured using the dotnet-config command" )
593
- }
594
594
595
595
rtDetails , targetRepo , useNugetV2 , err := getNugetAndDotnetConfigFields (configFilePath )
596
596
if err != nil {
@@ -690,14 +690,12 @@ func goCmdVerification(c *cli.Context) (string, error) {
690
690
if c .NArg () < 1 {
691
691
return "" , cliutils .WrongNumberOfArgumentsHandler (c )
692
692
}
693
- configFilePath , exists , err := project .GetProjectConfFilePath (project .Go )
693
+
694
+ configFilePath , err := getProjectConfigPathOrThrow (project .Go , "go" , "go-config" )
694
695
if err != nil {
695
696
return "" , err
696
697
}
697
- // Verify config file is found.
698
- if ! exists {
699
- return "" , fmt .Errorf ("no config file was found! Before running the go command on a project for the first time, the project should be configured using the go-config command" )
700
- }
698
+
701
699
log .Debug ("Go config file was found in:" , configFilePath )
702
700
return configFilePath , nil
703
701
}
@@ -887,13 +885,9 @@ func NpmPublishCmd(c *cli.Context) (err error) {
887
885
}
888
886
889
887
func GetNpmConfigAndArgs (c * cli.Context ) (configFilePath string , args []string , err error ) {
890
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Npm )
888
+ configFilePath , err = getProjectConfigPathOrThrow (project .Npm , "npm" , "npm-config" )
891
889
if err != nil {
892
- return "" , nil , err
893
- }
894
-
895
- if ! exists {
896
- return "" , nil , errorutils .CheckErrorf ("no config file was found! Before running the npm command on a project for the first time, the project should be configured using the npm-config command" )
890
+ return
897
891
}
898
892
_ , args = getCommandName (c .Args ())
899
893
return
@@ -970,13 +964,9 @@ func terraformCmd(c *cli.Context) error {
970
964
}
971
965
972
966
func getTerraformConfigAndArgs (c * cli.Context ) (configFilePath string , args []string , err error ) {
973
- configFilePath , exists , err := project . GetProjectConfFilePath (project .Terraform )
967
+ configFilePath , err = getProjectConfigPathOrThrow (project .Terraform , "terraform" , "terraform-config" )
974
968
if err != nil {
975
- return "" , nil , err
976
- }
977
-
978
- if ! exists {
979
- return "" , nil , errors .New ("no config file was found! Before running the terraform command on a project for the first time, the project should be configured using the terraform-config command" )
969
+ return
980
970
}
981
971
args = cliutils .ExtractCommand (c )
982
972
return
@@ -992,3 +982,63 @@ func terraformPublishCmd(configFilePath string, args []string, c *cli.Context) e
992
982
result := terraformCmd .Result ()
993
983
return cliutils .PrintBriefSummaryReport (result .SuccessCount (), result .FailCount (), cliutils .IsFailNoOp (c ), err )
994
984
}
985
+
986
+ func getProjectConfigPathOrThrow (projectType project.ProjectType , cmdName , configCmdName string ) (configFilePath string , err error ) {
987
+ configFilePath , exists , err := project .GetProjectConfFilePath (projectType )
988
+ if err != nil {
989
+ return
990
+ }
991
+ if ! exists {
992
+ return "" , errorutils .CheckErrorf (getMissingConfigErrMsg (cmdName , configCmdName ))
993
+ }
994
+ return
995
+ }
996
+
997
+ func getMissingConfigErrMsg (cmdName , configCmdName string ) string {
998
+ return fmt .Sprintf ("no config file was found! Before running the 'jf %s' command on a project for the first time, the project should be configured with the 'jf %s' command" , cmdName , configCmdName )
999
+ }
1000
+
1001
+ func twineCmd (c * cli.Context ) error {
1002
+ if show , err := cliutils .ShowCmdHelpIfNeeded (c , c .Args ()); show || err != nil {
1003
+ return err
1004
+ }
1005
+ serverDetails , targetRepo , err := getTwineConfigAndArgs ()
1006
+ if err != nil {
1007
+ return err
1008
+ }
1009
+ cmdName , filteredArgs := getCommandName (cliutils .ExtractCommand (c ))
1010
+ return python .NewTwineCommand (cmdName ).SetServerDetails (serverDetails ).SetTargetRepo (targetRepo ).SetArgs (filteredArgs ).Run ()
1011
+ }
1012
+
1013
+ func getTwineConfigAndArgs () (serverDetails * coreConfig.ServerDetails , targetRepo string , err error ) {
1014
+ configFilePath , err := getTwineConfigPath ()
1015
+ if err != nil {
1016
+ return
1017
+ }
1018
+
1019
+ vConfig , err := project .ReadConfigFile (configFilePath , project .YAML )
1020
+ if err != nil {
1021
+ return nil , "" , fmt .Errorf ("failed while reading configuration file '%s'. Error: %s" , configFilePath , err .Error ())
1022
+ }
1023
+ projectConfig , err := project .GetRepoConfigByPrefix (configFilePath , project .ProjectConfigDeployerPrefix , vConfig )
1024
+ if err != nil {
1025
+ return nil , "" , err
1026
+ }
1027
+ serverDetails , err = projectConfig .ServerDetails ()
1028
+ if err != nil {
1029
+ return nil , "" , err
1030
+ }
1031
+ targetRepo = projectConfig .TargetRepo ()
1032
+ return
1033
+ }
1034
+
1035
+ func getTwineConfigPath () (configFilePath string , err error ) {
1036
+ var exists bool
1037
+ for _ , projectType := range []project.ProjectType {project .Pip , project .Pipenv } {
1038
+ configFilePath , exists , err = project .GetProjectConfFilePath (projectType )
1039
+ if err != nil || exists {
1040
+ return
1041
+ }
1042
+ }
1043
+ return "" , errorutils .CheckErrorf (getMissingConfigErrMsg ("twine" , "pip-config OR pipenv-config" ))
1044
+ }
0 commit comments