Skip to contentSkip to conversation

tools: normalize usage messages

PATCH In review Caio Marcelo de Oliveira Filho 2 participants 3 messages Feb 9, 2015 – Feb 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tools: normalize usage messages

From: Caio Marcelo de Oliveira Filho <[email protected]>

Normalize to use program_invocation_short_name. Also make the usage command correct for 'kmod list'.

---
 tools/kmod.c  | 11 ++++++++---
 tools/kmod.h  |  2 ++
 tools/lsmod.c |  3 ++-
 3 files changed, 12 insertions(+), 4 deletions(-)
tools/kmod.c +8 -3
index 8ae1d86..521c2b9 100644
@@ -63,7 +63,7 @@ static int kmod_help(int argc, char *argv[])
 			"Options:\n"
 			"\t-V, --version     show version\n"
 			"\t-h, --help        show this help\n\n"
-			"Commands:\n", basename(argv[0]));
+			"Commands:\n", program_invocation_short_name);
 
 	for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) {
 		if (kmod_cmds[i]->help != NULL) {
@@ -150,7 +150,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[])
 	const char *cmd;
 	size_t i;
 
-	cmd = basename(argv[0]);
+	cmd = program_invocation_short_name;
 
 	for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) {
 		if (streq(kmod_compat_cmds[i]->name, cmd))
@@ -160,11 +160,16 @@ static int handle_kmod_compat_commands(int argc, char *argv[])
 	return -ENOENT;
 }
 
+bool is_kmod_cmd(void)
+{
+	return streq(program_invocation_short_name, "kmod");
+}
+
 int main(int argc, char *argv[])
 {
 	int err;
 
-	if (streq(program_invocation_short_name, "kmod"))
+	if (is_kmod_cmd())
 		err = handle_kmod_commands(argc, argv);
 	else
 		err = handle_kmod_compat_commands(argc, argv);
tools/kmod.h +2 -0
index 50adda4..71bc0c1 100644
@@ -27,6 +27,8 @@ struct kmod_cmd {
 	const char *help;
 };
 
+bool is_kmod_cmd(void);
+
 extern const struct kmod_cmd kmod_cmd_compat_lsmod;
 extern const struct kmod_cmd kmod_cmd_compat_rmmod;
 extern const struct kmod_cmd kmod_cmd_compat_insmod;
tools/lsmod.c +2 -1
index e953c7e..5eb6f25 100644
@@ -36,7 +36,8 @@ static int do_lsmod(int argc, char *argv[])
 	int err;
 
 	if (argc != 1) {
-		fprintf(stderr, "Usage: %s\n", argv[0]);
+		fprintf(stderr, "Usage: %s%s\n", program_invocation_short_name,
+			is_kmod_cmd() ? " list" : "");
 		return EXIT_FAILURE;
 	}
 
Signature · 1 line
2.2.2
#1 lore raw

PATCH 2/2 tools: add kmod info

From: Caio Marcelo de Oliveira Filho <[email protected]>

---
 man/kmod.xml    |  6 ++++++
 tools/kmod.c    |  1 +
 tools/kmod.h    |  1 +
 tools/modinfo.c | 11 +++++++++--
 4 files changed, 17 insertions(+), 2 deletions(-)
man/kmod.xml +6 -0
index 0706ad5..caa07a4 100644
@@ -72,6 +72,12 @@
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term><command>info</command></term>
+        <listitem>
+          <para>Show information about a module.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><command>list</command></term>
         <listitem>
           <para>List the currently loaded modules.</para>
tools/kmod.c +1 -0
index 521c2b9..1b5c346 100644
@@ -40,6 +40,7 @@ static const struct kmod_cmd kmod_cmd_help;
 
 static const struct kmod_cmd *kmod_cmds[] = {
 	&kmod_cmd_help,
+	&kmod_cmd_info,
 	&kmod_cmd_list,
 	&kmod_cmd_static_nodes,
 };
tools/kmod.h +1 -0
index 71bc0c1..f57a92e 100644
@@ -36,6 +36,7 @@ extern const struct kmod_cmd kmod_cmd_compat_modinfo;
 extern const struct kmod_cmd kmod_cmd_compat_modprobe;
 extern const struct kmod_cmd kmod_cmd_compat_depmod;
 
+extern const struct kmod_cmd kmod_cmd_info;
 extern const struct kmod_cmd kmod_cmd_list;
 extern const struct kmod_cmd kmod_cmd_static_nodes;
 
tools/modinfo.c +9 -2
index 94d55c9..9a32143 100644
@@ -330,7 +330,7 @@ static const struct option cmdopts[] = {
 static void help(void)
 {
 	printf("Usage:\n"
-		"\t%s [options] filename [args]\n"
+		"\t%s%s [options] filename [args]\n"
 		"Options:\n"
 		"\t-a, --author                Print only 'author'\n"
 		"\t-d, --description           Print only 'description'\n"
@@ -343,7 +343,8 @@ static void help(void)
 		"\t-b, --basedir=DIR           Use DIR as filesystem root for /lib/modules\n"
 		"\t-V, --version               Show version\n"
 		"\t-h, --help                  Show this help\n",
-		program_invocation_short_name);
+		program_invocation_short_name,
+		is_kmod_cmd() ? " info" : "");
 }
 
 static bool is_module_filename(const char *name)
@@ -464,3 +465,9 @@ const struct kmod_cmd kmod_cmd_compat_modinfo = {
 	.cmd = do_modinfo,
 	.help = "compat modinfo command",
 };
+
+const struct kmod_cmd kmod_cmd_info = {
+	.name = "info",
+	.cmd = do_modinfo,
+	.help = "show information about a module",
+};
Signature · 1 line
2.2.2
#2 lore raw

Re: [PATCH 2/2] tools: add kmod info

Quoted 8 lines · Caio Marcelo de Oliveira Filho

From: Caio Marcelo de Oliveira Filho <[email protected]>

        printf("Usage:\n"
tools/modinfo.c +1 -1
-               "\t%s [options] filename [args]\n"
+               "\t%s%s [options] filename [args]\n"
                "Options:\n"
                "\t-a, --author                Print only 'author'\n"
                "\t-d, --description           Print only 'description'\n"

tools/modinfo.c static void help(void) · line 347

Quoted 6 lines
tools/modinfo.c +2 -1
@@ -343,7 +343,8 @@ static void help(void)
                "\t-b, --basedir=DIR           Use DIR as filesystem root for /lib/modules\n"
                "\t-V, --version               Show version\n"
                "\t-h, --help                  Show this help\n",
-               program_invocation_short_name);
+               program_invocation_short_name,
+               is_kmod_cmd() ? " info" : "");

humn... what I really wanted with the commands was to normalize the common options. For example, --version would only be used as an option to kmod, not "kmod info".
"-b, --basedir"... this should be an option to kmod as well. depmod and modprobe also make use of it, though with a different name (-d in modprobe, -b in depmod)

tools/modinfo.c const struct kmod_cmd kmod_cmd_compat_modinfo = { · line 473

Quoted 13 lines
tools/modinfo.c +6 -0
 }
 
 static bool is_module_filename(const char *name)
@@ -464,3 +465,9 @@ const struct kmod_cmd kmod_cmd_compat_modinfo = {
        .cmd = do_modinfo,
        .help = "compat modinfo command",
 };
+
+const struct kmod_cmd kmod_cmd_info = {
+       .name = "info",
+       .cmd = do_modinfo,
+       .help = "show information about a module",
+};

anyway... I think we can merge something like this and start factoring out the common options later.

Signature · 1 line
Lucas De Marchi