Fossil SCM
When using "fossil command --help" restrict the ambiguous matching to just commands to avoid breaking prefixes that otherwise work fine as a command. For example, "fossil di" works fine as a command, but "fossil di --help" suddenly makes it ambiguous.
Commit
99f650af0d26c232013ef9d6d69b02cca395d3e61a51acf1a83e5bf25cd517bf
Parent
34f5ea44038583f…
2 files changed
+13
-5
+5
-4
+13
-5
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -1008,18 +1008,21 @@ | ||
| 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|--command 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; |
| 1023 | + int fCmdsOnly = 0; | |
| 1021 | 1024 | Blob txt; |
| 1022 | 1025 | if( g.argc<3 ){ |
| 1023 | 1026 | z = g.argv[0]; |
| 1024 | 1027 | fossil_print( |
| 1025 | 1028 | "Usage: %s help TOPIC\n" |
| @@ -1052,36 +1055,41 @@ | ||
| 1052 | 1055 | } |
| 1053 | 1056 | else if( find_option("setting","s",0) ){ |
| 1054 | 1057 | command_list(0, CMDFLAG_SETTING); |
| 1055 | 1058 | return; |
| 1056 | 1059 | } |
| 1060 | + fCmdsOnly = find_option("commands","c",0)!=0; | |
| 1057 | 1061 | useHtml = find_option("html","h",0)!=0; |
| 1058 | 1062 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1059 | 1063 | if(isPage){ |
| 1060 | 1064 | zCmdOrPage = "page"; |
| 1065 | + }else if( fCmdsOnly ){ | |
| 1066 | + mask = CMDFLAG_COMMAND; | |
| 1067 | + zCmdOrPage = "command"; | |
| 1061 | 1068 | }else{ |
| 1062 | 1069 | zCmdOrPage = "command or setting"; |
| 1063 | 1070 | } |
| 1064 | - rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); | |
| 1071 | + rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); | |
| 1065 | 1072 | if( rc ){ |
| 1066 | 1073 | int i, n; |
| 1067 | 1074 | const char *az[5]; |
| 1068 | 1075 | if( rc==1 ){ |
| 1069 | 1076 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1070 | 1077 | }else{ |
| 1071 | 1078 | fossil_print("ambiguous %s prefix: %s\n", |
| 1072 | 1079 | zCmdOrPage, g.argv[2]); |
| 1073 | 1080 | } |
| 1074 | - fossil_print("Did you mean one of:\n"); | |
| 1081 | + fossil_print("Did you mean one of these TOPICs:\n"); | |
| 1075 | 1082 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1076 | 1083 | for(i=0; i<n; i++){ |
| 1077 | 1084 | fossil_print(" * %s\n", az[i]); |
| 1078 | 1085 | } |
| 1079 | 1086 | 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"); | |
| 1087 | + fossil_print(" fossil help TOPIC ;# show help on TOPIC\n"); | |
| 1088 | + fossil_print(" fossil help -a ;# show all commands\n"); | |
| 1089 | + fossil_print(" fossil help -w ;# show all web-pages\n"); | |
| 1090 | + fossil_print(" fossil help -s ;# show all settings\n"); | |
| 1083 | 1091 | fossil_exit(1); |
| 1084 | 1092 | } |
| 1085 | 1093 | z = pCmd->zHelp; |
| 1086 | 1094 | if( z==0 ){ |
| 1087 | 1095 | fossil_fatal("no help available for the %s %s", |
| 1088 | 1096 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1008,18 +1008,21 @@ | |
| 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; |
| 1021 | Blob txt; |
| 1022 | if( g.argc<3 ){ |
| 1023 | z = g.argv[0]; |
| 1024 | fossil_print( |
| 1025 | "Usage: %s help TOPIC\n" |
| @@ -1052,36 +1055,41 @@ | |
| 1052 | } |
| 1053 | else if( find_option("setting","s",0) ){ |
| 1054 | command_list(0, CMDFLAG_SETTING); |
| 1055 | return; |
| 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,18 +1008,21 @@ | |
| 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|--command 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; |
| 1023 | int fCmdsOnly = 0; |
| 1024 | Blob txt; |
| 1025 | if( g.argc<3 ){ |
| 1026 | z = g.argv[0]; |
| 1027 | fossil_print( |
| 1028 | "Usage: %s help TOPIC\n" |
| @@ -1052,36 +1055,41 @@ | |
| 1055 | } |
| 1056 | else if( find_option("setting","s",0) ){ |
| 1057 | command_list(0, CMDFLAG_SETTING); |
| 1058 | return; |
| 1059 | } |
| 1060 | fCmdsOnly = find_option("commands","c",0)!=0; |
| 1061 | useHtml = find_option("html","h",0)!=0; |
| 1062 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1063 | if(isPage){ |
| 1064 | zCmdOrPage = "page"; |
| 1065 | }else if( fCmdsOnly ){ |
| 1066 | mask = CMDFLAG_COMMAND; |
| 1067 | zCmdOrPage = "command"; |
| 1068 | }else{ |
| 1069 | zCmdOrPage = "command or setting"; |
| 1070 | } |
| 1071 | rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); |
| 1072 | if( rc ){ |
| 1073 | int i, n; |
| 1074 | const char *az[5]; |
| 1075 | if( rc==1 ){ |
| 1076 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1077 | }else{ |
| 1078 | fossil_print("ambiguous %s prefix: %s\n", |
| 1079 | zCmdOrPage, g.argv[2]); |
| 1080 | } |
| 1081 | fossil_print("Did you mean one of these TOPICs:\n"); |
| 1082 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1083 | for(i=0; i<n; i++){ |
| 1084 | fossil_print(" * %s\n", az[i]); |
| 1085 | } |
| 1086 | fossil_print("Also consider using:\n"); |
| 1087 | fossil_print(" fossil help TOPIC ;# show help on TOPIC\n"); |
| 1088 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 1089 | fossil_print(" fossil help -w ;# show all web-pages\n"); |
| 1090 | fossil_print(" fossil help -s ;# show all settings\n"); |
| 1091 | fossil_exit(1); |
| 1092 | } |
| 1093 | z = pCmd->zHelp; |
| 1094 | if( z==0 ){ |
| 1095 | fossil_fatal("no help available for the %s %s", |
| 1096 |
+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 |