aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2015-10-24 11:49:26 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-10-26 13:08:48 -0400
commit01b19455c08cc37d1c3ef174524278e84c92fec1 (patch)
tree6e518e485f1c6cd145e05d394c9bf3f69aab2fa6 /tools/perf
parentb272a59d835cd8ca6b45f41c66c61b473996c759 (diff)
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/parse-options.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index b8d98229a8af..eeeed98eb26d 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -7,6 +7,8 @@
7#define OPT_SHORT 1 7#define OPT_SHORT 1
8#define OPT_UNSET 2 8#define OPT_UNSET 2
9 9
10static struct strbuf error_buf = STRBUF_INIT;
11
10static int opterror(const struct option *opt, const char *reason, int flags) 12static int opterror(const struct option *opt, const char *reason, int flags)
11{ 13{
12 if (flags & OPT_SHORT) 14 if (flags & OPT_SHORT)
@@ -540,9 +542,11 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
540 exit(130); 542 exit(130);
541 default: /* PARSE_OPT_UNKNOWN */ 543 default: /* PARSE_OPT_UNKNOWN */
542 if (ctx.argv[0][1] == '-') { 544 if (ctx.argv[0][1] == '-') {
543 error("unknown option `%s'", ctx.argv[0] + 2); 545 strbuf_addf(&error_buf, "unknown option `%s'",
546 ctx.argv[0] + 2);
544 } else { 547 } else {
545 error("unknown switch `%c'", *ctx.opt); 548 strbuf_addf(&error_buf, "unknown switch `%c'",
549 *ctx.opt);
546 } 550 }
547 usage_with_options(usagestr, options); 551 usage_with_options(usagestr, options);
548 } 552 }
@@ -711,6 +715,13 @@ int usage_with_options_internal(const char * const *usagestr,
711 if (!usagestr) 715 if (!usagestr)
712 return PARSE_OPT_HELP; 716 return PARSE_OPT_HELP;
713 717
718 setup_pager();
719
720 if (strbuf_avail(&error_buf)) {
721 fprintf(stderr, " Error: %s\n", error_buf.buf);
722 strbuf_release(&error_buf);
723 }
724
714 fprintf(stderr, "\n Usage: %s\n", *usagestr++); 725 fprintf(stderr, "\n Usage: %s\n", *usagestr++);
715 while (*usagestr && **usagestr) 726 while (*usagestr && **usagestr)
716 fprintf(stderr, " or: %s\n", *usagestr++); 727 fprintf(stderr, " or: %s\n", *usagestr++);