Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Setup pager when printing usage and help

It's annoying to see error or help message when command has many options
like in perf record, report or top. So setup pager when print parser
error or help message - it should be OK since no UI is enabled at the
parsing time. The usage_with_options() already disables it by calling
exit_browser() anyway.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1445701767-12731-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
01b19455 b272a59d

+13 -2
+13 -2
tools/perf/util/parse-options.c
··· 7 7 #define OPT_SHORT 1 8 8 #define OPT_UNSET 2 9 9 10 + static struct strbuf error_buf = STRBUF_INIT; 11 + 10 12 static int opterror(const struct option *opt, const char *reason, int flags) 11 13 { 12 14 if (flags & OPT_SHORT) ··· 542 540 exit(130); 543 541 default: /* PARSE_OPT_UNKNOWN */ 544 542 if (ctx.argv[0][1] == '-') { 545 - error("unknown option `%s'", ctx.argv[0] + 2); 543 + strbuf_addf(&error_buf, "unknown option `%s'", 544 + ctx.argv[0] + 2); 546 545 } else { 547 - error("unknown switch `%c'", *ctx.opt); 546 + strbuf_addf(&error_buf, "unknown switch `%c'", 547 + *ctx.opt); 548 548 } 549 549 usage_with_options(usagestr, options); 550 550 } ··· 714 710 715 711 if (!usagestr) 716 712 return PARSE_OPT_HELP; 713 + 714 + setup_pager(); 715 + 716 + if (strbuf_avail(&error_buf)) { 717 + fprintf(stderr, " Error: %s\n", error_buf.buf); 718 + strbuf_release(&error_buf); 719 + } 717 720 718 721 fprintf(stderr, "\n Usage: %s\n", *usagestr++); 719 722 while (*usagestr && **usagestr)