Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87707

QCommandLineParser load/export JSON

    XMLWordPrintable

    Details

    • Type: User Story
    • Status: Open
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core: Other
    • Labels:
      None

      Description

      TLDR

      I've created a wrapper around QCommandLineParser which implements issue's title.

      CommandLineParser.zip

      Introduction

      It's a common practice to load application's configuration by 2 ways:

      1. command line arguments
      2. 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:

      1. positional
      2. flags
      3. 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();
      };

       

        

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            sirotin Igor Sirotin
            Reporter:
            sirotin Igor Sirotin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes