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 {
mod, err := modInfo()
if err != nil {
return err
}
mod := modInfo(root)
globs, err := globber.ParseFile(ignore)
if err != nil {
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")
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 {
mod, err := modInfo()
if err != nil {
return err
}
mod := modInfo(cwd)
src, err := io.ReadAll(os.Stdin)
if err != nil {
return err
@ -46,9 +48,10 @@ func mainErr() error {
return err
}
fmt.Print(string(formatted))
return nil
}
root := "."
root := cwd
if fs.NArg() > 0 {
root = fs.Arg(0)
}
@ -79,16 +82,15 @@ func (m *module) UnmarshalJSON(data []byte) error {
return nil
}
func modInfo() (module, error) {
func modInfo(dir string) module {
cmd := exec.Command("go", "mod", "edit", "--json")
cmd.Dir = dir
out, err := cmd.Output()
if err != nil {
return module{}, err
return module{}
}
var m module
if err := json.Unmarshal(out, &m); err != nil {
return m, err
}
return m, nil
_ = json.Unmarshal(out, &m)
return m
}