From: tip-bot for Namhyung Kim <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: namhyung@kernel.org, jolsa@redhat.com,
linux-kernel@vger.kernel.org, acme@redhat.com,
tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org,
dsahern@gmail.com, a.p.zijlstra@chello.nl
Subject: [tip:perf/core] perf tools: Setup pager when printing usage and help
Date: Thu, 29 Oct 2015 02:40:09 -0700 [thread overview]
Message-ID: <tip-01b19455c08cc37d1c3ef174524278e84c92fec1@git.kernel.org> (raw)
In-Reply-To: <1445701767-12731-3-git-send-email-namhyung@kernel.org>
Commit-ID: 01b19455c08cc37d1c3ef174524278e84c92fec1
Gitweb: http://git.kernel.org/tip/01b19455c08cc37d1c3ef174524278e84c92fec1
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Sun, 25 Oct 2015 00:49:26 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 26 Oct 2015 14:08:48 -0300
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>
---
tools/perf/util/parse-options.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index b8d9822..eeeed98 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -7,6 +7,8 @@
#define OPT_SHORT 1
#define OPT_UNSET 2
+static struct strbuf error_buf = STRBUF_INIT;
+
static int opterror(const struct option *opt, const char *reason, int flags)
{
if (flags & OPT_SHORT)
@@ -540,9 +542,11 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
exit(130);
default: /* PARSE_OPT_UNKNOWN */
if (ctx.argv[0][1] == '-') {
- error("unknown option `%s'", ctx.argv[0] + 2);
+ strbuf_addf(&error_buf, "unknown option `%s'",
+ ctx.argv[0] + 2);
} else {
- error("unknown switch `%c'", *ctx.opt);
+ strbuf_addf(&error_buf, "unknown switch `%c'",
+ *ctx.opt);
}
usage_with_options(usagestr, options);
}
@@ -711,6 +715,13 @@ int usage_with_options_internal(const char * const *usagestr,
if (!usagestr)
return PARSE_OPT_HELP;
+ setup_pager();
+
+ if (strbuf_avail(&error_buf)) {
+ fprintf(stderr, " Error: %s\n", error_buf.buf);
+ strbuf_release(&error_buf);
+ }
+
fprintf(stderr, "\n Usage: %s\n", *usagestr++);
while (*usagestr && **usagestr)
fprintf(stderr, " or: %s\n", *usagestr++);
next prev parent reply other threads:[~2015-10-29 9:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-24 15:49 [PATCH 1/4] perf tools: Improve ambiguous option help message Namhyung Kim
2015-10-24 15:49 ` [PATCH 2/4] perf report: Rename to --show-cpu-utilization Namhyung Kim
2015-10-25 8:59 ` Ingo Molnar
2015-10-29 9:39 ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-10-24 15:49 ` [PATCH 3/4] perf tools: Setup pager when printing usage and help Namhyung Kim
2015-10-25 9:04 ` Ingo Molnar
2015-10-29 9:40 ` tip-bot for Namhyung Kim [this message]
2015-10-24 15:49 ` [PATCH 4/4] perf tools: Introduce usage_with_options_msg() Namhyung Kim
2015-10-26 17:13 ` Arnaldo Carvalho de Melo
2015-10-26 23:13 ` 平松雅巳 / HIRAMATU,MASAMI
2015-10-27 12:29 ` Arnaldo Carvalho de Melo
2015-10-29 9:40 ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-10-25 8:48 ` [PATCH 1/4] perf tools: Improve ambiguous option help message Ingo Molnar
2015-10-29 9:39 ` [tip:perf/core] " tip-bot for Namhyung Kim
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=tip-01b19455c08cc37d1c3ef174524278e84c92fec1@git.kernel.org \
--to=tipbot@zytor.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=hpa@zytor.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
/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
Powered by JetHome