svn commit: r350461 - head/sbin/nvmecontrol

Alexander Motin mav at FreeBSD.org
Wed Jul 31 03:48:48 UTC 2019


Author: mav
Date: Wed Jul 31 03:48:48 2019
New Revision: 350461
URL: https://svnweb.freebsd.org/changeset/base/350461

Log:
  Fix usage printing for nested subcommands.
  
  Instead of `nvmecontrol create` should be `nvmecontrol ns create`, etc.
  
  MFC after:	2 weeks

Modified:
  head/sbin/nvmecontrol/comnd.c

Modified: head/sbin/nvmecontrol/comnd.c
==============================================================================
--- head/sbin/nvmecontrol/comnd.c	Wed Jul 31 00:16:12 2019	(r350460)
+++ head/sbin/nvmecontrol/comnd.c	Wed Jul 31 03:48:48 2019	(r350461)
@@ -50,10 +50,22 @@ __FBSDID("$FreeBSD$");
 static struct cmd top;
 
 static void
+print_tree(const struct cmd *f)
+{
+
+	if (f->parent != NULL)
+		print_tree(f->parent);
+	if (f->name != NULL)
+		fprintf(stderr, " %s", f->name);
+}
+
+static void
 print_usage(const struct cmd *f)
 {
 
-	fprintf(stderr, "    %s %-15s - %s\n", getprogname(), f->name, f->descr);
+	fprintf(stderr, "    %s", getprogname());
+	print_tree(f->parent);
+	fprintf(stderr, " %-15s - %s\n", f->name, f->descr);
 }
 
 static void
@@ -120,7 +132,8 @@ arg_help(int argc __unused, char * const *argv, const 
 	// XXX walk up the cmd list...
 	if (argv[optind])
 		fprintf(stderr, "Unknown argument: %s\n", argv[optind]);
-	fprintf(stderr, "Usage:\n    %s %s", getprogname(), argv[0]);
+	fprintf(stderr, "Usage:\n    %s", getprogname());
+	print_tree(f);
 	if (opts)
 		fprintf(stderr, " <args>");
 	if (args) {


More information about the svn-src-head mailing list