Store your Minecraft configs with your other dotfiles, and load it automatically.

feat: cli, instance home and actual writing

Changed files
+131 -24
cli
config
core
minecraft
+1
.gitignore
···
+
instance
+27
cli/cli.go
···
+
package cli
+
+
import (
+
"context"
+
"os"
+
+
"github.com/charmbracelet/log"
+
"github.com/urfave/cli/v3"
+
)
+
+
var rootCommand = cli.Command{
+
Name: "dmc", // TODO? short name?
+
Authors: []any{
+
"banana", "rad",
+
},
+
Copyright: "(c) 2025 potassium.sh",
+
Description: "Store your Minecraft configs with your other dotfiles, and load them automatically.",
+
Commands: []*cli.Command{
+
syncCommand,
+
},
+
}
+
+
func Run() {
+
if err := rootCommand.Run(context.Background(), os.Args); err != nil {
+
log.Fatal(err)
+
}
+
}
+23
cli/sync.go
···
+
package cli
+
+
import (
+
"context"
+
+
"github.com/urfave/cli/v3"
+
"potassium.sh/dot-mining/core"
+
"potassium.sh/dot-mining/minecraft"
+
)
+
+
var syncCommand = &cli.Command{
+
Name: "sync",
+
Description: "Synchronise your mods and configs.",
+
Action: func(ctx context.Context, cmd *cli.Command) error {
+
return sync()
+
},
+
}
+
+
func sync() error {
+
core.InitConfig()
+
minecraft.WriteOptions(core.Config.Options, core.MinecraftFile("options.txt"))
+
return nil
+
}
+2
config.toml
···
+
directory = "instance"
+
[options]
main_hand = "left"
ao = false
+7 -6
config/config.go
···
type (
Config struct {
-
Options minecraft.Options `toml:options`
-
Fabric Loader `toml:fabric`
-
Mods map[string]string `toml:mods`
+
Options minecraft.Options `toml:"options"`
+
Fabric Loader `toml:"fabric"`
+
Mods map[string]string `toml:"mods"`
+
Directory string `toml:"directory"`
}
Loader struct {
-
Mods map[string]string `toml:mods`
+
Mods map[string]string `toml:"mods"`
}
)
-
func LoadConfig() (Config) {
+
func LoadConfig() Config {
file, _ := os.ReadFile("config.toml")
-
var config Config
+
var config Config
toml.Decode(string(file), &config)
return config
}
+24
core/core.go
···
+
package core
+
+
import (
+
"os"
+
"path/filepath"
+
+
"potassium.sh/dot-mining/config"
+
)
+
+
var (
+
Config config.Config
+
)
+
+
func InitConfig() {
+
Config = config.LoadConfig()
+
}
+
+
func MinecraftFile(path ...string) string {
+
cwd, _ := os.Getwd()
+
args := []string{cwd, Config.Directory}
+
args = append(args, path...)
+
+
return filepath.Join(args...)
+
}
+1
go.mod
···
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
+
github.com/urfave/cli/v3 v3.6.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.30.0 // indirect
+23
go.sum
···
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
+
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
+
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
···
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+
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.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+
github.com/urfave/cli v1.22.17 h1:SYzXoiPfQjHBbkYxbew5prZHS1TOLT3ierW8SYLqtVQ=
+
github.com/urfave/cli v1.22.17/go.mod h1:b0ht0aqgH/6pBYzzxURyrM4xXNgsoT/n2ZzwQiEhNVo=
+
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
+
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
···
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+3 -9
main.go
···
package main
-
import (
-
"potassium.sh/dot-mining/config"
-
"potassium.sh/dot-mining/minecraft"
-
)
-
-
+
import "potassium.sh/dot-mining/cli"
func main() {
-
config := config.LoadConfig()
-
minecraft.WriteOptions(config.Options, "")
-
}
+
cli.Run()
+
}
+20 -9
minecraft/options.go
···
package minecraft
import (
-
"fmt"
+
"os"
+
"path/filepath"
"reflect"
"strconv"
-
)
+
"github.com/charmbracelet/log"
+
)
type (
Options struct {
MainHand string `toml:"main_hand" txt:"mainHand"`
-
AO bool `toml:"smooth_lighting" txt:"ao"`
-
Fov int `toml:"fov" txt:"fov"`
+
AO bool `toml:"smooth_lighting" txt:"ao"`
+
Fov int `toml:"fov" txt:"fov"`
}
)
···
reflectOptions := reflect.TypeOf(options)
-
for i := 0; i < reflectOptions.NumField(); i++ {
+
for i := range reflectOptions.NumField() {
field := reflectOptions.Field(i)
txt := field.Tag.Get("txt")
-
if (txt == "") {
+
if txt == "" {
txt = field.Name
}
value := reflect.ValueOf(options).Field(i)
-
-
switch field.Type.Kind(){
+
+
switch field.Type.Kind() {
case reflect.String:
plainText += txt + ":" + "\"" + value.String() + "\"\n"
case reflect.Int:
···
plainText += txt + ":" + strconv.FormatBool(value.Bool()) + "\n"
}
}
-
fmt.Print(plainText)
+
+
dir := filepath.Dir(path)
+
if err := os.MkdirAll(dir, 0755); err != nil {
+
log.Fatal("Failed creating instance directory ", dir, ": ", err)
+
return
+
}
+
+
if err := os.WriteFile(path, []byte(plainText), 0755); err != nil {
+
log.Fatal("Failed writing options", "error", err)
+
}
}