Fossil SCM

Improvements to "help": List commands if the command for which help is requested is unknown. If the command prefix is ambiguous, show all alternatives.

drh 2011-01-12 02:24 trunk
Commit 1b159db28210a14b82f001f8c1f002d1d61a9b9c
1 file changed +15 -12
+15 -12
--- src/main.c
+++ src/main.c
@@ -603,21 +603,20 @@
603603
printf("\n");
604604
}
605605
}
606606
607607
/*
608
-** COM -off- MAND: commands
609
-**
610
-** Usage: %fossil commands
611
-** List all supported commands.
608
+** List of commands starting with zPrefix, or all commands if zPrefix is NULL.
612609
*/
613
-void cmd_cmd_list(void){
610
+static void cmd_cmd_list(const char *zPrefix){
614611
int i, nCmd;
612
+ int nPrefix = zPrefix ? strlen(zPrefix) : 0;
615613
const char *aCmd[count(aCommand)];
616614
for(i=nCmd=0; i<count(aCommand); i++){
617
- if( strncmp(aCommand[i].zName,"test",4)==0 ) continue;
618
- /* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
615
+ const char *z = aCommand[i].zName;
616
+ if( memcmp(z,"test",4)==0 ) continue;
617
+ if( zPrefix && memcmp(zPrefix, z, nPrefix)!=0 ) continue;
619618
aCmd[nCmd++] = aCommand[i].zName;
620619
}
621620
multi_column_list(aCmd, nCmd);
622621
}
623622
@@ -631,11 +630,10 @@
631630
void cmd_test_cmd_list(void){
632631
int i, nCmd;
633632
const char *aCmd[count(aCommand)];
634633
for(i=nCmd=0; i<count(aCommand); i++){
635634
if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
636
- /* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
637635
aCmd[nCmd++] = aCommand[i].zName;
638636
}
639637
multi_column_list(aCmd, nCmd);
640638
}
641639
@@ -660,22 +658,27 @@
660658
** Display information on how to use COMMAND
661659
*/
662660
void help_cmd(void){
663661
int rc, idx;
664662
const char *z;
665
- if( g.argc!=3 ){
663
+ if( g.argc<3 ){
666664
printf("Usage: %s help COMMAND.\nAvailable COMMANDs:\n",
667665
fossil_nameofexe());
668
- cmd_cmd_list();
666
+ cmd_cmd_list(0);
669667
version_cmd();
670668
return;
671669
}
672670
rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
673671
if( rc==1 ){
674
- fossil_fatal("unknown command: %s", g.argv[2]);
672
+ fossil_print("unknown command: %s\nAvailable commands:\n", g.argv[2]);
673
+ cmd_cmd_list(0);
674
+ fossil_exit(1);
675675
}else if( rc==2 ){
676
- fossil_fatal("ambiguous command prefix: %s", g.argv[2]);
676
+ fossil_print("ambiguous command prefix: %s\nMatching commands:\n",
677
+ g.argv[2]);
678
+ cmd_cmd_list(g.argv[2]);
679
+ fossil_exit(1);
677680
}
678681
z = aCmdHelp[idx];
679682
if( z==0 ){
680683
fossil_fatal("no help available for the %s command",
681684
aCommand[idx].zName);
682685
--- src/main.c
+++ src/main.c
@@ -603,21 +603,20 @@
603 printf("\n");
604 }
605 }
606
607 /*
608 ** COM -off- MAND: commands
609 **
610 ** Usage: %fossil commands
611 ** List all supported commands.
612 */
613 void cmd_cmd_list(void){
614 int i, nCmd;
 
615 const char *aCmd[count(aCommand)];
616 for(i=nCmd=0; i<count(aCommand); i++){
617 if( strncmp(aCommand[i].zName,"test",4)==0 ) continue;
618 /* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
 
619 aCmd[nCmd++] = aCommand[i].zName;
620 }
621 multi_column_list(aCmd, nCmd);
622 }
623
@@ -631,11 +630,10 @@
631 void cmd_test_cmd_list(void){
632 int i, nCmd;
633 const char *aCmd[count(aCommand)];
634 for(i=nCmd=0; i<count(aCommand); i++){
635 if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
636 /* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
637 aCmd[nCmd++] = aCommand[i].zName;
638 }
639 multi_column_list(aCmd, nCmd);
640 }
641
@@ -660,22 +658,27 @@
660 ** Display information on how to use COMMAND
661 */
662 void help_cmd(void){
663 int rc, idx;
664 const char *z;
665 if( g.argc!=3 ){
666 printf("Usage: %s help COMMAND.\nAvailable COMMANDs:\n",
667 fossil_nameofexe());
668 cmd_cmd_list();
669 version_cmd();
670 return;
671 }
672 rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
673 if( rc==1 ){
674 fossil_fatal("unknown command: %s", g.argv[2]);
 
 
675 }else if( rc==2 ){
676 fossil_fatal("ambiguous command prefix: %s", g.argv[2]);
 
 
 
677 }
678 z = aCmdHelp[idx];
679 if( z==0 ){
680 fossil_fatal("no help available for the %s command",
681 aCommand[idx].zName);
682
--- src/main.c
+++ src/main.c
@@ -603,21 +603,20 @@
603 printf("\n");
604 }
605 }
606
607 /*
608 ** List of commands starting with zPrefix, or all commands if zPrefix is NULL.
 
 
 
609 */
610 static void cmd_cmd_list(const char *zPrefix){
611 int i, nCmd;
612 int nPrefix = zPrefix ? strlen(zPrefix) : 0;
613 const char *aCmd[count(aCommand)];
614 for(i=nCmd=0; i<count(aCommand); i++){
615 const char *z = aCommand[i].zName;
616 if( memcmp(z,"test",4)==0 ) continue;
617 if( zPrefix && memcmp(zPrefix, z, nPrefix)!=0 ) continue;
618 aCmd[nCmd++] = aCommand[i].zName;
619 }
620 multi_column_list(aCmd, nCmd);
621 }
622
@@ -631,11 +630,10 @@
630 void cmd_test_cmd_list(void){
631 int i, nCmd;
632 const char *aCmd[count(aCommand)];
633 for(i=nCmd=0; i<count(aCommand); i++){
634 if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
 
635 aCmd[nCmd++] = aCommand[i].zName;
636 }
637 multi_column_list(aCmd, nCmd);
638 }
639
@@ -660,22 +658,27 @@
658 ** Display information on how to use COMMAND
659 */
660 void help_cmd(void){
661 int rc, idx;
662 const char *z;
663 if( g.argc<3 ){
664 printf("Usage: %s help COMMAND.\nAvailable COMMANDs:\n",
665 fossil_nameofexe());
666 cmd_cmd_list(0);
667 version_cmd();
668 return;
669 }
670 rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
671 if( rc==1 ){
672 fossil_print("unknown command: %s\nAvailable commands:\n", g.argv[2]);
673 cmd_cmd_list(0);
674 fossil_exit(1);
675 }else if( rc==2 ){
676 fossil_print("ambiguous command prefix: %s\nMatching commands:\n",
677 g.argv[2]);
678 cmd_cmd_list(g.argv[2]);
679 fossil_exit(1);
680 }
681 z = aCmdHelp[idx];
682 if( z==0 ){
683 fossil_fatal("no help available for the %s command",
684 aCommand[idx].zName);
685

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button