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

Add variable input/output support to QCommandLineParser / QCommandLineOption

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Other
    • None

    Description

      Most command line parsers allow associating a variable with a command line option.

      Such variable is then automatically updated from the command line option argument value when the parser encounters such command line option.

      The default value for a command line option with an assigned variable is also implicitly provided by what value the variable held before the command line parsing process was started, including for optionally printing such default value in the command line help text.


      For example libpopt supports automatically setting the following variable types:

      Value               Description                        Arg type
      POPT_ARG_NONE       No argument expected               int
      POPT_ARG_STRING     No type checking to be performed   char *
      POPT_ARG_ARGV       No type checking to be performed   char **
      POPT_ARG_SHORT      A short argument is expected       short
      POPT_ARG_INT        An integer argument is expected    int
      POPT_ARG_LONG       A long integer is expected         long
      POPT_ARG_LONGLONG   A long long integer is expected    long long
      POPT_ARG_VAL        Integer value taken from val       int
      POPT_ARG_FLOAT      A float argument is expected       float
      POPT_ARG_DOUBLE     A double argument is expected      double
      

      POPT_ARG_NONE is for cases where the presence of such command line option itself (without any arguments) sets the provided int flag value to 1.


      Glib has very similar functionality available via GOptionEntry: G_OPTION_ARG_NONE, G_OPTION_ARG_STRING, G_OPTION_ARG_INT, G_OPTION_ARG_FILENAME, G_OPTION_ARG_STRING_ARRAY, G_OPTION_ARG_FILENAME_ARRAY, G_OPTION_ARG_DOUBLE.


      Such variable input/output functionality of command line parser significantly reduces the amount of boilerplate code necessary for command line option parsing.

      I was surprised that Qt doesn't offer anything similar to these C libraries here.

      Attachments

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

        Activity

          People

            cnn Qt Core & Network
            mhej Maciej Szmigiero
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes