MCPcopy Create free account
hub / github.com/apache/openwhisk-cli / ReadFile

Function ReadFile

commands/util.go:935–964  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

933}
934
935func ReadFile(filename string) (string, error) {
936 exists, err := FileExists(filename)
937
938 if err != nil {
939 return "", err
940 }
941
942 if !exists {
943 errMsg := wski18n.T("File '{{.name}}' is not a valid file or it does not exist",
944 map[string]interface{}{
945 "name": filename,
946 })
947 whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_USAGE,
948 whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
949
950 return "", whiskErr
951 }
952
953 file, err := ioutil.ReadFile(filename)
954 if err != nil {
955 whisk.Debug(whisk.DbgError, "os.ioutil.ReadFile(%s) error: %s\n", filename, err)
956 errMsg := wski18n.T("Unable to read the file '{{.name}}': {{.err}}",
957 map[string]interface{}{"name": filename, "err": err})
958 whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL,
959 whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
960 return "", whiskErr
961 }
962
963 return string(file), nil
964}
965
966func writeFile(filename string, content string) error {
967 file, err := os.Create(filename)

Callers 3

parseSwaggerApiFunction · 0.70
parseArgsFunction · 0.70
getExecFunction · 0.70

Calls 1

FileExistsFunction · 0.85

Tested by

no test coverage detected