diff --git a/cmd/nixgen/main.go b/cmd/nixgen/main.go deleted file mode 100644 index 907f1720ee6f38301053c0abdba89e73063705ab..0000000000000000000000000000000000000000 --- a/cmd/nixgen/main.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "flag" - "fmt" - "os" - "strings" - - "github.com/pelletier/go-toml/v2" - "go.jolheiser.com/nixfig" - "gopkg.in/yaml.v3" -) - -func maine() error { - fs := flag.NewFlagSet("nixgen", flag.ExitOnError) - - format := func(v any) ([]byte, error) { - return json.MarshalIndent(v, "", "\t") - } - formatFunc := func(s string) error { - switch strings.ToLower(s) { - case "json": - // Default - case "yaml": - format = yaml.Marshal - case "toml": - format = toml.Marshal - default: - return fmt.Errorf("unknown format %q, should be one of [json yaml toml]", s) - } - return nil - } - fs.Func("format", "Output format", formatFunc) - fs.Func("f", "--format", formatFunc) - if err := fs.Parse(os.Args[1:]); err != nil { - return err - } - - if len(fs.Args()) < 1 { - return errors.New("nixgen requires a file") - } - - fp := fs.Arg(0) - data, err := os.ReadFile(fp) - if err != nil { - return err - } - - var nix map[string]any - if err := nixfig.Unmarshal(data, &nix); err != nil { - return err - } - - out, err := format(nix) - if err != nil { - return err - } - fmt.Println(string(out)) - - return nil -} - -func main() { - if err := maine(); err != nil { - fmt.Println(err) - os.Exit(1) - } -} diff --git a/go.mod b/go.mod index 556b398e1d418bd11616e77532e066b51b4c0018..320eb929bd3d8f921051c72e3d2a394f84ffe14b 100644 --- a/go.mod +++ b/go.mod @@ -2,11 +2,7 @@ module go.jolheiser.com/nixfig go 1.21.4 -require ( - github.com/alecthomas/assert/v2 v2.4.0 - github.com/pelletier/go-toml/v2 v2.2.1 - gopkg.in/yaml.v3 v3.0.1 -) +require github.com/alecthomas/assert/v2 v2.4.0 require ( github.com/alecthomas/repr v0.3.0 // indirect diff --git a/go.sum b/go.sum index 0c882c31c9dcfde941c3ed0ab83cee22123fb59e..bb218edf75f7e5851f885dad9c29af54e00b24a4 100644 --- a/go.sum +++ b/go.sum @@ -2,26 +2,5 @@ github.com/alecthomas/assert/v2 v2.4.0 h1:/ZiZ0NnriAWPYYO+4eOjgzNELrFQLaHNr92mHSHFj9U= github.com/alecthomas/assert/v2 v2.4.0/go.mod h1:fw5suVxB+wfYJ3291t0hRTqtGzFYdSwstnRQdaQx2DM= github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= -github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/nixfig_test.go b/nixfig_test.go index 1d70aee17e7838ca41ce74183489c9ae304f7983..517070e2cc31cc7dedb3a30385e90c859f8d830d 100644 --- a/nixfig_test.go +++ b/nixfig_test.go @@ -8,8 +8,7 @@ "github.com/alecthomas/assert/v2" ) type Config struct { - User string - Log struct { + Log struct { Level string File string } @@ -21,7 +20,6 @@ } } var testCfg = Config{ - User: "jolheiser", Log: struct { Level string File string diff --git a/testdata/config.nix b/testdata/config.nix index 535f62e6b10bc8eb8e75e475da1501bedc8ef653..2d38d2b0ab1e6123cc206ee20ffb72b739676809 100644 --- a/testdata/config.nix +++ b/testdata/config.nix @@ -1,7 +1,6 @@ let user = "jolheiser"; in { - inherit user; log = { level = "warn"; # Name the log file after the user....for reasons