Message ID | 8441512.T7Z3S40VBb@devpool47.emlix.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | improve qconfig C++ code | expand |
On Wed, Oct 23, 2024 at 3:33 PM Rolf Eike Beer <eb@emlix.com> wrote: > > This has a much nicer output without manual processing. It also adds window > management options from Qt for free. > > Signed-off-by: Rolf Eike Beer <eb@emlix.com> > --- The help message looks as follows: $ ./scripts/kconfig/qconf --help QSocketNotifier: Can only be used with threads started with QThread Usage: ./scripts/kconfig/qconf [options] Kconfig Options: -s silent -h, --help Displays help on commandline options. --help-all Displays help including Qt specific options. Arguments: file config file to open I want to see something better for the explanation of '-s' and I want 'file' and 'Kconfig' to match. > int main(int ac, char** av) > { > ConfigMainWindow* v; > - const char *name; > + configApp = new QApplication(ac, av); > + QCommandLineParser cmdline; Please rename 'cmdline' to 'parser' because this is used in the code example. https://doc.qt.io/qt-6/qcommandlineparser.html#details > + QCommandLineOption silent("s", "silent"); How about this ? silent("s", "Print this message and exit."); The description is consistent with "./scripts/kconfig/conf --help". > + cmdline.addOption(silent); > + cmdline.addHelpOption(); > + cmdline.addPositionalArgument("file", "config file to open", "Kconfig"); I think the third parameter is unneeded. Then, the help message will look better. -- Best Regards Masahiro Yamada
On Thu, Oct 24, 2024 at 1:39 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Wed, Oct 23, 2024 at 3:33 PM Rolf Eike Beer <eb@emlix.com> wrote: > > > > This has a much nicer output without manual processing. It also adds window > > management options from Qt for free. > > > > Signed-off-by: Rolf Eike Beer <eb@emlix.com> > > --- > > The help message looks as follows: > > > $ ./scripts/kconfig/qconf --help > QSocketNotifier: Can only be used with threads started with QThread > Usage: ./scripts/kconfig/qconf [options] Kconfig > > Options: > -s silent > -h, --help Displays help on commandline options. > --help-all Displays help including Qt specific options. > > Arguments: > file config file to open "config file" is a bit confusing. (it sounds like ".config"). The positional argument specifies the top-level Kconfig. I added this to the help of scripts/kconfig/conf: https://lore.kernel.org/linux-kbuild/20241024112548.1438155-1-masahiroy@kernel.org/T/#u Best Regards Masahiro Yamada
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index 6a653ebe9df3..313a51941825 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -8,6 +8,7 @@ #include <QActionGroup> #include <QApplication> #include <QCloseEvent> +#include <QCommandLineParser> #include <QDebug> #include <QFileDialog> #include <QLabel> @@ -1844,41 +1845,30 @@ void fixup_rootmenu(struct menu *menu) } } -static const char *progname; - -static void usage(void) -{ - printf("%s [-s] <config>\n", progname); - exit(0); -} - int main(int ac, char** av) { ConfigMainWindow* v; - const char *name; + configApp = new QApplication(ac, av); + QCommandLineParser cmdline; + QCommandLineOption silent("s", "silent"); - progname = av[0]; - if (ac > 1 && av[1][0] == '-') { - switch (av[1][1]) { - case 's': - conf_set_message_callback(NULL); - break; - case 'h': - case '?': - usage(); - } - name = av[2]; - } else - name = av[1]; - if (!name) - usage(); + cmdline.addOption(silent); + cmdline.addHelpOption(); + cmdline.addPositionalArgument("file", "config file to open", "Kconfig"); + + cmdline.process(*configApp); + + if (cmdline.isSet(silent)) + conf_set_message_callback(NULL); - conf_parse(name); + QStringList args = cmdline.positionalArguments(); + if (args.isEmpty()) + cmdline.showHelp(1); + + conf_parse(args.first().toLocal8Bit().constData()); fixup_rootmenu(&rootmenu); //zconfdump(stdout); - configApp = new QApplication(ac, av); - configSettings = new ConfigSettings(); configSettings->beginGroup("/kconfig/qconf"); v = new ConfigMainWindow();
This has a much nicer output without manual processing. It also adds window management options from Qt for free. Signed-off-by: Rolf Eike Beer <eb@emlix.com> --- scripts/kconfig/qconf.cc | 44 ++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 27 deletions(-)