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.

andybradford 2020-11-25 20:55 trunk
Commit 99f650af0d26c232013ef9d6d69b02cca395d3e61a51acf1a83e5bf25cd517bf
2 files changed +13 -5 +5 -4
+13 -5
--- src/dispatch.c
+++ src/dispatch.c
@@ -1008,18 +1008,21 @@
10081008
** -w|--www List all web pages
10091009
**
10101010
** These options can be used when TOPIC is present:
10111011
**
10121012
** -h|--html Format output as HTML rather than plain text
1013
+** -c|--command Restrict TOPIC search to commands
10131014
*/
10141015
void help_cmd(void){
10151016
int rc;
1017
+ int mask = CMDFLAG_ANY;
10161018
int isPage = 0;
10171019
const char *z;
10181020
const char *zCmdOrPage;
10191021
const CmdOrPage *pCmd = 0;
10201022
int useHtml = 0;
1023
+ int fCmdsOnly = 0;
10211024
Blob txt;
10221025
if( g.argc<3 ){
10231026
z = g.argv[0];
10241027
fossil_print(
10251028
"Usage: %s help TOPIC\n"
@@ -1052,36 +1055,41 @@
10521055
}
10531056
else if( find_option("setting","s",0) ){
10541057
command_list(0, CMDFLAG_SETTING);
10551058
return;
10561059
}
1060
+ fCmdsOnly = find_option("commands","c",0)!=0;
10571061
useHtml = find_option("html","h",0)!=0;
10581062
isPage = ('/' == *g.argv[2]) ? 1 : 0;
10591063
if(isPage){
10601064
zCmdOrPage = "page";
1065
+ }else if( fCmdsOnly ){
1066
+ mask = CMDFLAG_COMMAND;
1067
+ zCmdOrPage = "command";
10611068
}else{
10621069
zCmdOrPage = "command or setting";
10631070
}
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);
10651072
if( rc ){
10661073
int i, n;
10671074
const char *az[5];
10681075
if( rc==1 ){
10691076
fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]);
10701077
}else{
10711078
fossil_print("ambiguous %s prefix: %s\n",
10721079
zCmdOrPage, g.argv[2]);
10731080
}
1074
- fossil_print("Did you mean one of:\n");
1081
+ fossil_print("Did you mean one of these TOPICs:\n");
10751082
n = dispatch_approx_match(g.argv[2], 5, az);
10761083
for(i=0; i<n; i++){
10771084
fossil_print(" * %s\n", az[i]);
10781085
}
10791086
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");
10831091
fossil_exit(1);
10841092
}
10851093
z = pCmd->zHelp;
10861094
if( z==0 ){
10871095
fossil_fatal("no help available for the %s %s",
10881096
--- 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 @@
796796
/* If --help is found anywhere on the command line, translate the command
797797
* to "fossil help cmdname" where "cmdname" is the first argument that
798798
* does not begin with a "-" character. If all arguments start with "-",
799799
* translate to "fossil help argv[1] argv[2]...". */
800800
int i, nNewArgc;
801
- char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+2) );
801
+ char **zNewArgv = fossil_malloc( sizeof(char*)*(g.argc+3) );
802802
zNewArgv[0] = g.argv[0];
803803
zNewArgv[1] = "help";
804
+ zNewArgv[2] = "-c";
804805
for(i=1; i<g.argc; i++){
805806
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;
809810
break;
810811
}
811812
}
812813
if( i==g.argc ){
813814
for(i=1; i<g.argc; i++) zNewArgv[i+1] = g.argv[i];
814815
--- 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

Keyboard Shortcuts

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