fix: print errors to stderr and exit code 1
ci/woodpecker/push/goreleaser Pipeline was successful
Details
ci/woodpecker/push/goreleaser Pipeline was successful
Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>main v0.0.6
parent
f9f2f02f90
commit
5c91d2e95a
2
imp.go
2
imp.go
|
@ -49,7 +49,7 @@ func runImp(root, ignore string, write, gofumpt, gofumptExtra bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
formatted, err := impFormat(data, mod, gofumpt, gofumptExtra)
|
formatted, err := impFormat(data, mod, gofumpt, gofumptExtra)
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, format.ErrNoImports) {
|
||||||
return fmt.Errorf("could not format file %q: %w", walkPath, err)
|
return fmt.Errorf("could not format file %q: %w", walkPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
main.go
19
main.go
|
@ -12,6 +12,13 @@ import (
|
||||||
var Version = "develop"
|
var Version = "develop"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if err := mainErr(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainErr() error {
|
||||||
fs := flag.NewFlagSet("imp", flag.ExitOnError)
|
fs := flag.NewFlagSet("imp", flag.ExitOnError)
|
||||||
writeFlag := fs.Bool("write", false, "Write the re-ordered imports instead of just printing them")
|
writeFlag := fs.Bool("write", false, "Write the re-ordered imports instead of just printing them")
|
||||||
fs.BoolVar(writeFlag, "w", *writeFlag, "--write")
|
fs.BoolVar(writeFlag, "w", *writeFlag, "--write")
|
||||||
|
@ -28,17 +35,15 @@ func main() {
|
||||||
if *stdinFlag {
|
if *stdinFlag {
|
||||||
mod, err := modInfo()
|
mod, err := modInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
src, err := io.ReadAll(os.Stdin)
|
src, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
formatted, err := impFormat(src, mod, *gofumptFlag, *gofumptExtraFlag)
|
formatted, err := impFormat(src, mod, *gofumptFlag, *gofumptExtraFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return err
|
||||||
}
|
}
|
||||||
fmt.Print(string(formatted))
|
fmt.Print(string(formatted))
|
||||||
}
|
}
|
||||||
|
@ -48,9 +53,7 @@ func main() {
|
||||||
root = fs.Arg(0)
|
root = fs.Arg(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runImp(root, *ignoreFlag, *writeFlag, *gofumptFlag, *gofumptExtraFlag); err != nil {
|
return runImp(root, *ignoreFlag, *writeFlag, *gofumptFlag, *gofumptExtraFlag)
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type module struct {
|
type module struct {
|
||||||
|
|
Reference in New Issue