github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/npm/args.go (about)

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