From patchwork Mon Apr 17 03:26:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9683493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9B5C46037D for ; Mon, 17 Apr 2017 03:27:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B1CA20499 for ; Mon, 17 Apr 2017 03:27:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8013B26490; Mon, 17 Apr 2017 03:27:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C915D205FB for ; Mon, 17 Apr 2017 03:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932614AbdDQD0z (ORCPT ); Sun, 16 Apr 2017 23:26:55 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:24203 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932464AbdDQD0v (ORCPT ); Sun, 16 Apr 2017 23:26:51 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="17809854" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Apr 2017 11:26:47 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 8107B47E989E; Mon, 17 Apr 2017 11:26:47 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 17 Apr 2017 11:26:51 +0800 From: Qu Wenruo To: , Subject: [PATCH 4/9] btrfs-progs: help: Unbind short help description from btrfs Date: Mon, 17 Apr 2017 11:26:37 +0800 Message-ID: <20170417032642.30770-5-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170417032642.30770-1-quwenruo@cn.fujitsu.com> References: <20170417032642.30770-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 8107B47E989E.AEAFA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP usage_command_group_short() always binds its description to 'btrfs', making us unable to this function in other progs. This patch makes the short description independent, so callers need to pass the short description by themselves. Signed-off-by: Qu Wenruo --- btrfs.c | 12 +++++++++++- help.c | 14 +++++++------- help.h | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/btrfs.c b/btrfs.c index f096e780..b3686c4b 100644 --- a/btrfs.c +++ b/btrfs.c @@ -24,6 +24,15 @@ #include "utils.h" #include "help.h" +static const char * const btrfs_short_desc[] = { + "For an overview of a given command use 'btrfs command --help'", + "or 'btrfs [command...] --help --full' to print all available options.", + "Any command name can be shortened as far as it stays unambiguous,", + "however it is recommended to use full command names in scripts.", + "All command groups have their manual page named 'btrfs-'.", + NULL +}; + static const char * const btrfs_cmd_group_usage[] = { "btrfs [--help] [--version] [...] []", NULL @@ -126,7 +135,8 @@ int main(int argc, char **argv) if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { - usage_command_group_short(&btrfs_cmd_group); + usage_command_group_short(&btrfs_cmd_group, + btrfs_short_desc); exit(1); } } diff --git a/help.c b/help.c index 19b0d357..13c45ffd 100644 --- a/help.c +++ b/help.c @@ -262,7 +262,8 @@ static void usage_command_group_internal(const struct cmd_group *grp, int full, } } -void usage_command_group_short(const struct cmd_group *grp) +void usage_command_group_short(const struct cmd_group *grp, + const char * const *short_desc) { const char * const *usagestr = grp->usagestr; FILE *outf = stdout; @@ -298,12 +299,11 @@ void usage_command_group_short(const struct cmd_group *grp) fprintf(outf, " %-16s %s\n", cmd->token, cmd->usagestr[1]); } - fputc('\n', outf); - fprintf(stderr, "For an overview of a given command use 'btrfs command --help'\n"); - fprintf(stderr, "or 'btrfs [command...] --help --full' to print all available options.\n"); - fprintf(stderr, "Any command name can be shortened as far as it stays unambiguous,\n"); - fprintf(stderr, "however it is recommended to use full command names in scripts.\n"); - fprintf(stderr, "All command groups have their manual page named 'btrfs-'.\n"); + if (short_desc) { + fputc('\n', outf); + while (*short_desc && **short_desc) + fprintf(outf, "%s\n", *short_desc++); + } } void usage_command_group(const struct cmd_group *grp, int full, int err) diff --git a/help.h b/help.h index 7458e745..9b190fb1 100644 --- a/help.h +++ b/help.h @@ -58,7 +58,8 @@ struct cmd_group; void usage(const char * const *usagestr) __attribute__((noreturn)); void usage_command(const struct cmd_struct *cmd, int full, int err); void usage_command_group(const struct cmd_group *grp, int all, int err); -void usage_command_group_short(const struct cmd_group *grp); +void usage_command_group_short(const struct cmd_group *grp, + const char * const *short_desc); void help_unknown_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn)); void help_ambiguous_token(const char *arg, const struct cmd_group *grp) __attribute__((noreturn));