File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ linters:
3838 - fmt.Fprintf
3939 - fmt.Fprintln
4040
41+ gomoddirectives :
42+ replace-local : true
43+
4144 goheader :
4245 template : |-
4346 Copyright Josh Komoroske. All rights reserved.
Original file line number Diff line number Diff line change 77package cmd
88
99import (
10+ "bytes"
1011 "fmt"
1112 "os"
1213 "path/filepath"
1314 "strings"
1415
1516 "github.com/joshdk/buildversion"
1617 "github.com/spf13/cobra"
18+
19+ "github.com/joshdk/modfmt/pkg/modfmt"
1720)
1821
1922// Command returns a complete command line handler for modfmt.
@@ -47,7 +50,22 @@ func Command() *cobra.Command {
4750 }
4851
4952 for _ , filename := range filenames {
50- fmt .Println (filename )
53+ // Read the original file.
54+ original , err := os .ReadFile (filename )
55+ if err != nil {
56+ return err
57+ }
58+
59+ // Format the file.
60+ formatted , err := modfmt .Format (filename , original )
61+ if err != nil {
62+ return err
63+ }
64+
65+ // Did formatting change the file or was it already formatted?
66+ if ! bytes .Equal (original , formatted ) {
67+ fmt .Println (filename )
68+ }
5169 }
5270
5371 return nil
Original file line number Diff line number Diff line change @@ -4,10 +4,16 @@ go 1.23.0
44
55require (
66 github.com/joshdk/buildversion v0.1.0
7+ github.com/joshdk/modfmt/pkg/modfmt v0.0.0-00010101000000-000000000000
78 github.com/spf13/cobra v1.10.1
89)
910
1011require (
1112 github.com/inconshreveable/mousetrap v1.1.0 // indirect
1213 github.com/spf13/pflag v1.0.9 // indirect
14+ golang.org/x/mod v0.27.0 // indirect
15+ )
16+
17+ replace (
18+ github.com/joshdk/modfmt/pkg/modfmt => ./pkg/modfmt
1319)
Original file line number Diff line number Diff line change @@ -8,5 +8,7 @@ github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
88github.com/spf13/cobra v1.10.1 /go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0 =
99github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY =
1010github.com/spf13/pflag v1.0.9 /go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg =
11+ golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ =
12+ golang.org/x/mod v0.27.0 /go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc =
1113gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
1214gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments