|
// existsOrCreate checks to see if a plan file and markdown exist or were created |
|
// Prints to terminal stating so |
|
func existsOrCreated(files []tpFile) error { |
|
for _, v := range files { |
|
exists := doesExist(v.Name) |
|
if exists { |
|
Logger.Debugf("%s file %s was created.", v.Purpose, v.Name) |
|
fmt.Fprintf(color.Output, "%s %s%s\n", |
|
bold(green("✔")), v.Purpose, " Created...") |
|
} else if !exists { |
|
// |
|
Logger.Errorf("Markdown file %s was not created.", v.Name) |
|
fmt.Fprintf(color.Output, "%s %s%s\n", |
|
bold(red("✕")), v.Purpose, " Failed to Create ...") |
|
} else { |
|
// I'm only human. NFC how you got here. I hope to never have to find out. |
|
Logger.Errorf("If you see this error message, please open a bug. Error Code: TPE003. Error: %s", err) |
|
} |
|
} |
|
return err |
|
} |
existsOrCreated() is a bit misleading. "Does the file exist?" It may or may not. If it does, "Was it created? (by us?)" That's the edge case. It may not have been by us, rather it could be a remanant from a previous run or something else entirely. But we report that it was created simply because it exists.
Because of the generic nature of the file name and simply checking that the file exists as a way to say we created it, we may never know if it is fact the file we created. We need a unique identifier related to the file to have an awareness that that is in fact the file we created.
Brainstorming
- We could possibly move the logic to the planMd, err = os.Create(mdParam) so that when this is
Close()'d we could do the 'File created' message there.
- We could prepend a unique ID to each file and use that as the identifier to know that that file is in fact the file we created.
- Put a UUID in a comment in the markdown and parse the UUID to identify that that file is in fact the file we created.
- Create a hash or md5sum of the file and use that to calculate that that is in fact the file we created.
gh-tp/cmd/tools.go
Lines 34 to 54 in 75a65e4
existsOrCreated()is a bit misleading. "Does the file exist?" It may or may not. If it does, "Was it created? (by us?)" That's the edge case. It may not have been by us, rather it could be a remanant from a previous run or something else entirely. But we report that it was created simply because it exists.Because of the generic nature of the file name and simply checking that the file exists as a way to say we created it, we may never know if it is fact the file we created. We need a unique identifier related to the file to have an awareness that that is in fact the file we created.
Brainstorming
Close()'d we could do the 'File created' message there.