Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple config file parsing? #42

Closed
paul-chambers opened this issue Nov 24, 2019 · 2 comments
Closed

simple config file parsing? #42

paul-chambers opened this issue Nov 24, 2019 · 2 comments
Assignees

Comments

@paul-chambers
Copy link

I often find myself often wanting the same set of options defined in a config file as I do on the command line. In other words, use a config file as a stored set of options, which get parsed and override the default settings of the executable, and then can be 'fine-tuned'/overridden by options if provided on the command line.

I guess I could parse the config file into a fake argc/argv array, and feed that to argtable3, but that feels like I'm throwing away information, and potentially messing up the error reporting.

Reasonable enhancement request, or outside the scope of argtablle3?

@tomghuang tomghuang self-assigned this Nov 24, 2019
@tomghuang
Copy link
Contributor

@paul-chambers There are several issues to combine both config file parsing and command line parsing in a single library. First, it will make the library too large for people who only want to use the config file parsing API or the command line parsing API of the library. Second, there are already too many config file formats, and creating a new one seems doesn't help the community too much. Third, if we want to build in any existing config file parser, people who use other formats won't be comfortable.

I think config file parsing and command line parsing are better separated, because you'll have freedom to choose any config file parsing library you like. Besides, it should not be too hard to achieve what you want.

For example, you can load the config file and put all the keys and values in an internal dictionary. At the same time, you can override any key by specifying the new value in command-line option:

$ myprog --config myconfig.json --set key=new_value

The new value will override the old value in the internal dictionary. That's how I implement my applications. I've combined the power of argtable3 and many config file parsers, and I'm glad that I can choose whatever config parser I need for a specific project.

@tomghuang
Copy link
Contributor

@paul-chambers I never expect that some day I will have an interview with some one asking questions in Argtable3. Now I know how small the world is, and I am glad that I always try my best to answer questions in GitHub. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants