Compare commits

...

2 Commits
v0.0.6 ... main

Author SHA1 Message Date
jolheiser 587759243a
fix: empty module
ci/woodpecker/push/goreleaser Pipeline was successful Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-07-16 22:56:33 -05:00
jolheiser 49a668d1a9
fix: cwd
ci/woodpecker/push/goreleaser Pipeline was successful Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-07-16 21:43:05 -05:00
2 changed files with 15 additions and 16 deletions

5
imp.go
View File

@ -16,10 +16,7 @@ import (
) )
func runImp(root, ignore string, write, gofumpt, gofumptExtra bool) error { func runImp(root, ignore string, write, gofumpt, gofumptExtra bool) error {
mod, err := modInfo() mod := modInfo(root)
if err != nil {
return err
}
globs, err := globber.ParseFile(ignore) globs, err := globber.ParseFile(ignore)
if err != nil { if err != nil {
if !errors.Is(err, fs.ErrNotExist) { if !errors.Is(err, fs.ErrNotExist) {

26
main.go
View File

@ -29,14 +29,16 @@ func mainErr() error {
stdinFlag := fs.Bool("stdin", false, "Format stdin") stdinFlag := fs.Bool("stdin", false, "Format stdin")
if err := fs.Parse(os.Args[1:]); err != nil { if err := fs.Parse(os.Args[1:]); err != nil {
fmt.Println(err) return err
}
cwd, err := os.Getwd()
if err != nil {
return err
} }
if *stdinFlag { if *stdinFlag {
mod, err := modInfo() mod := modInfo(cwd)
if err != nil {
return err
}
src, err := io.ReadAll(os.Stdin) src, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {
return err return err
@ -46,9 +48,10 @@ func mainErr() error {
return err return err
} }
fmt.Print(string(formatted)) fmt.Print(string(formatted))
return nil
} }
root := "." root := cwd
if fs.NArg() > 0 { if fs.NArg() > 0 {
root = fs.Arg(0) root = fs.Arg(0)
} }
@ -79,16 +82,15 @@ func (m *module) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func modInfo() (module, error) { func modInfo(dir string) module {
cmd := exec.Command("go", "mod", "edit", "--json") cmd := exec.Command("go", "mod", "edit", "--json")
cmd.Dir = dir
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
return module{}, err return module{}
} }
var m module var m module
if err := json.Unmarshal(out, &m); err != nil { _ = json.Unmarshal(out, &m)
return m, err return m
}
return m, nil
} }