Skip to content

Commit bb6e84a

Browse files
Add extra padding in subcommand section (#170)
* Tweak lint/format rules * Add extra padding in subcommand section
1 parent ce0cd08 commit bb6e84a

8 files changed

Lines changed: 20 additions & 3 deletions

File tree

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ formatters:
44
enable:
55
- gofumpt
66
- goimports
7+
- golines
78

89
settings:
910
gofumpt:
1011
extra-rules: true
1112

13+
golines:
14+
max-len: 140
15+
shorten-comments: true
16+
reformat-tags: true
17+
1218
linters:
1319
default: all
1420
disable:

Taskfile.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ tasks:
2525
desc: Run go fmt on all source files
2626
sources:
2727
- "**/*.go"
28+
- .golangci.yml
2829
cmds:
29-
- go fmt ./...
30+
- golangci-lint fmt ./...
3031

3132
test:
3233
desc: Run the test suite
3334
sources:
3435
- "**/*.go"
35-
- testdata/**/*.txt
36+
- "**/testdata/**/*"
3637
- go.mod
3738
- go.sum
3839
cmds:

command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ func writeSubcommands(cmd *Command, s *strings.Builder) error {
674674

675675
s.WriteString(colour.Title("Commands"))
676676
s.WriteByte(':')
677-
s.WriteByte('\n')
677+
s.WriteString("\n\n")
678678

679679
tab := table.New(s)
680680
for _, subcommand := range cmd.subcommands {

internal/flag/set_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ func TestFlagSet(t *testing.T) {
948948

949949
err = flag.AddToSet(set, f)
950950
test.Err(t, err)
951+
951952
if err != nil {
952953
test.Equal(t, err.Error(), "cannot add flag to a nil set")
953954
}
@@ -961,6 +962,7 @@ func TestFlagSet(t *testing.T) {
961962
test: func(t *testing.T, set *flag.Set) {
962963
err := set.Parse([]string{"args", "here", "doesn't", "matter"})
963964
test.Err(t, err)
965+
964966
if err != nil {
965967
test.Equal(t, err.Error(), "Parse called on a nil set")
966968
}
@@ -990,6 +992,7 @@ func TestFlagSet(t *testing.T) {
990992
// Add the same flag again
991993
err = flag.AddToSet(set, f)
992994
test.Err(t, err)
995+
993996
if err != nil {
994997
test.Equal(t, err.Error(), `flag "count" already defined`)
995998
}
@@ -1013,6 +1016,7 @@ func TestFlagSet(t *testing.T) {
10131016
// Add the different flag with the same na,e
10141017
err = flag.AddToSet(set, f2)
10151018
test.Err(t, err)
1019+
10161020
if err != nil {
10171021
test.Equal(t, err.Error(), `flag "count" already defined`)
10181022
}
@@ -1036,6 +1040,7 @@ func TestFlagSet(t *testing.T) {
10361040
// Add the different flag with the same na,e
10371041
err = flag.AddToSet(set, f2)
10381042
test.Err(t, err)
1043+
10391044
if err != nil {
10401045
test.Equal(t, err.Error(), `shorthand "c" already in use for flag "count"`)
10411046
}

internal/table/table.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func New(w io.Writer) Table {
3030
}
3131

3232
// Row adds a row to the [Table].
33+
//
34+
//nolint:goprintffuncname // I like it this way
3335
func (t Table) Row(format string, a ...any) {
3436
fmt.Fprintf(t.tw, format, a...)
3537
}

testdata/snapshots/TestHelp/subcommands_different_lengths.snap.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A longer, probably multiline description
55
Usage: test [OPTIONS] COMMAND
66

77
Commands:
8+
89
sub1 Do one thing
910
sub2 Do another thing
1011
very-long-subcommand Wow so long

testdata/snapshots/TestHelp/with_subcommands.snap.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A longer, probably multiline description
55
Usage: test [OPTIONS] COMMAND
66

77
Commands:
8+
89
sub1 Do one thing
910
sub2 Do another thing
1011

testdata/snapshots/TestHelp/with_subcommands_and_flags.snap.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A longer, probably multiline description
55
Usage: test [OPTIONS] COMMAND
66

77
Commands:
8+
89
sub1 Do one thing
910
sub2 Do another thing
1011

0 commit comments

Comments
 (0)