in cmd/utils.go [66:114]
func parseArgsForParams(args []string) ([]string, []string, error) {
var paramArgs []string
var err error
i := 0
// iterate over the list of input arguments
// append key value pair of --param <parameter name> <parameter value> as a string
// in case of --param-file, read parameter file, append each JSON "key: value" pair as a string
for i < len(args) {
// when arg is -P or --param-file, open and read the specified JSON file
if args[i] == SHORT_CMD+FLAG_PARAMFILE_SHORT || args[i] == LONG_CMD+FLAG_PARAMFILE {
// Command line parser library Cobra, assigns value of --param-file to utils.Flags.ParamFile
// but at this point of execution, we still don't have utils.Flags.ParamFile assigned any value
// and that's the reason, we have to explicitly parse the argument list to get the file name
paramArgs, args, err = getValueFromArgs(args, i, paramArgs)
if err != nil {
return nil, nil, err
}
filename := paramArgs[len(paramArgs)-1]
// drop the argument (--param-file) and its value from the argument list after retrieving filename
// read file content as a single string and append it to the list of params
file, readErr := ioutil.ReadFile(filename)
if readErr != nil {
err = wskderrors.NewCommandError(FLAG_PARAMFILE+"/"+FLAG_PARAMFILE_SHORT,
wski18n.T(wski18n.ID_ERR_INVALID_PARAM_FILE_X_file_X,
map[string]interface{}{
wski18n.KEY_PATH: filename,
wski18n.KEY_ARG: FLAG_PARAMFILE + "/" + FLAG_PARAMFILE_SHORT,
wski18n.KEY_ERR: readErr}))
return nil, nil, err
}
paramArgs[len(paramArgs)-1] = string(file)
// --param can appear multiple times in a single invocation of whisk deploy
// for example, wskdeploy -m manifest.yaml --param key1 value1 --param key2 value2
// parse key value map for each --param from the argument list
// drop each --param and key value map from the argument list after reading the map
// append key value as a string to the list of params
} else if args[i] == LONG_CMD+FLAG_PARAM {
paramArgs, args, err = getKeyValueArgs(args, i, paramArgs)
if err != nil {
return nil, nil, err
}
} else {
i++
}
}
return args, paramArgs, nil
}