Details
-
User Story
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
TLDR
I've created a wrapper around QCommandLineParser which implements issue's title.
Introduction
It's a common practice to load application's configuration by 2 ways:
- command line arguments
- configuration file
Each of these have benefits, so developers usually have to bother with supporting both. The thing is that it can be easily done with just one class: QCommandLineParser.
Idea
Just like QCommandLineParser supports -help option out-of-box, it could also support -config <filename> and -export <filename> options. With these 2 options QCommandLineParser could load/export options from/to a file in the background.
The class interface would stay the same for the user to add options and read values. But the user could also specify if the arguments can be loaded with an option -config (or exported with -export).
File format
Qt has great support of JSON, so I think this is a good option here.
All app's arguments can be divided into 3 groups:
- positional
- flags
- named
This is easily intergarted into JSON:
{ "positional": [ "positional_arg_1", "positional_arg_2" ], "flags": [ "flag-1", "flag-2", ], "named": { "named-arg-1": "value1", "named-arg-2": "value2", } }
Class API
class QCommandLineParser { public: QCommandLineOption addConfigOption(); QCommandLineOption addExportOption(); };