Message ID | 1438687723-31091-1-git-send-email-vapier@gentoo.org |
---|---|
State | New |
Headers | show |
On 08/04/2015 07:28 AM, Mike Frysinger wrote: > I keep trying to run tests with --help and then remembering that does > nothing when it throws an error. That means I have to dig into the > source when I want to refer to flags or env vars and re-read a good > amount of code to find the nested locations. > > Make this all much more user friendly with a usage screen that gets > printed out whenever an unknown option is specified. > > 2015-08-04 Mike Frysinger <vapier@gentoo.org> > > * test-skeleton.c (usage): New function. > (main): Call usage when opt is '?'. LGTM for 2.23. > --- > test-skeleton.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/test-skeleton.c b/test-skeleton.c > index 9ee5001..1b2688c 100644 > --- a/test-skeleton.c > +++ b/test-skeleton.c > @@ -250,6 +250,41 @@ set_fortify_handler (void (*handler) (int sig)) > ignore_stderr (); > } > > +/* Show people how to run the program. */ > +static void > +usage (void) > +{ > + size_t i; > + > + printf ("Usage: %s [options]\n" > + "\n" > + "Environment Variables:\n" > + " TIMEOUTFACTOR An integer used to scale the timeout\n" > + " TMPDIR Where to place temporary files\n" > + "\n", > + program_invocation_short_name); > + printf ("Options:\n"); > + for (i = 0; options[i].name; ++i) > + { > + int indent; > + > + indent = printf (" --%s", options[i].name); > + if (options[i].has_arg == required_argument) > + indent += printf (" <arg>"); > + printf ("%*s", 25 - indent, ""); > + switch (options[i].val) > + { > + case OPT_DIRECT: > + printf ("Run the test directly (instead of forking & monitoring)"); > + break; > + case OPT_TESTDIR: > + printf ("Override the TMPDIR env var"); > + break; > + } > + printf ("\n"); > + } > +} > + > /* We provide the entry point here. */ > int > main (int argc, char *argv[]) > @@ -271,6 +306,7 @@ main (int argc, char *argv[]) > switch (opt) > { > case '?': > + usage (); > exit (1); > case OPT_DIRECT: > direct = 1; >
On 04 Aug 2015 10:32, Carlos O'Donell wrote: > On 08/04/2015 07:28 AM, Mike Frysinger wrote: > > I keep trying to run tests with --help and then remembering that does > > nothing when it throws an error. That means I have to dig into the > > source when I want to refer to flags or env vars and re-read a good > > amount of code to find the nested locations. > > > > Make this all much more user friendly with a usage screen that gets > > printed out whenever an unknown option is specified. > > > > 2015-08-04 Mike Frysinger <vapier@gentoo.org> > > > > * test-skeleton.c (usage): New function. > > (main): Call usage when opt is '?'. > > LGTM for 2.23. pushed, thanks -mike
diff --git a/test-skeleton.c b/test-skeleton.c index 9ee5001..1b2688c 100644 --- a/test-skeleton.c +++ b/test-skeleton.c @@ -250,6 +250,41 @@ set_fortify_handler (void (*handler) (int sig)) ignore_stderr (); } +/* Show people how to run the program. */ +static void +usage (void) +{ + size_t i; + + printf ("Usage: %s [options]\n" + "\n" + "Environment Variables:\n" + " TIMEOUTFACTOR An integer used to scale the timeout\n" + " TMPDIR Where to place temporary files\n" + "\n", + program_invocation_short_name); + printf ("Options:\n"); + for (i = 0; options[i].name; ++i) + { + int indent; + + indent = printf (" --%s", options[i].name); + if (options[i].has_arg == required_argument) + indent += printf (" <arg>"); + printf ("%*s", 25 - indent, ""); + switch (options[i].val) + { + case OPT_DIRECT: + printf ("Run the test directly (instead of forking & monitoring)"); + break; + case OPT_TESTDIR: + printf ("Override the TMPDIR env var"); + break; + } + printf ("\n"); + } +} + /* We provide the entry point here. */ int main (int argc, char *argv[]) @@ -271,6 +306,7 @@ main (int argc, char *argv[]) switch (opt) { case '?': + usage (); exit (1); case OPT_DIRECT: direct = 1;