Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line parameters or configuration file?

Tags:

I'm developing a tool that will perform several types of analysis, and each analysis can have different levels of thoroughness. This app will have a fair amount of options to be given before it starts. I started implementing this using a configuration file, since the number of types of analysis specified were little. As the number of options implemented grew, I created more configuration files. Then, I started mixing some command line parameters since some of the options could only be flags. Now, I've mixed a bunch of command line parameters with configuration files and feel I need refactoring.

My question is, When and why would you use command line parameters instead of configuration files and vice versa?

Is it perhaps related to the language you use, personal preference, etc.?

EDIT: I'm developing a java app that will work in Windows and Mac. I don't have a GUI for now.

like image 758
Carlos Blanco Avatar asked Feb 23 '10 23:02

Carlos Blanco


People also ask

What is the command to show the configuration file?

Displaying Configuration Files Use the show running-config command to view the running configuration file.

What is a parameter in CMD?

The Parameter (PARM) command definition statement defines a parameter of a command being created. A parameter is the means by which a value is passed to the command processing program. One PARM statement must be used for each parameter that appears in the command being defined.

How do I use a config file?

A file with the . CFG or . CONFIG file extension is a configuration file used by various programs to store settings that are specific to their respective software. Some configuration files are plain text files but others might be stored in a format specific to the program.


Video Answer


2 Answers

Command line parameters are useful for quickly overriding some parameter setting from the configuration file. As well, command line parameters are useful if there are not so many parameters. For your case, I'd suggest that you export parameter presets to command line.

like image 194
Vlad Avatar answered Oct 14 '22 00:10

Vlad


Command line arguments:

Pros:

  1. concise - no extra config files to maintain by itself
  2. great interaction with bash scripts - e.g. variable substitution, variable reference, bash math, etc.

Cons:

  1. it could get very long as the options become more complex
  2. formatting is inflexible - besides some command line utilities that help you parse the high level switches and such, anything more complex (e.g. nested structured information) requires custom syntax such as using Regex, and the structure could be quite rigid - while JSON or YAML would be hard to specify at the command line level

Configuration files:

Pros:

  1. it can be very large, as large as you need it to be
  2. formatting is more flexible - you can use JSON, YAML, INI, or any other structural format to represent the information in a more human consumable way

Cons:

  1. inflexible to interact with bash variable substitutions and references (as well as bash math) - you have to probably define your own substitution rules if you want the config file to be "generic" and reusable, while this is the biggest advantage of using command line arguments - variable math would be difficult in config files (if not impossible) - you have to define your own "operator" in the config files, or you have to rely on another bash script to carry out the variable math, and perform your custom variable substitution so the "generic" config file could become "concretely usable".
  2. for all that it takes to have a generic config file (with custom defined variable substitution rules) ready, a bash script is still needed to carry out the actual substitution, and you still have to code your command line to accept all the variable substitutions, so either you have config files with no variable substitution, which means you "hard code" and repeat the config file for different scenarios, or the substitution logic with custom variable substitution rules make your in-app config file logic much more complex.

In my use case, I value being able to do variable substitution / reference (as well as bash math) in the bash scripts more important, since I'm using the same binary to start many server nodes with different responsibilities in a server backend cluster, and I kind of use the bash scripts as sort of a container or actually a config file to start the many different nodes with differing command line arguments.

like image 30
Dejavu Avatar answered Oct 14 '22 00:10

Dejavu