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")
|
2022-05-30 16:08:36 +00:00
|
|
|
var maxJobs = flag.Int("jobs", 10, "Number of max parallel jobs")
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-26 11:06:01 +00:00
|
|
|
goMod2NixPath := filepath.Join(outDir, "gomod2nix.toml")
|
|
|
|
outFile := goMod2NixPath
|
2022-05-30 16:08:36 +00:00
|
|
|
pkgs, err := generate.GeneratePkgs(*directory, goMod2NixPath, *maxJobs)
|
2020-07-20 11:55:32 +00:00
|
|
|
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)
|
2022-05-26 11:06:01 +00:00
|
|
|
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 11:55:32 +00:00
|
|
|
|
2020-07-20 10:52:58 +00:00
|
|
|
}
|