-
Notifications
You must be signed in to change notification settings - Fork 55
/
args.go
38 lines (33 loc) · 1.29 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package npm
import (
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/utils/coreutils"
"strconv"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
)
func ExtractNpmOptionsFromArgs(args []string) (threads int, jsonOutput bool, cleanArgs []string, buildConfig *utils.BuildConfiguration, err error) {
threads = 3
// Extract threads information from the args.
flagIndex, valueIndex, numOfThreads, err := coreutils.FindFlag("--threads", args)
if err != nil {
return
}
coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
if numOfThreads != "" {
threads, err = strconv.Atoi(numOfThreads)
if err != nil {
err = errorutils.CheckError(err)
return
}
}
// Since we use --json flag for retrieving the npm config for writing the temp .npmrc, json=true is written to the config list.
// We don't want to force the json output for all users, so we check whether the json output was explicitly required.
flagIndex, jsonOutput, err = coreutils.FindBooleanFlag("--json", args)
if err != nil {
return
}
// Since boolean flag might appear as --flag or --flag=value, the value index is the same as the flag index.
coreutils.RemoveFlagFromCommand(&args, flagIndex, flagIndex)
cleanArgs, buildConfig, err = utils.ExtractBuildDetailsFromArgs(args)
return
}