added example config and cli args

This commit is contained in:
Johannes Bülow 2025-09-14 19:30:14 +02:00
parent 693fda9891
commit f559a6f990
Signed by: jmb
GPG key ID: B56971CF7B8F83A6
3 changed files with 17 additions and 9 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
mcd
*.swp

View file

@ -22,6 +22,7 @@ import (
"git.jmbit.de/jmb/mcd/internal/config"
"git.jmbit.de/jmb/mcd/internal/service"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cfgFile string
@ -30,12 +31,7 @@ var cfgFile string
var rootCmd = &cobra.Command{
Use: "mcd",
Short: "Systemd-Compatible wrapper for Minecraft Server",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Long: `mcd wraps a minecraft server in a way that makes it work better as a systemd service`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
@ -59,9 +55,14 @@ func init() {
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.mcd.yaml)")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./mcd.toml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.PersistentFlags().StringP("java", "J", "/usr/bin/java", "Path to java executable")
rootCmd.PersistentFlags().StringSliceP("java-args", "A", []string{"-Xms2G", "-Xmx3G"}, "Java args, default is -Xms2G,Xmx3G")
rootCmd.PersistentFlags().StringP("jar", "j", "./server.jar", "Path to minecraft server jar")
viper.BindPFlag("java.path", rootCmd.Flags().Lookup("java"))
viper.BindPFlag("java.args", rootCmd.Flags().Lookup("java-args"))
viper.BindPFlag("server.jar", rootCmd.Flags().Lookup("jar"))
}

5
mcd.toml Normal file
View file

@ -0,0 +1,5 @@
[java]
path = "/usr/bin/java"
args = ["-Xms2G", "-Xmx3G"]
[server]
jar = "./server.jar"