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.
Commit
1b159db28210a14b82f001f8c1f002d1d61a9b9c
Parent
a00888f66637381…
1 file changed
+15
-12
+15
-12
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -603,21 +603,20 @@ | ||
| 603 | 603 | printf("\n"); |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /* |
| 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. | |
| 612 | 609 | */ |
| 613 | -void cmd_cmd_list(void){ | |
| 610 | +static void cmd_cmd_list(const char *zPrefix){ | |
| 614 | 611 | int i, nCmd; |
| 612 | + int nPrefix = zPrefix ? strlen(zPrefix) : 0; | |
| 615 | 613 | const char *aCmd[count(aCommand)]; |
| 616 | 614 | 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; | |
| 619 | 618 | aCmd[nCmd++] = aCommand[i].zName; |
| 620 | 619 | } |
| 621 | 620 | multi_column_list(aCmd, nCmd); |
| 622 | 621 | } |
| 623 | 622 | |
| @@ -631,11 +630,10 @@ | ||
| 631 | 630 | void cmd_test_cmd_list(void){ |
| 632 | 631 | int i, nCmd; |
| 633 | 632 | const char *aCmd[count(aCommand)]; |
| 634 | 633 | for(i=nCmd=0; i<count(aCommand); i++){ |
| 635 | 634 | if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue; |
| 636 | - /* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */ | |
| 637 | 635 | aCmd[nCmd++] = aCommand[i].zName; |
| 638 | 636 | } |
| 639 | 637 | multi_column_list(aCmd, nCmd); |
| 640 | 638 | } |
| 641 | 639 | |
| @@ -660,22 +658,27 @@ | ||
| 660 | 658 | ** Display information on how to use COMMAND |
| 661 | 659 | */ |
| 662 | 660 | void help_cmd(void){ |
| 663 | 661 | int rc, idx; |
| 664 | 662 | const char *z; |
| 665 | - if( g.argc!=3 ){ | |
| 663 | + if( g.argc<3 ){ | |
| 666 | 664 | printf("Usage: %s help COMMAND.\nAvailable COMMANDs:\n", |
| 667 | 665 | fossil_nameofexe()); |
| 668 | - cmd_cmd_list(); | |
| 666 | + cmd_cmd_list(0); | |
| 669 | 667 | version_cmd(); |
| 670 | 668 | return; |
| 671 | 669 | } |
| 672 | 670 | rc = name_search(g.argv[2], aCommand, count(aCommand), &idx); |
| 673 | 671 | 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); | |
| 675 | 675 | }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); | |
| 677 | 680 | } |
| 678 | 681 | z = aCmdHelp[idx]; |
| 679 | 682 | if( z==0 ){ |
| 680 | 683 | fossil_fatal("no help available for the %s command", |
| 681 | 684 | aCommand[idx].zName); |
| 682 | 685 |
| --- 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 |