-
Notifications
You must be signed in to change notification settings - Fork 91
Migrate life cycle commands from jfrog-cli to jfrog-cli-artifactory #1351
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
Changes from 3 commits
1aaa667
1a021e2
fc63058
999c614
8df2a5f
48103fd
d16eb73
a22d870
463cbce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "errors" | ||
| artifactoryUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" | ||
| "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" | ||
| clientutils "github.com/jfrog/jfrog-client-go/utils" | ||
| "os" | ||
| "sort" | ||
| "strconv" | ||
| "strings" | ||
|
|
@@ -13,6 +16,13 @@ import ( | |
| "golang.org/x/exp/slices" | ||
| ) | ||
|
|
||
| const ( | ||
| minSplit = "min-split" | ||
| DownloadMinSplitKb = 5120 | ||
| DownloadSplitCount = 3 | ||
| DownloadMaxSplitCount = 15 | ||
| ) | ||
|
|
||
| func GetStringsArrFlagValue(c *components.Context, flagName string) (resultArray []string) { | ||
| if c.IsFlagSet(flagName) { | ||
| resultArray = append(resultArray, strings.Split(c.GetStringFlagValue(flagName), ";")...) | ||
|
|
@@ -124,3 +134,71 @@ func getCiValue() bool { | |
| } | ||
| return ci | ||
| } | ||
|
|
||
| // Get project key from flag or environment variable | ||
| func GetProject(c *components.Context) string { | ||
| projectKey := c.GetStringFlagValue("project") | ||
| return getOrDefaultEnv(projectKey, coreutils.Project) | ||
| } | ||
|
|
||
| // Return argument if not empty or retrieve from environment variable | ||
| func getOrDefaultEnv(arg, envKey string) string { | ||
| if arg != "" { | ||
| return arg | ||
| } | ||
| return os.Getenv(envKey) | ||
| } | ||
|
|
||
| func CreateDownloadConfiguration(c *components.Context) (downloadConfiguration *artifactoryUtils.DownloadConfiguration, err error) { | ||
|
||
| downloadConfiguration = new(artifactoryUtils.DownloadConfiguration) | ||
| downloadConfiguration.MinSplitSize, err = getMinSplit(c, DownloadMinSplitKb) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| downloadConfiguration.SplitCount, err = getSplitCount(c, DownloadSplitCount, DownloadMaxSplitCount) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| downloadConfiguration.Threads, err = GetThreadsCount(c) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| downloadConfiguration.SkipChecksum = c.GetBoolFlagValue("skip-checksum") | ||
| downloadConfiguration.Symlink = true | ||
| return | ||
| } | ||
|
|
||
| func getMinSplit(c *components.Context, defaultMinSplit int64) (minSplitSize int64, err error) { | ||
| minSplitSize = defaultMinSplit | ||
| if c.GetStringFlagValue(minSplit) != "" { | ||
| minSplitSize, err = strconv.ParseInt(c.GetStringFlagValue(minSplit), 10, 64) | ||
| if err != nil { | ||
| err = errors.New("The '--min-split' option should have a numeric value. " + GetDocumentationMessage()) | ||
| return 0, err | ||
| } | ||
| } | ||
|
|
||
| return minSplitSize, nil | ||
| } | ||
|
|
||
| func GetDocumentationMessage() string { | ||
| return "You can read the documentation at " + coreutils.JFrogHelpUrl + "jfrog-cli" | ||
| } | ||
|
|
||
| func getSplitCount(c *components.Context, defaultSplitCount, maxSplitCount int) (splitCount int, err error) { | ||
| splitCount = defaultSplitCount | ||
| err = nil | ||
| if c.GetStringFlagValue("split-count") != "" { | ||
| splitCount, err = strconv.Atoi(c.GetStringFlagValue("split-count")) | ||
| if err != nil { | ||
| err = errors.New("The '--split-count' option should have a numeric value. " + GetDocumentationMessage()) | ||
| } | ||
| if splitCount > maxSplitCount { | ||
| err = errors.New("The '--split-count' option value is limited to a maximum of " + strconv.Itoa(maxSplitCount) + ".") | ||
| } | ||
| if splitCount < 0 { | ||
| err = errors.New("the '--split-count' option cannot have a negative value") | ||
| } | ||
| } | ||
| return | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,9 +61,19 @@ func (c *Context) GetStringFlagValue(flagName string) string { | |
| } | ||
|
|
||
| func (c *Context) AddStringFlag(key, value string) { | ||
| if c.stringFlags == nil { | ||
| c.stringFlags = make(map[string]string) | ||
| } | ||
| c.stringFlags[key] = value | ||
| } | ||
|
|
||
| func (c *Context) AddBoolFlag(key string, value bool) { | ||
| if c.boolFlags == nil { | ||
| c.boolFlags = make(map[string]bool) | ||
| } | ||
| c.boolFlags[key] = value | ||
| } | ||
|
|
||
| func (c *Context) GetIntFlagValue(flagName string) (value int, err error) { | ||
| parsed, err := strconv.ParseInt(c.GetStringFlagValue(flagName), 0, 64) | ||
| if err != nil { | ||
|
|
@@ -74,6 +84,19 @@ func (c *Context) GetIntFlagValue(flagName string) (value int, err error) { | |
| return | ||
| } | ||
|
|
||
| func (c *Context) GetDefaultIntFlagValueIfNotSet(flagName string, defaultValue int) (value int, err error) { | ||
| if c.IsFlagSet(flagName) { | ||
| 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, err | ||
| } | ||
| value = int(parsed) | ||
| return value, err | ||
| } | ||
| return defaultValue, nil | ||
| } | ||
|
|
||
| func (c *Context) GetBoolFlagValue(flagName string) bool { | ||
| return c.boolFlags[flagName] | ||
| } | ||
|
|
@@ -183,6 +206,18 @@ func WithBoolDefaultValueFalse() BoolFlagOption { | |
| } | ||
| } | ||
|
|
||
| func WithHiddenTrue() StringFlagOption { | ||
|
||
| return func(f *StringFlag) { | ||
| f.Hidden = true | ||
| } | ||
| } | ||
|
|
||
| func WithBoolDefaultValueTrue() BoolFlagOption { | ||
| return func(f *BoolFlag) { | ||
| f.DefaultValue = true | ||
| } | ||
| } | ||
|
|
||
| type BoolFlag struct { | ||
| BaseFlag | ||
| DefaultValue bool | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.