I hope this is not a flame or offtopic question. In the console application (no matter what is written, for specificity, let it be Java, but this is not critical), it is possible to pass parameters in the following ways:

  • command line parameter values ​​(-f value1)
  • values ​​in the configuration file (xml, ini, yml, properties files, etc.)
  • environment variable values ​​($ F_PARAM_VALUE = value1)

The question is: in what order should the application handle these values? Are there any recommendations, best practices, etc.?

For example, if the value is specified both in the configuration file, and in the parameters of environment variables, and in the parameters of the application itself, which value should be used?

Logically, the command line parameters should be the strongest?

  • 2
    I would do (in descending order of importance) command line, environment, config. Although of course, more importantly the config or the environment is another question. I think there may be different situations. - Mike
  • Another interesting case is when there is a command line parameter “path to the config file”, and the value of this parameter is the path to a nonexistent / invalid file, and there are valid values ​​of environment variables. - lospejos
  • one
    путь к файлу конфига", и значение этого параметра - путь к несуществующему / неправильному файлу just swear and exit the application. - KoVadim

1 answer 1

Well, of course in the command line more priority values.
Their meaning is that you can run the application in a special mode, different from the settings from the config.
If these settings do not overlap, there is no point in determining priority at all.
The rest is a matter of technology. You can use the parameters in order to call a short function at all without initializing the other settings.