Skip to content

Commit

Permalink
Make extract function generic
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Nov 18, 2024
1 parent 3df4169 commit df2772a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 1 addition & 13 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func NugetCmd(c *cli.Context) error {
return err
}

allowInsecureConnection, err := extractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections")
allowInsecureConnection, err := cliutils.ExtractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections")
if err != nil {
return err
}
Expand Down Expand Up @@ -1083,15 +1083,3 @@ func getTwineConfigPath() (configFilePath string, err error) {
}
return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config"))
}

// Extracts the boolean flag from the args and removes it from the args.
func extractBoolFlagFromArgs(filteredNugetArgs *[]string, flagName string) (value bool, err error) {
var flagIndex int
var allowInsecureConnection bool
flagIndex, allowInsecureConnection, err = coreutils.FindBooleanFlag("--"+flagName, *filteredNugetArgs)
if err != nil {
return false, err
}
coreutils.RemoveFlagFromCommand(filteredNugetArgs, flagIndex, flagIndex)
return allowInsecureConnection, nil
}
12 changes: 12 additions & 0 deletions utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,3 +809,15 @@ func getDebFlag(c *cli.Context) (deb string, err error) {
}
return deb, nil
}

// ExtractBoolFlagFromArgs Extracts a boolean flag from the args and removes it from the slice.
func ExtractBoolFlagFromArgs(filteredArgs *[]string, flagName string) (value bool, err error) {
var flagIndex int
var boolFlag bool
flagIndex, boolFlag, err = coreutils.FindBooleanFlag("--"+flagName, *filteredArgs)
if err != nil {
return false, err
}
coreutils.RemoveFlagFromCommand(filteredArgs, flagIndex, flagIndex)
return boolFlag, nil
}

0 comments on commit df2772a

Please sign in to comment.