@@ -16,12 +16,13 @@ package cmd
1616
1717import (
1818 "fmt"
19+ "log"
1920 "os"
2021
22+ "github.com/itzg/rcon-cli/cli"
2123 "github.com/spf13/cobra"
2224 "github.com/spf13/viper"
2325 "net"
24- "github.com/itzg/rcon-cli/cli"
2526 "strconv"
2627)
2728
@@ -38,7 +39,7 @@ rcon-cli --host mc1 --port 25575
3839rcon-cli --port 25575 stop
3940RCON_PORT=25575 rcon-cli stop
4041` ,
41- Long : `
42+ Long : `
4243rcon-cli is a CLI for attaching to an RCON enabled game server, such as Minecraft.
4344Without any additional arguments, the CLI will start an interactive session with
4445the RCON server.
@@ -47,7 +48,7 @@ If arguments are passed into the CLI, then the arguments are sent
4748as a single command (joined by spaces), the response is displayed,
4849and the CLI will exit.
4950` ,
50- Run : func (cmd * cobra.Command , args []string ) {
51+ Run : func (cmd * cobra.Command , args []string ) {
5152
5253 hostPort := net .JoinHostPort (viper .GetString ("host" ), strconv .Itoa (viper .GetInt ("port" )))
5354 password := viper .GetString ("password" )
@@ -76,21 +77,24 @@ func init() {
7677 RootCmd .PersistentFlags ().String ("host" , "localhost" , "RCON server's hostname" )
7778 RootCmd .PersistentFlags ().String ("password" , "" , "RCON server's password" )
7879 RootCmd .PersistentFlags ().Int ("port" , 27015 , "Server's RCON port" )
79- viper .BindPFlags (RootCmd .PersistentFlags ())
80+ err := viper .BindPFlags (RootCmd .PersistentFlags ())
81+ if err != nil {
82+ log .Fatal (err )
83+ }
8084}
8185
8286// initConfig reads in config file and ENV variables if set.
8387func initConfig () {
8488 if cfgFile != "" { // enable ability to specify config file via flag
8589 viper .SetConfigFile (cfgFile )
90+ } else {
91+ viper .SetConfigName (".rcon-cli" ) // name of config file (without extension)
92+ viper .AddConfigPath ("$HOME" ) // adding home directory as first search path
8693 }
8794
8895 // This will allow for env vars like RCON_PORT
8996 viper .SetEnvPrefix ("rcon" )
90-
91- viper .SetConfigName (".rcon-cli" ) // name of config file (without extension)
92- viper .AddConfigPath ("$HOME" ) // adding home directory as first search path
93- viper .AutomaticEnv () // read in environment variables that match
97+ viper .AutomaticEnv () // read in environment variables that match
9498
9599 // If a config file is found, read it in.
96100 if err := viper .ReadInConfig (); err == nil {
0 commit comments