Skip to content

Commit

Permalink
💬 Rewrite input of CLI
Browse files Browse the repository at this point in the history
For better clarity, rewrote error printing and Gut save help messages
  • Loading branch information
julien040 committed Dec 27, 2022
1 parent 7eaccf5 commit a0d0f93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ import (

// An helper function to exit the program if an error occurs
func exitOnError(str string, err error) {
fmt.Println("")
if err != nil {
print.Message(str, print.Error)
fmt.Println(err)
if str != "" {
print.Message(str, print.Error)
}
fmt.Printf("Error message: %s\n", err)
print.Message("If this error persists, please open an issue on GitHub: https://github.com/julien040/gut/issues/new", print.None)
print.Message("Exiting...\n", print.Info)
os.Exit(1)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/controller/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ func Save(cmd *cobra.Command, args []string) {
var qs = []*survey.Question{
{
Name: "Type",
Prompt: &survey.Select{Message: "Select an emoji:", Options: emojiList(), PageSize: 12, Help: "Select an emoji to describe your commit"},
Prompt: &survey.Select{Message: "Select a category", Options: emojiList(), PageSize: 12, Help: "Gut uses emojis to categorize your commits. Select an emoji that best describes your commit"},
Validate: survey.Required,
},
}
if title == "" || len(title) > 50 {
qs = append(qs, &survey.Question{
Name: "Titre",
Prompt: &survey.Input{Message: "What describes best your commit? (max 50 chars)", Help: "Write a short description of your commit (max 50 chars)"},
Prompt: &survey.Input{Message: "Title of your commit (max 50 chars)", Help: "Ask yourself what you did in this commit | Use active voice | Avoid using 'and' or 'or'"},
Validate: titleValidation,
})
} else {
Expand All @@ -124,7 +124,7 @@ func Save(cmd *cobra.Command, args []string) {
if message == "" {
qs = append(qs, &survey.Question{
Name: "Description",
Prompt: &survey.Multiline{Message: "Describe your commit (optional)", Help: "Write a description of your commit (optional)"},
Prompt: &survey.Multiline{Message: "Describe your commit (optional)", Help: "Write a description of your commit. Explain why you did this commit and assume that you are explaining to a colleague who knows nothing about the codebase"},
},
)
} else {
Expand All @@ -133,15 +133,15 @@ func Save(cmd *cobra.Command, args []string) {

err = survey.Ask(qs, &answers)
if err != nil {
exitOnError("Error while asking questions", err)
exitOnError("We can't get your answers", err)
}
commitMessage := computeCommitMessage(answers)
Result, err := executor.Commit(wd, commitMessage)
if err != nil {
exitOnError("Error while committing", err)
}
print.Message("Changes updated successfully with commit hash: "+Result.Hash, print.Success)
fmt.Printf("%d files changed, %d insertions(+), %d deletions(-)", Result.FilesUpdated, Result.FilesAdded, Result.FilesDeleted)
print.Message("\n\nChanges updated successfully with commit hash: "+Result.Hash, print.Success)
fmt.Printf("%d files changed, %d insertions(+), %d deletions(-)\n", Result.FilesUpdated, Result.FilesAdded, Result.FilesDeleted)

}

Expand Down

0 comments on commit a0d0f93

Please sign in to comment.