diff options
author | xengineering <me@xengineering.eu> | 2024-07-06 09:14:10 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-07-06 09:14:10 +0200 |
commit | b8f4ee66c9bcf1e31b233a9beaa0aa693eae2a89 (patch) | |
tree | 44d305ca053fb08d541d58b75d9907b10d5ed3f8 | |
parent | 2942b48b87a08de1dab8ca23c66fc5ffa659c50b (diff) | |
download | craft-b8f4ee66c9bcf1e31b233a9beaa0aa693eae2a89.tar craft-b8f4ee66c9bcf1e31b233a9beaa0aa693eae2a89.tar.zst craft-b8f4ee66c9bcf1e31b233a9beaa0aa693eae2a89.zip |
Modify log output
- exit message
- more consistent messages
- refactoring to implement this
-rw-r--r-- | main.go | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -14,17 +14,17 @@ import ( func main() { log.SetFlags(0) + defer log.Println("Exiting craft") log.Println("Starting craft") log.Printf("Git hook type: %s\n", getHookType()) - - cwd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - fmt.Printf("Current working directory: %s\n", cwd) + log.Printf("Git repository: %s\n", getRepositoryPath()) for { - fmt.Println(getUpdate()) + eof, update := getUpdate() + if eof { + break + } + log.Printf("Git ref update: %s\n", update) } } @@ -55,24 +55,32 @@ func validateHookType(hookType string) { log.Fatalf("Not supported Git hook type '%s'\n", hookType) } +func getRepositoryPath() string { + cwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + return cwd +} + type update struct { old, updated, ref string } func (u update) String() string { - ret := fmt.Sprintf("'%s' updated from '%s' to '%s'", u.ref, u.old, u.updated) + ret := fmt.Sprintf("'%s' from '%s' to '%s'", u.ref, u.old, u.updated) return ret } -func getUpdate() update { +func getUpdate() (bool, update) { var u update _, err := fmt.Scanf("%s %s %s\n", &u.old, &u.updated, &u.ref) if err != nil { if errors.Is(err, io.EOF) { - os.Exit(0) + return true, u } else { log.Fatal(err) } } - return u + return false, u } |