Fossil SCM

Improve the "--help" option on commands so that it avoids ambiguity by only looking at commands in the help dictionary.

drh 2020-11-25 21:51 trunk merge
Commit 3091605fdf469d2f9b8d3c391967a1a02f74b278a2c01149274b0f814e11ea48
2 files changed +11 -5 +5 -4
+11 -5
--- src/dispatch.c
+++ src/dispatch.c
@@ -1008,13 +1008,15 @@
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|--commands 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;
@@ -1056,32 +1058,36 @@
10561058
}
10571059
useHtml = find_option("html","h",0)!=0;
10581060
isPage = ('/' == *g.argv[2]) ? 1 : 0;
10591061
if(isPage){
10601062
zCmdOrPage = "page";
1063
+ }else if( find_option("commands","c",0)!=0 ){
1064
+ mask = CMDFLAG_COMMAND;
1065
+ zCmdOrPage = "command";
10611066
}else{
10621067
zCmdOrPage = "command or setting";
10631068
}
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);
10651070
if( rc ){
10661071
int i, n;
10671072
const char *az[5];
10681073
if( rc==1 ){
10691074
fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]);
10701075
}else{
10711076
fossil_print("ambiguous %s prefix: %s\n",
10721077
zCmdOrPage, g.argv[2]);
10731078
}
1074
- fossil_print("Did you mean one of:\n");
1079
+ fossil_print("Did you mean one of these TOPICs:\n");
10751080
n = dispatch_approx_match(g.argv[2], 5, az);
10761081
for(i=0; i<n; i++){
10771082
fossil_print(" * %s\n", az[i]);
10781083
}
10791084
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");
10831089
fossil_exit(1);
10841090
}
10851091
z = pCmd->zHelp;
10861092
if( z==0 ){
10871093
fossil_fatal("no help available for the %s %s",
10881094
--- 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 @@
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