diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e450c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +mcd +*.swp diff --git a/cmd/root.go b/cmd/root.go index 7854c4b..68367aa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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")) } diff --git a/mcd.toml b/mcd.toml new file mode 100644 index 0000000..b029364 --- /dev/null +++ b/mcd.toml @@ -0,0 +1,5 @@ +[java] +path = "/usr/bin/java" +args = ["-Xms2G", "-Xmx3G"] +[server] +jar = "./server.jar"