Compare commits

..

No commits in common. "main" and "v0.0.6" have entirely different histories.
main ... v0.0.6

2 changed files with 16 additions and 15 deletions

5
imp.go
View File

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

26
main.go
View File

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