@@ -122,6 +122,7 @@ func main() {
122122 // Define configuration defaults.
123123 viper .SetDefault ("count" , 1 )
124124 viper .SetDefault ("delay" , 3 )
125+ viper .SetDefault ("disable-config" , false )
125126 viper .SetDefault ("display" , "raw" )
126127 viper .SetDefault ("elasticsearch-addr" , "" )
127128 viper .SetDefault ("elasticsearch-index" , "" )
@@ -149,6 +150,10 @@ func main() {
149150 viper .SetDefault ("version" , false )
150151
151152 // Define arguments.
153+ flag .Bool (
154+ "disable-config" ,
155+ viper .GetBool ("disable-config" ),
156+ "Disable config loading, even if \" config\" is provided." )
152157 flag .Bool ("help" , false , "Show usage." )
153158 flag .Bool ("history" , viper .GetBool ("history" ), "Whether or not to use or preserve history." )
154159 flag .Bool ("show-help" , viper .GetBool ("show-help" ), "Whether or not to show help displays." )
@@ -196,17 +201,21 @@ func main() {
196201
197202 // Define configuration sources.
198203 viper .BindPFlags (flag .CommandLine )
199- viper .SetConfigFile (viper .GetString ("config" ))
200- err = viper .ReadInConfig ()
201- if err != nil {
202- // Exclude errors that indicate a missing configuration file.
203- if _ , ok := err .(viper.ConfigFileNotFoundError ); ! ok {
204- // FIXME There is currently a bug preventing Viper from ever returning
205- // `ConfigFileNotFoundError`. For now, skip over any configuration file errors.
206- //
207- // See: https://github.com/spf13/viper/issues/1783
208- // panic(err)
209- slog .Warn (err .Error ())
204+
205+ // Load a configuration file.
206+ if ! viper .GetBool ("disable-config" ) {
207+ viper .SetConfigFile (viper .GetString ("config" ))
208+ err = viper .ReadInConfig ()
209+ if err != nil {
210+ // Exclude errors that indicate a missing configuration file.
211+ if _ , ok := err .(viper.ConfigFileNotFoundError ); ! ok {
212+ // FIXME There is currently a bug preventing Viper from ever returning
213+ // `ConfigFileNotFoundError`. For now, skip over any configuration file errors.
214+ //
215+ // See: https://github.com/spf13/viper/issues/1783
216+ // panic(err)
217+ slog .Warn (err .Error ())
218+ }
210219 }
211220 }
212221
0 commit comments