1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-17 00:18:05 +02:00

Bump git-todo-parser

This commit is contained in:
Gustavo Krieger
2023-07-02 00:52:25 -03:00
parent cff9850374
commit 87fe30d50d
8 changed files with 19 additions and 21 deletions

View File

@ -16,7 +16,7 @@ var (
ErrMissingRef = errors.New("missing ref")
)
func Parse(f io.Reader) ([]Todo, error) {
func Parse(f io.Reader, commentChar byte) ([]Todo, error) {
var result []Todo
scanner := bufio.NewScanner(f)
@ -30,7 +30,7 @@ func Parse(f io.Reader) ([]Todo, error) {
continue
}
cmd, err := parseLine(line)
cmd, err := parseLine(line, commentChar)
if err != nil {
return nil, fmt.Errorf("failed to parse line %q: %w", line, err)
}
@ -45,12 +45,12 @@ func Parse(f io.Reader) ([]Todo, error) {
return result, nil
}
func parseLine(line string) (Todo, error) {
func parseLine(line string, commentChar byte) (Todo, error) {
var todo Todo
if strings.HasPrefix(line, CommentChar) {
if line[0] == commentChar {
todo.Command = Comment
todo.Comment = strings.TrimLeft(line, CommentChar)
todo.Comment = line[1:]
return todo, nil
}
@ -143,8 +143,8 @@ func parseLine(line string) (Todo, error) {
todo.Commit = fields[0]
fields = fields[1:]
// Trim # and whitespace
todo.Msg = strings.TrimPrefix(strings.Join(fields, " "), CommentChar+" ")
// Trim comment char and whitespace
todo.Msg = strings.TrimPrefix(strings.Join(fields, " "), fmt.Sprintf("%c ", commentChar))
return todo, nil
}

View File

@ -23,8 +23,6 @@ const (
Comment
)
const CommentChar = "#"
type Todo struct {
Command TodoCommand
Commit string

View File

@ -5,9 +5,9 @@ import (
"strings"
)
func Write(f io.Writer, todos []Todo) error {
func Write(f io.Writer, todos []Todo, commentChar byte) error {
for _, todo := range todos {
if err := writeTodo(f, todo); err != nil {
if err := writeTodo(f, todo, commentChar); err != nil {
return err
}
}
@ -15,7 +15,7 @@ func Write(f io.Writer, todos []Todo) error {
return nil
}
func writeTodo(f io.Writer, todo Todo) error {
func writeTodo(f io.Writer, todo Todo, commentChar byte) error {
var sb strings.Builder
if todo.Command != Comment {
sb.WriteString(todo.Command.String())
@ -26,7 +26,7 @@ func writeTodo(f io.Writer, todo Todo) error {
return nil
case Comment:
sb.WriteString(CommentChar)
sb.WriteByte(commentChar)
sb.WriteString(todo.Comment)
case Break: