Jelajahi Sumber

vcc: -help [command] is now usable

intirain 4 tahun lalu
induk
melakukan
6bb69c4f2f
3 mengubah file dengan 44 tambahan dan 13 penghapusan
  1. 2 2
      Makefile
  2. 40 9
      cmd.c
  3. 2 2
      include/vcc/version.h

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 23
-VCC_PATCH 		= 1
+VCC_MINOR 		= 24
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 40 - 9
cmd.c

@@ -188,23 +188,54 @@ static int __help(struct cmdtable *cmdtab) {
 }
 
 
+struct cmdtable *find_in(struct cmdtable *table, char *s) {
+	struct cmdtable *cmd;
+
+	for (cmd = table; cmd->cmd; cmd++) 
+		if (!(strcmp(cmd->cmd, s))) 
+			return cmd;
+
+	return NULL;
+}
+
 int do_cmd_help(int argc, char **argv) {
 	struct plugin *p;
+	struct cmdtable *cmd;
 	int i;
 
-	(void) argv;
+	switch (argc) {
+	case 1:
+		__help(cmdtab);
 
-	if (argc != 1) {
-		fprintf(stderr, _("usage: -help\n"));
+		for (i = 0; (p = plugins[i]); i++) 
+			__help(p->cmdtab);
 
-		return 1;
-	}
+		break;
 
-	__help(cmdtab);
+	case 2:
+		if (!(cmd = find_in(cmdtab, argv[1]))) {
+			for (i = 0; (p = plugins[i]); i++) 
+				if ((cmd = find_in(p->cmdtab, argv[1]))) 
+					break;
+
+			if (!cmd) {
+				fprintf(stderr, _("%s: command not found. \n"), argv[1]);
+				fprintf(stderr, _("Do you mean -%s? \n"), argv[1]);
+
+				return 1;
+			}
+		}
+
+		pretty_cmd_help(cmd->cmd, cmd->help);
+
+		break;
+
+	default:
+		fprintf(stderr, _("usage: -help [command]"));
+
+		break;
+	}
 
-	for (i = 0; (p = plugins[i]); i++) 
-		__help(p->cmdtab);
-	
 	return 0;
 }
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.23.1 Fri Jun  3 05:47:46 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.23.1-rc "
+#define VCC_VERSION "VCC 1.24.0 Fri Jun  3 06:07:18 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.24.0-rc "