Skip to content

Commit

Permalink
Improve upload archive progress bar
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Nov 20, 2024
1 parent 72c6dd7 commit 20e2f2c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
61 changes: 52 additions & 9 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package buildtools
import (
"errors"
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/buildtoollogin"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/packagemanagerlogin"
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
"github.com/jfrog/jfrog-cli-security/utils/techutils"
"golang.org/x/exp/maps"
"os"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -66,11 +69,22 @@ import (
)

const (
buildToolsCategory = "Build Tools"
buildToolsCategory = "Package Managers:"
)

func GetCommands() []cli.Command {
return cliutils.GetSortedCommands(cli.CommandsByName{
{
Name: "setmeup",
Flags: cliutils.GetCommandFlags(cliutils.Mvn),
Usage: mvndoc.GetDescription(),
HelpName: corecommon.CreateUsage("mvn", mvndoc.GetDescription(), mvndoc.Usage),
UsageText: mvndoc.GetArguments(),
ArgsUsage: common.CreateEnvVars(mvndoc.EnvVar...),
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: packageManagerLoginInteractiveCmd,
},
{
Name: "mvn-config",
Aliases: []string{"mvnc"},
Expand Down Expand Up @@ -556,7 +570,7 @@ func yarnGenericCmd(c *cli.Context, cmdName string) error {
return err
}
if cmdName == "login" {
return buildToolLoginCmd(c, project.Yarn)
return packageManagerLoginCmd(c, project.Yarn)
}

return YarnCmd(c)
Expand Down Expand Up @@ -890,7 +904,7 @@ func npmGenericCmd(c *cli.Context, cmdName string, collectBuildInfoIfRequested b
case "publish", "p":
return NpmPublishCmd(c)
case "login":
return buildToolLoginCmd(c, project.Npm)
return packageManagerLoginCmd(c, project.Npm)
}

// Run generic npm command.
Expand Down Expand Up @@ -936,17 +950,46 @@ func NpmPublishCmd(c *cli.Context) (err error) {
return
}

func buildToolLoginCmd(c *cli.Context, buildTool project.ProjectType) (err error) {
func packageManagerLoginInteractiveCmd(c *cli.Context) (err error) {
var supportedPackageManagers []string
for _, packageManager := range maps.Keys(packagemanagerlogin.PackageManagerToRepositoryPackageType) {
supportedPackageManagers = append(supportedPackageManagers, packageManager.String())
}

var selected string
var selectedPackageManager project.ProjectType
var selectableItems []ioutils.PromptItem
allSupportedPackageManagers := maps.Keys(packagemanagerlogin.PackageManagerToRepositoryPackageType)
sort.Slice(allSupportedPackageManagers, func(i, j int) bool {
return allSupportedPackageManagers[i] < allSupportedPackageManagers[j]
})
for _, packageManager := range allSupportedPackageManagers {
selectableItems = append(selectableItems, ioutils.PromptItem{Option: packageManager.String(), TargetValue: &selected})
}
err = ioutils.SelectString(selectableItems, "Please select a package manager to set up:", false, func(item ioutils.PromptItem) {
*item.TargetValue = item.Option
selectedPackageManager = project.FromString(*item.TargetValue)
})
if err != nil {
return
}
if selectedPackageManager == -1 {
return errorutils.CheckErrorf("No package manager was selected")
}
return packageManagerLoginCmd(c, selectedPackageManager)
}

func packageManagerLoginCmd(c *cli.Context, buildTool project.ProjectType) (err error) {
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), buildTool.String()+"loginhelp"); show || err != nil {
return err
}
buildToolLoginCmd := buildtoollogin.NewBuildToolLoginCommand(project.Npm)
packageManagerLoginCmd := packagemanagerlogin.NewPackageManagerLoginCommand(buildTool)
artDetails, err := cliutils.CreateArtifactoryDetailsByFlags(c)
if err != nil {
return err
}
buildToolLoginCmd.SetServerDetails(artDetails)
return commands.Exec(buildToolLoginCmd)
packageManagerLoginCmd.SetServerDetails(artDetails)
return commands.Exec(packageManagerLoginCmd)
}

func GetNpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) {
Expand Down Expand Up @@ -995,7 +1038,7 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
cmdName, filteredArgs := getCommandName(orgArgs)

if cmdName == "login" {
return buildToolLoginCmd(c, projectType)
return packageManagerLoginCmd(c, projectType)
}

switch projectType {
Expand Down
18 changes: 0 additions & 18 deletions buildtools/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/jfrog/jfrog-cli/docs/buildtools/dockerpush"
"github.com/jfrog/jfrog-cli/docs/buildtools/npmci"
"github.com/jfrog/jfrog-cli/docs/buildtools/npminstall"
"github.com/jfrog/jfrog-cli/docs/buildtools/npmlogin"
"github.com/jfrog/jfrog-cli/docs/buildtools/yarnlogin"
"github.com/jfrog/jfrog-cli/docs/common"
"github.com/jfrog/jfrog-cli/utils/cliutils"
"github.com/urfave/cli"
Expand Down Expand Up @@ -62,21 +60,5 @@ func GetBuildToolsHelpCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
Hidden: true,
},
{
Name: "npmloginhelp",
Flags: cliutils.GetCommandFlags(cliutils.NpmLogin),
Usage: npmlogin.GetDescription(),
HelpName: corecommon.CreateUsage("npm login", npmlogin.GetDescription(), npmlogin.Usage),
ArgsUsage: common.CreateEnvVars(),
Hidden: true,
},
{
Name: "yarnloginhelp",
Flags: cliutils.GetCommandFlags(cliutils.YarnLogin),
Usage: yarnlogin.GetDescription(),
HelpName: corecommon.CreateUsage("yarn login", yarnlogin.GetDescription(), yarnlogin.Usage),
ArgsUsage: common.CreateEnvVars(),
Hidden: true,
},
})
}
2 changes: 1 addition & 1 deletion docs/buildtools/mvn/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Usage = []string{"mvn <goals and options> [command options]"}
var EnvVar = []string{common.JfrogCliReleasesRepo, common.JfrogCliDependenciesDir}

func GetDescription() string {
return "Run Maven build."
return "Package manager set me up command."
}

func GetArguments() string {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241113152357-24197a744331
replace github.com/jfrog/jfrog-cli-core/v2 => ../jfrog-cli-core

// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.12.5-0.20241107141149-42cf964808a1

Expand Down

0 comments on commit 20e2f2c

Please sign in to comment.