Skip to content

Commit

Permalink
fix(cli): don't drop body from -m args
Browse files Browse the repository at this point in the history
  • Loading branch information
SKalt committed Aug 10, 2024
1 parent c72bb94 commit b39bbde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {
message, _ := cmd.Flags().GetStringArray("message")

if len(message) > 0 {
//> If multiple `-m` options are given, their values are concatenated as separate paragraphs.
//> see https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---messageltmsggt
cc, _ = parser.ParseAsMuchOfCCAsPossible(strings.Join(message, "\n\n"))
} else {
cc, _ = parser.ParseAsMuchOfCCAsPossible((strings.Join(args, " ")))
Expand Down
20 changes: 16 additions & 4 deletions cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type model struct {
// the width of the terminal; needed for instantiating components
// width int
choice chan string
// any body stashed during the initial parse of command-line --message args
remainingBody string
}

// returns whether the minimum requirements for a conventional commit are met.
Expand All @@ -73,17 +75,26 @@ func (m model) contextValue() string {
result.WriteString(": ")
return result.String()
}
func (m model) descriptionValue() string {
return m.commit[shortDescriptionIndex]
}
func (m model) breakingChangeValue() string {
return m.commit[breakingChangeIndex]
}

// Returns a pretty-printed CC string. The model should be `.ready()` before you call `.value()`.
func (m model) value() string {
result := strings.Builder{}
result.WriteString(m.contextValue())
result.WriteString(m.commit[shortDescriptionIndex])
result.WriteString(m.descriptionValue())
result.WriteString("\n")
breakingChange := m.commit[breakingChangeIndex]
if breakingChange != "" {
result.WriteString(fmt.Sprintf("\n\nBREAKING CHANGE: %s\n", breakingChange))
if m.remainingBody != "" {
result.WriteString(m.remainingBody)
result.WriteString("\n")
}
if breakingChange := m.breakingChangeValue(); breakingChange != "" {
// TODO: handle multiple breaking change footers(?)
result.WriteString(fmt.Sprintf("\n\nBREAKING CHANGE: %s\n", breakingChange))
}
return result.String()
}
Expand Down Expand Up @@ -134,6 +145,7 @@ func initialModel(choice chan string, cc *parser.CC, cfg *config.Cfg) model {
descriptionInput: descModel,
breakingChangeInput: bcModel,
viewing: commitTypeIndex,
remainingBody: cc.Body,
}
if m.shouldSkip(m.viewing) {
m = m.submit().advance()
Expand Down

0 comments on commit b39bbde

Please sign in to comment.