Config file or parameters, plus parameter standards

Forum rules
Before you post please read how to get help
0x2620
Level 2
Level 2
Posts: 67
Joined: Mon Jan 09, 2017 3:17 pm

Config file or parameters, plus parameter standards

Postby 0x2620 » Fri Jul 21, 2017 2:27 am

I'm writing a Java program to print pointer tables, and the parameters keep piling up. What's the cut-off point for too many parameters - when do you move them all to a config file?

Also is there a *nix standard (or best practices) anywhere for formatting parameters for CLI apps?

User avatar
xenopeek
Level 24
Level 24
Posts: 21473
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Config file or parameters, plus parameter standards

Postby xenopeek » Fri Jul 21, 2017 3:05 am

0x2620 wrote:What's the cut-off point for too many parameters - when do you move them all to a config file?

There's not really a cut-off point. There are plenty of CLI programs that have more parameters then you can dream up. Like curl for example (the manpage online https://curl.haxx.se/docs/manpage.html).

Probably better to approach this the other way round: which parameters would a user set once and use unchanged each time they run the program, and which parameters are users likely to need/want to set to something specific each time they run the program? Consider the use of your parameters. If you do go with a config file a nice parameter to add is to use a different from default config file. So users can easily have two or more config files for particular uses.

0x2620 wrote:Also is there a *nix standard (or best practices) anywhere for formatting parameters for CLI apps?

Not really. For single letter (short) parameters use single dash. For longer than single letter (long) parameters use double dashes. Single letter parameters without (optional) arguments one would expect to be able to combine. Like if you have a -l (list) and -v (verbose) parameter, -lv should do both. Long parameters for these would for example be --list and --verbose. Good idea to have -h / --help both to show a summary of command line arguments.
Image



Return to “Scripts & Bash”