Browse Source

feat: switch to toml as a config file

pull/79/head
Thomas Dickson 1 year ago
parent
commit
c3b0ffa524
  1. 5
      defaults.go
  2. 5
      go.mod
  3. 2
      go.sum
  4. 15
      main.go

5
defaults.go

@ -4,9 +4,10 @@
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/pelletier/go-toml/v2"
)
var cmdDefaults = &Command{
@ -26,7 +27,7 @@ func runDefaults(args []string) error {
}
func writeConfig(c *userConfig) error {
b, err := json.MarshalIndent(c, "", "\t")
b, err := toml.Marshal(c)
if err != nil {
return fmt.Errorf("cannot encode config: %v", err)
}

5
go.mod

@ -1,6 +1,8 @@
module mvdan.cc/fdroidcl
go 1.19
go 1.21.0
toolchain go1.23.0
require (
github.com/kr/pretty v0.3.1
@ -12,6 +14,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect

2
go.sum

@ -13,6 +13,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

15
main.go

@ -4,12 +4,13 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/pelletier/go-toml/v2"
)
const cmdName = "fdroidcl"
@ -43,17 +44,17 @@ func mustData() string {
}
func configPath() string {
return filepath.Join(mustData(), "config.json")
return filepath.Join(mustData(), "config.toml")
}
type repo struct {
ID string `json:"id"`
URL string `json:"url"`
Enabled bool `json:"enabled"`
ID string `toml:"id"`
URL string `toml:"url"`
Enabled bool `toml:"enabled"`
}
type userConfig struct {
Repos []repo `json:"repos"`
Repos []repo `toml:"repos"`
}
var config = userConfig{
@ -79,7 +80,7 @@ func readConfig() error {
}
defer f.Close()
fileConfig := userConfig{}
err = json.NewDecoder(f).Decode(&fileConfig)
err = toml.NewDecoder(f).Decode(&fileConfig)
if err != nil {
return err
}

Loading…
Cancel
Save