Fossil SCM
Improve the "--help" option on commands so that it avoids ambiguity by only looking at commands in the help dictionary.
Commit
3091605fdf469d2f9b8d3c391967a1a02f74b278a2c01149274b0f814e11ea48
Parent
471443b46424077…
2 files changed
+11
-5
+5
-4
+11
-5
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -1008,13 +1008,15 @@ | ||
| 1008 | 1008 | ** -w|--www List all web pages |
| 1009 | 1009 | ** |
| 1010 | 1010 | ** These options can be used when TOPIC is present: |
| 1011 | 1011 | ** |
| 1012 | 1012 | ** -h|--html Format output as HTML rather than plain text |
| 1013 | +** -c|--commands Restrict TOPIC search to commands | |
| 1013 | 1014 | */ |
| 1014 | 1015 | void help_cmd(void){ |
| 1015 | 1016 | int rc; |
| 1017 | + int mask = CMDFLAG_ANY; | |
| 1016 | 1018 | int isPage = 0; |
| 1017 | 1019 | const char *z; |
| 1018 | 1020 | const char *zCmdOrPage; |
| 1019 | 1021 | const CmdOrPage *pCmd = 0; |
| 1020 | 1022 | int useHtml = 0; |
| @@ -1056,32 +1058,36 @@ | ||
| 1056 | 1058 | } |
| 1057 | 1059 | useHtml = find_option("html","h",0)!=0; |
| 1058 | 1060 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1059 | 1061 | if(isPage){ |
| 1060 | 1062 | zCmdOrPage = "page"; |
| 1063 | + }else if( find_option("commands","c",0)!=0 ){ | |
| 1064 | + mask = CMDFLAG_COMMAND; | |
| 1065 | + zCmdOrPage = "command"; | |
| 1061 | 1066 | }else{ |
| 1062 | 1067 | zCmdOrPage = "command or setting"; |
| 1063 | 1068 | } |
| 1064 | - rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); | |
| 1069 | + rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); | |
| 1065 | 1070 | if( rc ){ |
| 1066 | 1071 | int i, n; |
| 1067 | 1072 | const char *az[5]; |
| 1068 | 1073 | if( rc==1 ){ |
| 1069 | 1074 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1070 | 1075 | }else{ |
| 1071 | 1076 | fossil_print("ambiguous %s prefix: %s\n", |
| 1072 | 1077 | zCmdOrPage, g.argv[2]); |
| 1073 | 1078 | } |
| 1074 | - fossil_print("Did you mean one of:\n"); | |
| 1079 | + fossil_print("Did you mean one of these TOPICs:\n"); | |
| 1075 | 1080 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1076 | 1081 | for(i=0; i<n; i++){ |
| 1077 | 1082 | fossil_print(" * %s\n", az[i]); |
| 1078 | 1083 | } |
| 1079 | 1084 | fossil_print("Also consider using:\n"); |
| 1080 | - fossil_print(" fossil help -a ;# show all commands\n"); | |
| 1081 | - fossil_print(" fossil help -w ;# show all web-pages\n"); | |
| 1082 | - fossil_print(" fossil help -s ;# show all settings\n"); | |
| 1085 | + fossil_print(" fossil help TOPIC ;# show help on TOPIC\n"); | |
| 1086 | + fossil_print(" fossil help -a ;# show all commands\n"); | |
| 1087 | + fossil_print(" fossil help -w ;# show all web-pages\n"); | |
| 1088 | + fossil_print(" fossil help -s ;# show all settings\n"); | |
| 1083 | 1089 | fossil_exit(1); |
| 1084 | 1090 | } |
| 1085 | 1091 | z = pCmd->zHelp; |
| 1086 | 1092 | if( z==0 ){ |
| 1087 | 1093 | fossil_fatal("no help available for the %s %s", |
| 1088 | 1094 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1008,13 +1008,15 @@ | |
| 1008 | ** -w|--www List all web pages |
| 1009 | ** |
| 1010 | ** These options can be used when TOPIC is present: |
| 1011 | ** |
| 1012 | ** -h|--html Format output as HTML rather than plain text |
| 1013 | */ |
| 1014 | void help_cmd(void){ |
| 1015 | int rc; |
| 1016 | int isPage = 0; |
| 1017 | const char *z; |
| 1018 | const char *zCmdOrPage; |
| 1019 | const CmdOrPage *pCmd = 0; |
| 1020 | int useHtml = 0; |
| @@ -1056,32 +1058,36 @@ | |
| 1056 | } |
| 1057 | useHtml = find_option("html","h",0)!=0; |
| 1058 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1059 | if(isPage){ |
| 1060 | zCmdOrPage = "page"; |
| 1061 | }else{ |
| 1062 | zCmdOrPage = "command or setting"; |
| 1063 | } |
| 1064 | rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); |
| 1065 | if( rc ){ |
| 1066 | int i, n; |
| 1067 | const char *az[5]; |
| 1068 | if( rc==1 ){ |
| 1069 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1070 | }else{ |
| 1071 | fossil_print("ambiguous %s prefix: %s\n", |
| 1072 | zCmdOrPage, g.argv[2]); |
| 1073 | } |
| 1074 | fossil_print("Did you mean one of:\n"); |
| 1075 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1076 | for(i=0; i<n; i++){ |
| 1077 | fossil_print(" * %s\n", az[i]); |
| 1078 | } |
| 1079 | fossil_print("Also consider using:\n"); |
| 1080 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 1081 | fossil_print(" fossil help -w ;# show all web-pages\n"); |
| 1082 | fossil_print(" fossil help -s ;# show all settings\n"); |
| 1083 | fossil_exit(1); |
| 1084 | } |
| 1085 | z = pCmd->zHelp; |
| 1086 | if( z==0 ){ |
| 1087 | fossil_fatal("no help available for the %s %s", |
| 1088 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1008,13 +1008,15 @@ | |
| 1008 | ** -w|--www List all web pages |
| 1009 | ** |
| 1010 | ** These options can be used when TOPIC is present: |
| 1011 | ** |
| 1012 | ** -h|--html Format output as HTML rather than plain text |
| 1013 | ** -c|--commands Restrict TOPIC search to commands |
| 1014 | */ |
| 1015 | void help_cmd(void){ |
| 1016 | int rc; |
| 1017 | int mask = CMDFLAG_ANY; |
| 1018 | int isPage = 0; |
| 1019 | const char *z; |
| 1020 | const char *zCmdOrPage; |
| 1021 | const CmdOrPage *pCmd = 0; |
| 1022 | int useHtml = 0; |
| @@ -1056,32 +1058,36 @@ | |
| 1058 | } |
| 1059 | useHtml = find_option("html","h",0)!=0; |
| 1060 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1061 | if(isPage){ |
| 1062 | zCmdOrPage = "page"; |
| 1063 | }else if( find_option("commands","c",0)!=0 ){ |
| 1064 | mask = CMDFLAG_COMMAND; |
| 1065 | zCmdOrPage = "command"; |
| 1066 | }else{ |
| 1067 | zCmdOrPage = "command or setting"; |
| 1068 | } |
| 1069 | rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); |
| 1070 | if( rc ){ |
| 1071 | int i, n; |
| 1072 | const char *az[5]; |
| 1073 | if( rc==1 ){ |
| 1074 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1075 | }else{ |
| 1076 | fossil_print("ambiguous %s prefix: %s\n", |
| 1077 | zCmdOrPage, g.argv[2]); |
| 1078 | } |
| 1079 | fossil_print("Did you mean one of these TOPICs:\n"); |
| 1080 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1081 | for(i=0; i<n; i++){ |
| 1082 | fossil_print(" * %s\n", az[i]); |
| 1083 | } |
| 1084 | fossil_print("Also consider using:\n"); |
| 1085 | fossil_print(" fossil help TOPIC ;# show help on TOPIC\n"); |
| 1086 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 1087 | fossil_print(" fossil help -w ;# show all web-pages\n"); |
| 1088 | fossil_print(" fossil help -s ;# show all settings\n"); |
| 1089 | fossil_exit(1); |
| 1090 | } |
| 1091 | z = pCmd->zHelp; |
| 1092 | if( z==0 ){ |
| 1093 | fossil_fatal("no help available for the %s %s", |
| 1094 |
+5
-4
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -796,18 +796,19 @@ | ||
| 796 | 796 | /* If --help is found anywhere on the command line, translate the command |
| 797 | 797 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 798 | 798 | * does not begin with a "-" character. If all arguments start with "-", |
| 799 | 799 | * translate to "fossil help argv[1] argv[2]...". */ |
| 800 | 800 | int i, nNewArgc; |
| 801 | - char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) ); | |
| 801 | + char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+3) ); | |
| 802 | 802 | zNewArgv[0] = g.argv[0]; |
| 803 | 803 | zNewArgv[1] = "help"; |
| 804 | + zNewArgv[2] = "-c"; | |
| 804 | 805 | for(i=1; i<g.argc; i++){ |
| 805 | 806 | if( g.argv[i][0]!='-' ){ |
| 806 | - nNewArgc = 3; | |
| 807 | - zNewArgv[2] = g.argv[i]; | |
| 808 | - zNewArgv[3] = 0; | |
| 807 | + nNewArgc = 4; | |
| 808 | + zNewArgv[3] = g.argv[i]; | |
| 809 | + zNewArgv[4] = 0; | |
| 809 | 810 | break; |
| 810 | 811 | } |
| 811 | 812 | } |
| 812 | 813 | if( i==g.argc ){ |
| 813 | 814 | for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i]; |
| 814 | 815 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -796,18 +796,19 @@ | |
| 796 | /* If --help is found anywhere on the command line, translate the command |
| 797 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 798 | * does not begin with a "-" character. If all arguments start with "-", |
| 799 | * translate to "fossil help argv[1] argv[2]...". */ |
| 800 | int i, nNewArgc; |
| 801 | char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) ); |
| 802 | zNewArgv[0] = g.argv[0]; |
| 803 | zNewArgv[1] = "help"; |
| 804 | for(i=1; i<g.argc; i++){ |
| 805 | if( g.argv[i][0]!='-' ){ |
| 806 | nNewArgc = 3; |
| 807 | zNewArgv[2] = g.argv[i]; |
| 808 | zNewArgv[3] = 0; |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | if( i==g.argc ){ |
| 813 | for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i]; |
| 814 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -796,18 +796,19 @@ | |
| 796 | /* If --help is found anywhere on the command line, translate the command |
| 797 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 798 | * does not begin with a "-" character. If all arguments start with "-", |
| 799 | * translate to "fossil help argv[1] argv[2]...". */ |
| 800 | int i, nNewArgc; |
| 801 | char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+3) ); |
| 802 | zNewArgv[0] = g.argv[0]; |
| 803 | zNewArgv[1] = "help"; |
| 804 | zNewArgv[2] = "-c"; |
| 805 | for(i=1; i<g.argc; i++){ |
| 806 | if( g.argv[i][0]!='-' ){ |
| 807 | nNewArgc = 4; |
| 808 | zNewArgv[3] = g.argv[i]; |
| 809 | zNewArgv[4] = 0; |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | if( i==g.argc ){ |
| 814 | for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i]; |
| 815 |