gomod2nix/main.go

43 lines
882 B
Go
Raw Normal View History

2020-07-20 10:52:58 +00:00
package main // import "github.com/tweag/gomod2nix"
import (
"flag"
"fmt"
2020-07-21 09:42:32 +00:00
log "github.com/sirupsen/logrus"
2022-05-27 17:25:35 +00:00
generate "github.com/tweag/gomod2nix/generate"
schema "github.com/tweag/gomod2nix/schema"
2020-07-20 12:32:17 +00:00
"io/ioutil"
2020-07-20 10:52:58 +00:00
"path/filepath"
)
func main() {
2020-07-21 07:20:36 +00:00
var directory = flag.String("dir", "./", "Go project directory")
2020-07-21 09:42:32 +00:00
var outDirFlag = flag.String("outdir", "", "output directory (if different from project directory)")
2020-07-20 10:52:58 +00:00
flag.Parse()
2020-07-21 09:42:32 +00:00
outDir := *outDirFlag
if outDir == "" {
outDir = *directory
}
goMod2NixPath := filepath.Join(outDir, "gomod2nix.toml")
outFile := goMod2NixPath
pkgs, err := generate.GeneratePkgs(*directory, goMod2NixPath)
if err != nil {
panic(err)
2020-07-20 10:52:58 +00:00
}
2022-05-27 17:25:35 +00:00
output, err := schema.Marshal(pkgs)
if err != nil {
panic(err)
2020-07-21 07:20:36 +00:00
}
2020-07-21 09:42:32 +00:00
err = ioutil.WriteFile(outFile, output, 0644)
2020-07-20 12:32:17 +00:00
if err != nil {
panic(err)
}
2020-07-21 09:42:32 +00:00
log.Info(fmt.Sprintf("Wrote: %s", outFile))
2020-07-20 10:52:58 +00:00
}