Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gofumpt to CI #1899

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ permissions:
contents: read

jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20"

- name: Clone repository
uses: actions/checkout@v4

- name: Set up gofumpt
run: go install mvdan.cc/gofumpt@latest

- name: Run gofumpt
run: |
non_formatted_files="$(gofumpt -l .)"
echo "$non_formatted_files"
test -z "$non_formatted_files"

staticcheck:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ jobs:

- name: Set PATH
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- if: matrix.go == '1.20.x' && matrix.os == 'ubuntu-latest'
run: make ensure-goimports

- if: matrix.go == '1.20.x' && matrix.os == 'ubuntu-latest'
run: make lint

- run: make vet
- run: make test
- run: make check-binary-size

- if: matrix.go == '1.20.x' && matrix.os == 'ubuntu-latest'
run: make generate

- run: make diffcheck

- if: matrix.go == '1.20.x' && matrix.os == 'ubuntu-latest'
run: make v3diff

- if: success() && matrix.go == '1.20.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
Expand Down
14 changes: 8 additions & 6 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {
return s[count:], nil
}

type FloatArg = ArgumentBase[float64, NoConfig, floatValue]
type IntArg = ArgumentBase[int64, IntegerConfig, intValue]
type StringArg = ArgumentBase[string, StringConfig, stringValue]
type StringMapArg = ArgumentBase[map[string]string, StringConfig, StringMap]
type TimestampArg = ArgumentBase[time.Time, TimestampConfig, timestampValue]
type UintArg = ArgumentBase[uint64, IntegerConfig, uintValue]
type (
FloatArg = ArgumentBase[float64, NoConfig, floatValue]
IntArg = ArgumentBase[int64, IntegerConfig, intValue]
StringArg = ArgumentBase[string, StringConfig, stringValue]
StringMapArg = ArgumentBase[map[string]string, StringConfig, StringMap]
TimestampArg = ArgumentBase[time.Time, TimestampConfig, timestampValue]
UintArg = ArgumentBase[uint64, IntegerConfig, uintValue]
)
2 changes: 0 additions & 2 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestArgumentsRootCommand(t *testing.T) {

cmd := buildMinimalTestCommand()
var ival int64
var fval float64
Expand Down Expand Up @@ -48,7 +47,6 @@ func TestArgumentsRootCommand(t *testing.T) {
}

func TestArgumentsSubcommand(t *testing.T) {

cmd := buildMinimalTestCommand()
var ifval int64
var svals []string
Expand Down
4 changes: 1 addition & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import (
"strings"
)

var (
isTracingOn = os.Getenv("URFAVE_CLI_TRACING") == "on"
)
var isTracingOn = os.Getenv("URFAVE_CLI_TRACING") == "on"

func tracef(format string, a ...any) {
if !isTracingOn {
Expand Down
7 changes: 2 additions & 5 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,8 @@ func TestPersistentFlag(t *testing.T) {
},
}

err := cmd.Run(buildTestContext(t), []string{"app",
err := cmd.Run(buildTestContext(t), []string{
"app",
"--persistentCommandFlag", "hello",
"--persistentCommandSliceFlag", "100",
"--persistentCommandOverrideFlag", "102",
Expand Down Expand Up @@ -2903,7 +2904,6 @@ func TestPersistentFlag(t *testing.T) {
}

func TestPersistentFlagIsSet(t *testing.T) {

result := ""
resultIsSet := false

Expand Down Expand Up @@ -2939,7 +2939,6 @@ func TestPersistentFlagIsSet(t *testing.T) {
}

func TestRequiredPersistentFlag(t *testing.T) {

app := &Command{
Name: "root",
Flags: []Flag{
Expand Down Expand Up @@ -3701,7 +3700,6 @@ func TestCommand_ParentCommand_Set(t *testing.T) {
}

func TestCommandReadArgsFromStdIn(t *testing.T) {

tests := []struct {
name string
input string
Expand Down Expand Up @@ -3860,7 +3858,6 @@ func TestCommandReadArgsFromStdIn(t *testing.T) {
} else {
r.Error(err)
}

})
}
}
Expand Down
1 change: 0 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type mutuallyExclusiveGroupRequiredFlag struct {
}

func (e *mutuallyExclusiveGroupRequiredFlag) Error() string {

var missingFlags []string
for _, grpf := range e.flags.Flags {
var grpString []string
Expand Down
1 change: 0 additions & 1 deletion fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (cmd *Command) prepareFishFlags(flags []Flag, previousCommands []string) []
completion.WriteString(fmt.Sprintf(
" -s %s", strings.TrimSpace(opt),
))

}
}

Expand Down
5 changes: 1 addition & 4 deletions flag_bool_with_inverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

var (
errBothEnvFlagsAreSet = fmt.Errorf("cannot set both flags `--env` and `--no-env`")
)
var errBothEnvFlagsAreSet = fmt.Errorf("cannot set both flags `--env` and `--no-env`")

type boolWithInverseTestCase struct {
args []string
Expand Down Expand Up @@ -361,7 +359,6 @@ func TestBoolWithInverseDestination(t *testing.T) {
checkAndReset := func(expectedCount int, expectedValue bool) error {
if *count != expectedCount {
return fmt.Errorf("expected count to be %d, got %d", expectedCount, *count)

}

if *destination != expectedValue {
Expand Down
6 changes: 4 additions & 2 deletions flag_float_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"flag"
)

type FloatSlice = SliceBase[float64, NoConfig, floatValue]
type FloatSliceFlag = FlagBase[[]float64, NoConfig, FloatSlice]
type (
FloatSlice = SliceBase[float64, NoConfig, floatValue]
FloatSliceFlag = FlagBase[[]float64, NoConfig, FloatSlice]
)

var NewFloatSlice = NewSliceBase[float64, NoConfig, floatValue]

Expand Down
6 changes: 4 additions & 2 deletions flag_int_slice.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

type IntSlice = SliceBase[int64, IntegerConfig, intValue]
type IntSliceFlag = FlagBase[[]int64, IntegerConfig, IntSlice]
type (
IntSlice = SliceBase[int64, IntegerConfig, intValue]
IntSliceFlag = FlagBase[[]int64, IntegerConfig, IntSlice]
)

var NewIntSlice = NewSliceBase[int64, IntegerConfig, intValue]

Expand Down
6 changes: 4 additions & 2 deletions flag_string_map.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

type StringMap = MapBase[string, StringConfig, stringValue]
type StringMapFlag = FlagBase[map[string]string, StringConfig, StringMap]
type (
StringMap = MapBase[string, StringConfig, stringValue]
StringMapFlag = FlagBase[map[string]string, StringConfig, StringMap]
)

var NewStringMap = NewMapBase[string, StringConfig, stringValue]

Expand Down
6 changes: 4 additions & 2 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

type StringSlice = SliceBase[string, StringConfig, stringValue]
type StringSliceFlag = FlagBase[[]string, StringConfig, StringSlice]
type (
StringSlice = SliceBase[string, StringConfig, stringValue]
StringSliceFlag = FlagBase[[]string, StringConfig, StringSlice]
)

var NewStringSlice = NewSliceBase[string, StringConfig, stringValue]

Expand Down
6 changes: 4 additions & 2 deletions flag_uint_slice.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

type UintSlice = SliceBase[uint64, IntegerConfig, uintValue]
type UintSliceFlag = FlagBase[[]uint64, IntegerConfig, UintSlice]
type (
UintSlice = SliceBase[uint64, IntegerConfig, uintValue]
UintSliceFlag = FlagBase[[]uint64, IntegerConfig, UintSlice]
)

var NewUintSlice = NewSliceBase[uint64, IntegerConfig, uintValue]

Expand Down
2 changes: 0 additions & 2 deletions flag_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func TestFlagDefaultValidation(t *testing.T) {

cmd := &Command{
Name: "foo",
Flags: []Flag{
Expand All @@ -33,7 +32,6 @@ func TestFlagDefaultValidation(t *testing.T) {
}

func TestFlagValidation(t *testing.T) {

r := require.New(t)

testCases := []struct {
Expand Down
3 changes: 2 additions & 1 deletion help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ func TestMutuallyExclusiveFlags(t *testing.T) {
Name: "s1",
},
},
}},
},
},
},
}

Expand Down
7 changes: 3 additions & 4 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func testCleanup(packages []string) error {
}
}

return os.WriteFile("coverage.txt", out.Bytes(), 0644)
return os.WriteFile("coverage.txt", out.Bytes(), 0o644)
}

func GfmrunActionFunc(ctx context.Context, cmd *cli.Command) error {
Expand Down Expand Up @@ -499,7 +499,7 @@ func GenerateActionFunc(ctx context.Context, cmd *cli.Command) error {
return os.WriteFile(
filepath.Join(top, "godoc-current.txt"),
[]byte(cliDocs),
0644,
0o644,
)
}

Expand Down Expand Up @@ -557,7 +557,7 @@ func EnsureGfmrunActionFunc(ctx context.Context, cmd *cli.Command) error {
return err
}

return downloadFile(gfmrunURL.String(), gfmrunExe, 0755, 0755)
return downloadFile(gfmrunURL.String(), gfmrunExe, 0o755, 0o755)
}

func EnsureMkdocsActionFunc(ctx context.Context, cmd *cli.Command) error {
Expand Down Expand Up @@ -642,7 +642,6 @@ func V3Diff(ctx context.Context, cmd *cli.Command) error {
"--label=b/godoc",
"godoc-current.txt",
)

if err != nil {
fmt.Printf("# %v ---> Hey! <---\n", badNewsEmoji)
fmt.Println(strings.TrimSpace(v3diffWarning))
Expand Down
15 changes: 10 additions & 5 deletions template.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package cli

var helpNameTemplate = `{{$v := offset .FullName 6}}{{wrap .FullName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
var argsTemplate = `{{if .Arguments}}{{range .Arguments}}{{.Usage}}{{end}}{{end}}`
var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{template "argsTemplate" .}}{{end}}{{end}}`
var descriptionTemplate = `{{wrap .Description 3}}`
var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
var (
helpNameTemplate = `{{$v := offset .FullName 6}}{{wrap .FullName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
argsTemplate = `{{if .Arguments}}{{range .Arguments}}{{.Usage}}{{end}}{{end}}`
usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{template "argsTemplate" .}}{{end}}{{end}}`
descriptionTemplate = `{{wrap .Description 3}}`
authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}
{{end}}{{$author}}{{end}}`
)

var visibleCommandTemplate = `{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}`

var visibleCommandCategoryTemplate = `{{range .VisibleCategories}}{{if .Name}}

{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{template "visibleCommandTemplate" .}}{{end}}{{end}}`

var visibleFlagCategoryTemplate = `{{range .VisibleFlagCategories}}
{{if .Name}}{{.Name}}

Expand Down
5 changes: 2 additions & 3 deletions value_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestEnvVarValueSource(t *testing.T) {
r.True(ok)
r.Equal(str, "bar")
})

})

t.Run("implements fmt.Stringer", func(t *testing.T) {
Expand Down Expand Up @@ -80,7 +79,7 @@ func TestFileValueSource(t *testing.T) {
fileName := filepath.Join(os.TempDir(), fmt.Sprintf("urfave-cli-testing-existing_file-%[1]v", rand.Int()))
t.Cleanup(func() { _ = os.Remove(fileName) })

r.Nil(os.WriteFile(fileName, []byte("pita"), 0644))
r.Nil(os.WriteFile(fileName, []byte("pita"), 0o644))

t.Run("found", func(t *testing.T) {
src := &fileValueSource{Path: fileName}
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestFilePaths(t *testing.T) {
fileName := filepath.Join(os.TempDir(), fmt.Sprintf("urfave-cli-tests-some_file_name_%[1]v", rand.Int()))
t.Cleanup(func() { _ = os.Remove(fileName) })

r.Nil(os.WriteFile(fileName, []byte("Hello"), 0644))
r.Nil(os.WriteFile(fileName, []byte("Hello"), 0o644))

sources := Files("junk_file_name", fileName)
str, src, ok := sources.LookupWithSource()
Expand Down
Loading