mirror of
https://github.com/tweag/gomod2nix.git
synced 2024-11-05 01:59:08 +00:00
42 lines
882 B
Go
42 lines
882 B
Go
package main // import "github.com/tweag/gomod2nix"
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
generate "github.com/tweag/gomod2nix/generate"
|
|
schema "github.com/tweag/gomod2nix/schema"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
|
|
var directory = flag.String("dir", "./", "Go project directory")
|
|
var outDirFlag = flag.String("outdir", "", "output directory (if different from project directory)")
|
|
flag.Parse()
|
|
|
|
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)
|
|
}
|
|
|
|
output, err := schema.Marshal(pkgs)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = ioutil.WriteFile(outFile, output, 0644)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
log.Info(fmt.Sprintf("Wrote: %s", outFile))
|
|
|
|
}
|