Skip to content

Commit 6d6ab09

Browse files
authored
Merge pull request #18 from 6543-forks/gofumpt
format with `gofumpt -w .`
2 parents bec0736 + f37e18b commit 6d6ab09

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

docs.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func ToTabularMarkdown(cmd *cli.Command, appPath string) (string, error) {
9898
// ToTabularToFileBetweenTags creates a tabular markdown documentation for the `*App` and updates the file between
9999
// the tags in the file. The function errors if either parsing or writing of the string fails.
100100
func ToTabularToFileBetweenTags(cmd *cli.Command, appPath, filePath string, startEndTags ...string) error {
101-
var start, end = "<!--GENERATED:CLI_DOCS-->", "<!--/GENERATED:CLI_DOCS-->" // default tags
101+
start, end := "<!--GENERATED:CLI_DOCS-->", "<!--/GENERATED:CLI_DOCS-->" // default tags
102102

103103
if len(startEndTags) == 2 {
104104
start, end = startEndTags[0], startEndTags[1]
@@ -128,7 +128,7 @@ func ToTabularToFileBetweenTags(cmd *cli.Command, appPath, filePath string, star
128128
updated := re.ReplaceAll(content, []byte(strings.Join([]string{start, comment, md, end}, "\n")))
129129

130130
// write updated content to file
131-
if err = os.WriteFile(filePath, updated, 0664); err != nil {
131+
if err = os.WriteFile(filePath, updated, 0o664); err != nil {
132132
return err
133133
}
134134

@@ -364,10 +364,10 @@ type tabularTemplate struct{}
364364

365365
// PrepareCommands converts CLI commands into a structs for the rendering.
366366
func (tt tabularTemplate) PrepareCommands(commands []*cli.Command, appPath, parentCommandName string, level uint) []cliTabularCommandTemplate {
367-
var result = make([]cliTabularCommandTemplate, 0, len(commands))
367+
result := make([]cliTabularCommandTemplate, 0, len(commands))
368368

369369
for _, cmd := range commands {
370-
var command = cliTabularCommandTemplate{
370+
command := cliTabularCommandTemplate{
371371
AppPath: appPath,
372372
Name: strings.TrimSpace(strings.Join([]string{parentCommandName, cmd.Name}, " ")),
373373
Aliases: cmd.Aliases,
@@ -394,15 +394,15 @@ func (tt tabularTemplate) PrepareCommands(commands []*cli.Command, appPath, pare
394394

395395
// PrepareFlags converts CLI flags into a structs for the rendering.
396396
func (tt tabularTemplate) PrepareFlags(flags []cli.Flag) []cliTabularFlagTemplate {
397-
var result = make([]cliTabularFlagTemplate, 0, len(flags))
397+
result := make([]cliTabularFlagTemplate, 0, len(flags))
398398

399399
for _, appFlag := range flags {
400400
flag, ok := appFlag.(cli.DocGenerationFlag)
401401
if !ok {
402402
continue
403403
}
404404

405-
var f = cliTabularFlagTemplate{
405+
f := cliTabularFlagTemplate{
406406
Usage: tt.PrepareMultilineString(flag.GetUsage()),
407407
EnvVars: flag.GetEnvVars(),
408408
TakesValue: flag.TakesValue(),
@@ -449,7 +449,7 @@ func (tabularTemplate) PrepareMultilineString(s string) string {
449449
}
450450

451451
func (tabularTemplate) Prettify(s string) string {
452-
var max = func(x, y int) int {
452+
max := func(x, y int) int {
453453
if x > y {
454454
return x
455455
}
@@ -460,14 +460,14 @@ func (tabularTemplate) Prettify(s string) string {
460460

461461
// search for tables
462462
for _, rawTable := range regexp.MustCompile(`(?m)^(\|[^\n]+\|\r?\n)((?:\|:?-+:?)+\|)(\n(?:\|[^\n]+\|\r?\n?)*)?$`).FindAllString(s, -1) {
463-
var lines = strings.FieldsFunc(rawTable, func(r rune) bool { return r == '\n' })
463+
lines := strings.FieldsFunc(rawTable, func(r rune) bool { return r == '\n' })
464464

465465
if len(lines) < 3 { // header, separator, body
466466
continue
467467
}
468468

469469
// parse table into the matrix
470-
var matrix = make([][]string, 0, len(lines))
470+
matrix := make([][]string, 0, len(lines))
471471
for _, line := range lines {
472472
items := strings.FieldsFunc(strings.Trim(line, "| "), func(r rune) bool { return r == '|' })
473473

@@ -479,13 +479,13 @@ func (tabularTemplate) Prettify(s string) string {
479479
}
480480

481481
// determine centered columns
482-
var centered = make([]bool, 0, len(matrix[1]))
482+
centered := make([]bool, 0, len(matrix[1]))
483483
for _, cell := range matrix[1] {
484484
centered = append(centered, strings.HasPrefix(cell, ":") && strings.HasSuffix(cell, ":"))
485485
}
486486

487487
// calculate max lengths
488-
var lengths = make([]int, len(matrix[0]))
488+
lengths := make([]int, len(matrix[0]))
489489
for n, row := range matrix {
490490
for i, cell := range row {
491491
if n == 1 {
@@ -571,7 +571,7 @@ func getFlagDefaultValue(f cli.DocGenerationFlag) string {
571571
return v.GetValue()
572572
}
573573

574-
var ref = reflect.ValueOf(f)
574+
ref := reflect.ValueOf(f)
575575
if ref.Kind() != reflect.Ptr {
576576
return ""
577577
} else {

docs_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import (
1313
"github.com/urfave/cli/v3"
1414
)
1515

16-
var (
17-
//go:embed testdata
18-
testdata embed.FS
19-
)
16+
//go:embed testdata
17+
var testdata embed.FS
2018

2119
func expectFileContent(t *testing.T, file, got string) {
2220
data, err := testdata.ReadFile(file)

0 commit comments

Comments
 (0)