mdeuser commented on a change in pull request #2544: Allow CLI to Save Code from Action URL: https://github.com/apache/incubator-openwhisk/pull/2544#discussion_r144969129
########## File path: tools/cli/go-whisk-cli/commands/action.go ########## @@ -495,6 +513,87 @@ func getExec(args []string, params ActionFlags) (*whisk.Exec, error) { return exec, nil } +func getBinaryKindExtension(kind string) (extension string){ + switch strings.ToLower(kind) { + case JAVA: + extension = JAVA_EXT + default: + extension = ZIP_EXT + } + + return extension +} + +func getKindExtension(kind string) (extension string){ + switch strings.ToLower(kind) { + case NODE_JS: + extension = NODE_JS_EXT + case PYTHON: + extension = PYTHON_EXT + case SWIFT: + fallthrough + case PHP: + extension = "." + kind + } + + return extension +} + +func saveCode(action whisk.Action, filename string) (err error) { + var code string + var kind string + var exec whisk.Exec + + exec = *action.Exec + kind = strings.Split(exec.Kind, ":")[0] + + if strings.ToLower(kind) == BLACKBOX { + return cannotSaveImageError() + } else if strings.ToLower(kind) == SEQUENCE { + return cannotSaveSequenceError() + } + + if exec.Code == nil { + code = "" + } else { + code = *exec.Code + } + + if *exec.Binary { + decoded, _ := base64.StdEncoding.DecodeString(code) + code = string(decoded) + + if len(filename) == 0 { + filename = action.Name + getBinaryKindExtension(kind) + } + } else { + if len(filename) == 0 { + filename = action.Name + getKindExtension(kind) + } + } + + if exists, err := FileExists(filename); err != nil { + return err + } else if exists { + return fileExistsError(filename) + } + + if err := writeFile(filename, code); err != nil { + return err + } + + pwd, err := os.Getwd() + if err != nil { + return err Review comment: log an error message indicating that it was the `os.Getwd` function that failed ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services