From: "Rüdiger Meier" <sweet_f_a@gmx.de>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 00/13] usage cleanup part 1
Date: Mon, 26 Jun 2017 16:44:59 +0200 [thread overview]
Message-ID: <f521dab1-98b2-e7da-2a5d-41f6779b0245@gmx.de> (raw)
In-Reply-To: <20170626140746.zv5vfomubhy7437u@ws.net.home>
On 06/26/2017 04:07 PM, Karel Zak wrote:
> On Mon, Jun 26, 2017 at 03:04:30PM +0200, Rüdiger Meier wrote:
>> On 06/22/2017 04:37 AM, Ruediger Meier wrote:
>>> From: Ruediger Meier <ruediger.meier@ga-group.nl>
>>>
>>> This is pull request #467 on github
>>> https://github.com/karelzak/util-linux/pull/467
>>
>>> The major goal is to avoid printing usage/help messages on stderr.
>>>
>>> This is the preparing first part of a bigger patch-set. There are
>>> some minor bug fixes and finally we add --help options to all our
>>> commands (just 5 commands were missing it).
>>>
>>> The next completing patch-set (part 2) will be more invasive but
>>> even more trivial.
>>
>> Thanks for merging.
>>
>> FYI I've PR'ed the second part on github only because it's almost
>> trivial but invasive.
>> https://github.com/karelzak/util-linux/pull/471
>
> Merged, thanks!
>
> It seems we have many places with "not enough arguments" or "device no
> specified" or "bad usage". What about to create some inline function
> for these things?
>
> static inline err_usage(int eval, char *msg)
> {
> warnx(msg);
> errtryhelp(eval);
> }
>
> #define errnoargs(x) err_usage(x, _("not enough arguments"))
> #define errnodevice(x) err_usage(x, _("no device specified"))
> #define errbadusage(x) err_usage(x, _("bad usage"))
>
> Maybe it seems like over-engineering, but it's pretty common in the
> code and some consolidation to avoid creativity would be nice. The current
> solution requires
>
> if (argv < 2) {
> warnx(_("not enough arguments")));
> errtryhelp(EXIT_FAILURE);
> }
>
> I think
>
> if (argv < 2)
> errnoargs(EXIT_FAILURE);
>
> is shorter, seems better and provides control on the messages
> (errtryhelp() call, etc).
>
> Comments?
I was already playing around with something like this
#define werrtryhelp(eval, s...) __extension__ ({ \
warnx(s); \
errtryhelp(eval); \
})
This would make things 1simple in about 100 cases, for example
- if (argc > 0) {
- warnx(_("%d too many arguments given"), argc);
- errtryhelp(EXIT_FAILURE);
- }
+ if (argc > 0)
+ werrtryhelp(EXIT_FAILURE, _("%d too many arguments given"), argc);
For the standard errors we would only need defines like:
#define ERR_MSG_NOARGS _("not enough arguments"))
if (argv < 2)
errtryhelp(EXIT_FAILURE, ERR_MSG_NOARGS);
Funny, I've had already deleted my werrtryhelp branch because I got
already tired of this cleanup. I just got it back from git-reflog
and safe it for later ;)
cu,
Rudi
next prev parent reply other threads:[~2017-06-26 14:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
2017-06-22 2:37 ` [PATCH 01/13] uuidd: remove unused define Ruediger Meier
2017-06-22 2:37 ` [PATCH 02/13] misc: remove superfluous null pointer checks for optarg Ruediger Meier
2017-06-22 2:37 ` [PATCH 03/13] misc: fix some broken exit codes Ruediger Meier
2017-06-22 20:49 ` Ruediger Meier
2017-06-22 2:37 ` [PATCH 04/13] blkid: use errtryhelp instead of errtryh Ruediger Meier
2017-06-22 2:37 ` [PATCH 05/13] dmesg: do not accept any non-option arguments Ruediger Meier
2017-06-22 2:37 ` [PATCH 06/13] setarch: print usage error if no argument given Ruediger Meier
2017-06-22 8:38 ` Karel Zak
2017-06-22 8:44 ` Ruediger Meier
2017-06-22 2:37 ` [PATCH 07/13] setarch: use errtryhelp() Ruediger Meier
2017-06-22 2:37 ` [PATCH 08/13] fsck: add --help and --version Ruediger Meier
2017-06-22 2:37 ` [PATCH 09/13] login: " Ruediger Meier
2017-06-22 8:42 ` Karel Zak
2017-06-22 2:37 ` [PATCH 10/13] whereis: " Ruediger Meier
2017-06-22 2:37 ` [PATCH 11/13] more: " Ruediger Meier
2017-06-22 2:37 ` [PATCH 12/13] mkfs.cramfs: " Ruediger Meier
2017-06-22 2:37 ` [PATCH 13/13] misc: no more errtryh() Ruediger Meier
2017-06-26 13:04 ` [PATCH 00/13] usage cleanup part 1 Rüdiger Meier
2017-06-26 14:07 ` Karel Zak
2017-06-26 14:44 ` Rüdiger Meier [this message]
2017-06-26 20:37 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f521dab1-98b2-e7da-2a5d-41f6779b0245@gmx.de \
--to=sweet_f_a@gmx.de \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).