Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate distribution V1 commands to cli-artifactory #1342

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugins/common/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

import (
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
clientutils "github.com/jfrog/jfrog-client-go/utils"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -100,3 +102,25 @@ func buildAndSortFlags(keys []string, flagsMap map[string]components.Flag) (flag
sort.Slice(flags, func(i, j int) bool { return flags[i].GetName() < flags[j].GetName() })
return
}

// This function indicates whether the command should be executed without
// confirmation warning or not.
// If the --quiet option was sent, it is used to determine whether to prompt the confirmation or not.
// If not, the command will prompt the confirmation, unless the CI environment variable was set to true.
func GetQuietValue(c *components.Context) bool {
if c.IsFlagSet("quiet") {
return c.GetBoolFlagValue("quiet")
}

return getCiValue()
}

// Return true if the CI environment variable was set to true.
func getCiValue() bool {
var ci bool
var err error
if ci, err = clientutils.GetBoolEnvValue(coreutils.CI, false); err != nil {
return false
}
return ci
}
14 changes: 14 additions & 0 deletions plugins/components/commandcomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,17 @@ func SetHiddenBoolFlag() BoolFlagOption {
f.Hidden = true
}
}

func (c *Context) WithDefaultIntFlagValue(flagName string, defValue int) (value int, err error) {
value = defValue
if c.IsFlagSet(flagName) {
var parsed int64
parsed, err = strconv.ParseInt(c.GetStringFlagValue(flagName), 0, 64)
if err != nil {
err = fmt.Errorf("can't parse int flag '%s': %w", flagName, err)
return
}
value = int(parsed)
}
return
}