Add number-lines processor#65
Conversation
numberlines prepends non-empty lines with consecutive numbers
processors/numberlines.go
Outdated
| } | ||
|
|
||
| func (p LineNumberer) Alias() []string { | ||
| return []string{"nl", "number-lines"} |
There was a problem hiding this comment.
There is no need to add the name as an alias
| return []string{"nl", "number-lines"} | |
| return []string{"nl"} |
| type LineNumberer struct{} | ||
|
|
||
| func (p LineNumberer) Name() string { | ||
| return "number-lines" |
There was a problem hiding this comment.
I'm unsure about the name here
There was a problem hiding this comment.
So am I. Initially I wanted "line-numbers" and the matching alias "ln" would suggest creating links. And "nl" alias mimicks the "nl" binary from coreutils, so I went this path...
processors/numberlines.go
Outdated
| result += line | ||
| } else { | ||
| result += fmt.Sprintf("%d. %s", counter, line) | ||
| counter += 1 |
There was a problem hiding this comment.
| counter += 1 | |
| counter++ |
processors/numberlines.go
Outdated
| if line == "\n" { | ||
| result += line |
There was a problem hiding this comment.
What is this case?
When does it happen?
There was a problem hiding this comment.
We keep empty lines on output but we don't want to number them.
processors/numberlines.go
Outdated
| } | ||
|
|
||
| func (p LineNumberer) Transform(data []byte, _ ...Flag) (string, error) { | ||
| var s = string(data[:]) |
There was a problem hiding this comment.
| var s = string(data[:]) | |
| var s = string(data) |
This, no?
processors/numberlines.go
Outdated
| } | ||
|
|
||
| } | ||
| return result, err |
There was a problem hiding this comment.
Don't add an err variable, simply do this
| return result, err | |
| return result, nil |
processors/numberlines.go
Outdated
| if line == "\n" { | ||
| result += line | ||
| } else { | ||
| result += fmt.Sprintf("%d. %s", counter, line) |
There was a problem hiding this comment.
We may consider to pad with space
Because
1. foo
…
9. foo
10. too
could be this
1. foo
…
9. foo
10. too
Or this
1. foo
…
9. foo
10. too
There was a problem hiding this comment.
I try left-pad (last suggestion above) in 8c8c68e.
|
Hello @kamchy many thanks for adding this new feature 👏 💯 🥳 Whats next: I will check and merge it over this week and do a new release. |
number-lines(alias:nl) prepends consecutive numbers to non-empty lines.