added example config and cli args
This commit is contained in:
parent
693fda9891
commit
f559a6f990
3 changed files with 17 additions and 9 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
mcd
|
||||||
|
*.swp
|
19
cmd/root.go
19
cmd/root.go
|
@ -22,6 +22,7 @@ import (
|
||||||
"git.jmbit.de/jmb/mcd/internal/config"
|
"git.jmbit.de/jmb/mcd/internal/config"
|
||||||
"git.jmbit.de/jmb/mcd/internal/service"
|
"git.jmbit.de/jmb/mcd/internal/service"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgFile string
|
var cfgFile string
|
||||||
|
@ -30,12 +31,7 @@ var cfgFile string
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "mcd",
|
Use: "mcd",
|
||||||
Short: "Systemd-Compatible wrapper for Minecraft Server",
|
Short: "Systemd-Compatible wrapper for Minecraft Server",
|
||||||
Long: `A longer description that spans multiple lines and likely contains
|
Long: `mcd wraps a minecraft server in a way that makes it work better as a systemd service`,
|
||||||
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.`,
|
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
@ -59,9 +55,14 @@ func init() {
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
// will be global for your application.
|
// 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
|
rootCmd.PersistentFlags().StringP("java", "J", "/usr/bin/java", "Path to java executable")
|
||||||
// when this action is called directly.
|
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
5
mcd.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[java]
|
||||||
|
path = "/usr/bin/java"
|
||||||
|
args = ["-Xms2G", "-Xmx3G"]
|
||||||
|
[server]
|
||||||
|
jar = "./server.jar"
|
Loading…
Add table
Reference in a new issue