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

Function writeFile

commands/util.go:966–990  ·  view source on GitHub ↗
(filename string, content string)

Source from the content-addressed store, hash-verified

964}
965
966func writeFile(filename string, content string) error {
967 file, err := os.Create(filename)
968
969 if err != nil {
970 whisk.Debug(whisk.DbgError, "os.Create(%s) error: %#v\n", filename, err)
971 errMsg := wski18n.T("Cannot create file '{{.name}}': {{.err}}",
972 map[string]interface{}{"name": filename, "err": err})
973 whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_USAGE, whisk.DISPLAY_MSG,
974 whisk.DISPLAY_USAGE)
975 return whiskErr
976 }
977
978 defer file.Close()
979
980 if _, err = file.WriteString(content); err != nil {
981 whisk.Debug(whisk.DbgError, "File.WriteString(%s) error: %#v\n", content, err)
982 errMsg := wski18n.T("Cannot create file '{{.name}}': {{.err}}",
983 map[string]interface{}{"name": filename, "err": err})
984 whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_USAGE, whisk.DISPLAY_MSG,
985 whisk.DISPLAY_USAGE)
986 return whiskErr
987 }
988
989 return nil
990}
991
992func FileExists(file string) (bool, error) {
993 _, err := os.Stat(file)

Callers 1

saveCodeFunction · 0.85

Calls 1

CreateMethod · 0.80

Tested by

no test coverage detected