Fossil SCM
Cleanup for the "fossil help" command implementation.
Commit
8a231a7990198d2b0dbd0129e7b040d68f03c56f306ccab4d08476d3a0c04add
Parent
cd90fc91141cc2c…
1 file changed
+73
-71
+73
-71
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -977,21 +977,22 @@ | ||
| 977 | 977 | |
| 978 | 978 | |
| 979 | 979 | /* |
| 980 | 980 | ** List of commands starting with zPrefix, or all commands if zPrefix is NULL. |
| 981 | 981 | */ |
| 982 | -static void command_list(const char *zPrefix, int cmdMask){ | |
| 983 | - int i, nCmd; | |
| 984 | - int nPrefix = zPrefix ? strlen(zPrefix) : 0; | |
| 985 | - const char *aCmd[MX_COMMAND]; | |
| 986 | - for(i=nCmd=0; i<MX_COMMAND; i++){ | |
| 987 | - const char *z = aCommand[i].zName; | |
| 988 | - if( (aCommand[i].eCmdFlags & cmdMask)==0 ) continue; | |
| 989 | - if( zPrefix && memcmp(zPrefix, z, nPrefix)!=0 ) continue; | |
| 990 | - aCmd[nCmd++] = aCommand[i].zName; | |
| 991 | - } | |
| 992 | - multi_column_list(aCmd, nCmd); | |
| 982 | +static void command_list(int cmdMask, int verboseFlag, int useHtml){ | |
| 983 | + if( verboseFlag ){ | |
| 984 | + display_all_help(cmdMask, useHtml, 0); | |
| 985 | + }else{ | |
| 986 | + int i, nCmd; | |
| 987 | + const char *aCmd[MX_COMMAND]; | |
| 988 | + for(i=nCmd=0; i<MX_COMMAND; i++){ | |
| 989 | + if( (aCommand[i].eCmdFlags & cmdMask)==0 ) continue; | |
| 990 | + aCmd[nCmd++] = aCommand[i].zName; | |
| 991 | + } | |
| 992 | + multi_column_list(aCmd, nCmd); | |
| 993 | + } | |
| 993 | 994 | } |
| 994 | 995 | |
| 995 | 996 | /* |
| 996 | 997 | ** Documentation on universal command-line options. |
| 997 | 998 | */ |
| @@ -1032,11 +1033,11 @@ | ||
| 1032 | 1033 | ** |
| 1033 | 1034 | ** -a|--all List both common and auxiliary commands |
| 1034 | 1035 | ** -o|--options List command-line options common to all commands |
| 1035 | 1036 | ** -s|--setting List setting names |
| 1036 | 1037 | ** -t|--test List unsupported "test" commands |
| 1037 | -** -v|--verbose List both names and verbose details where possible | |
| 1038 | +** -v|--verbose List both names and help text | |
| 1038 | 1039 | ** -x|--aux List only auxiliary commands |
| 1039 | 1040 | ** -w|--www List all web pages |
| 1040 | 1041 | ** -f|--full List full set of commands (including auxiliary |
| 1041 | 1042 | ** and unsupported "test" commands), options, |
| 1042 | 1043 | ** settings, and web pages |
| @@ -1050,81 +1051,82 @@ | ||
| 1050 | 1051 | void help_cmd(void){ |
| 1051 | 1052 | int rc; |
| 1052 | 1053 | int mask = CMDFLAG_ANY; |
| 1053 | 1054 | int isPage = 0; |
| 1054 | 1055 | int verboseFlag = 0; |
| 1056 | + int commandsFlag = 0; | |
| 1055 | 1057 | const char *z; |
| 1056 | 1058 | const char *zCmdOrPage; |
| 1057 | 1059 | const CmdOrPage *pCmd = 0; |
| 1058 | 1060 | int useHtml = 0; |
| 1061 | + const char *zTopic; | |
| 1059 | 1062 | Blob txt; |
| 1063 | + verboseFlag = find_option("verbose","v",0)!=0; | |
| 1064 | + commandsFlag = find_option("commands","c",0)!=0; | |
| 1065 | + useHtml = find_option("html","h",0)!=0; | |
| 1066 | + if( find_option("options","o",0) ){ | |
| 1067 | + fossil_print("%s", zOptions); | |
| 1068 | + return; | |
| 1069 | + } | |
| 1070 | + else if( find_option("all","a",0) ){ | |
| 1071 | + command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); | |
| 1072 | + return; | |
| 1073 | + } | |
| 1074 | + else if( find_option("www","w",0) ){ | |
| 1075 | + command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); | |
| 1076 | + return; | |
| 1077 | + } | |
| 1078 | + else if( find_option("aux","x",0) ){ | |
| 1079 | + command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); | |
| 1080 | + return; | |
| 1081 | + } | |
| 1082 | + else if( find_option("test","t",0) ){ | |
| 1083 | + command_list(CMDFLAG_TEST, verboseFlag, useHtml); | |
| 1084 | + return; | |
| 1085 | + } | |
| 1086 | + else if( find_option("setting","s",0) ){ | |
| 1087 | + command_list(CMDFLAG_SETTING, verboseFlag, useHtml); | |
| 1088 | + return; | |
| 1089 | + } | |
| 1090 | + else if( find_option("full","f",0) ){ | |
| 1091 | + fossil_print("fossil commands:\n\n"); | |
| 1092 | + command_list(CMDFLAG_1ST_TIER, verboseFlag, useHtml); | |
| 1093 | + fossil_print("\nfossil auxiliary commands:\n\n"); | |
| 1094 | + command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); | |
| 1095 | + fossil_print("\n%s", zOptions); | |
| 1096 | + fossil_print("\nfossil settings:\n\n"); | |
| 1097 | + command_list(CMDFLAG_SETTING, verboseFlag, useHtml); | |
| 1098 | + fossil_print("\nfossil web pages:\n\n"); | |
| 1099 | + command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); | |
| 1100 | + fossil_print("\nfossil test commands (unsupported):\n\n"); | |
| 1101 | + command_list(CMDFLAG_TEST, verboseFlag, useHtml); | |
| 1102 | + fossil_print("\n"); | |
| 1103 | + version_cmd(); | |
| 1104 | + return; | |
| 1105 | + } | |
| 1106 | + else if( find_option("everything","e",0) ){ | |
| 1107 | + display_all_help(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | | |
| 1108 | + CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0); | |
| 1109 | + return; | |
| 1110 | + } | |
| 1111 | + verify_all_options(); | |
| 1060 | 1112 | if( g.argc<3 ){ |
| 1061 | 1113 | z = g.argv[0]; |
| 1062 | 1114 | fossil_print( |
| 1063 | 1115 | "Usage: %s help TOPIC\n" |
| 1064 | 1116 | "Try \"%s help help\" or \"%s help -a\" for more options\n" |
| 1065 | 1117 | "Frequently used commands:\n", |
| 1066 | 1118 | z, z, z); |
| 1067 | - command_list(0, CMDFLAG_1ST_TIER); | |
| 1068 | - version_cmd(); | |
| 1069 | - return; | |
| 1070 | - } | |
| 1071 | - verboseFlag = find_option("verbose","v",0)!=0; | |
| 1072 | - if( find_option("options","o",0) ){ | |
| 1073 | - fossil_print("%s", zOptions); | |
| 1074 | - return; | |
| 1075 | - } | |
| 1076 | - else if( find_option("all","a",0) ){ | |
| 1077 | - command_list(0, CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER); | |
| 1078 | - return; | |
| 1079 | - } | |
| 1080 | - else if( find_option("www","w",0) ){ | |
| 1081 | - command_list(0, CMDFLAG_WEBPAGE); | |
| 1082 | - return; | |
| 1083 | - } | |
| 1084 | - else if( find_option("aux","x",0) ){ | |
| 1085 | - command_list(0, CMDFLAG_2ND_TIER); | |
| 1086 | - return; | |
| 1087 | - } | |
| 1088 | - else if( find_option("test","t",0) ){ | |
| 1089 | - command_list(0, CMDFLAG_TEST); | |
| 1090 | - return; | |
| 1091 | - } | |
| 1092 | - else if( find_option("setting","s",0) ){ | |
| 1093 | - if( verboseFlag ){ | |
| 1094 | - display_all_help(CMDFLAG_SETTING, 0, 0); | |
| 1095 | - }else{ | |
| 1096 | - command_list(0, CMDFLAG_SETTING); | |
| 1097 | - } | |
| 1098 | - return; | |
| 1099 | - } | |
| 1100 | - else if( find_option("full","f",0) ){ | |
| 1101 | - fossil_print("fossil commands:\n\n"); | |
| 1102 | - command_list(0, CMDFLAG_1ST_TIER); | |
| 1103 | - fossil_print("\nfossil auxiliary commands:\n\n"); | |
| 1104 | - command_list(0, CMDFLAG_2ND_TIER); | |
| 1105 | - fossil_print("\n%s", zOptions); | |
| 1106 | - fossil_print("\nfossil settings:\n\n"); | |
| 1107 | - command_list(0, CMDFLAG_SETTING); | |
| 1108 | - fossil_print("\nfossil web pages:\n\n"); | |
| 1109 | - command_list(0, CMDFLAG_WEBPAGE); | |
| 1110 | - fossil_print("\nfossil test commands (unsupported):\n\n"); | |
| 1111 | - command_list(0, CMDFLAG_TEST); | |
| 1112 | - fossil_print("\n"); | |
| 1113 | - version_cmd(); | |
| 1114 | - return; | |
| 1115 | - } | |
| 1116 | - else if( find_option("everything","e",0) ){ | |
| 1117 | - display_all_help(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | | |
| 1118 | - CMDFLAG_SETTING | CMDFLAG_TEST, 0, 0); | |
| 1119 | - return; | |
| 1120 | - } | |
| 1121 | - useHtml = find_option("html","h",0)!=0; | |
| 1122 | - isPage = ('/' == *g.argv[2]) ? 1 : 0; | |
| 1123 | - if(isPage){ | |
| 1124 | - zCmdOrPage = "page"; | |
| 1125 | - }else if( find_option("commands","c",0)!=0 ){ | |
| 1119 | + command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml); | |
| 1120 | + if( !verboseFlag ) version_cmd(); | |
| 1121 | + return; | |
| 1122 | + } | |
| 1123 | + zTopic = g.argv[2]; | |
| 1124 | + isPage = ('/' == zTopic[0]) ? 1 : 0; | |
| 1125 | + if(isPage){ | |
| 1126 | + zCmdOrPage = "page"; | |
| 1127 | + }else if( commandsFlag ){ | |
| 1126 | 1128 | mask = CMDFLAG_COMMAND; |
| 1127 | 1129 | zCmdOrPage = "command"; |
| 1128 | 1130 | }else{ |
| 1129 | 1131 | zCmdOrPage = "command or setting"; |
| 1130 | 1132 | } |
| 1131 | 1133 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -977,21 +977,22 @@ | |
| 977 | |
| 978 | |
| 979 | /* |
| 980 | ** List of commands starting with zPrefix, or all commands if zPrefix is NULL. |
| 981 | */ |
| 982 | static void command_list(const char *zPrefix, int cmdMask){ |
| 983 | int i, nCmd; |
| 984 | int nPrefix = zPrefix ? strlen(zPrefix) : 0; |
| 985 | const char *aCmd[MX_COMMAND]; |
| 986 | for(i=nCmd=0; i<MX_COMMAND; i++){ |
| 987 | const char *z = aCommand[i].zName; |
| 988 | if( (aCommand[i].eCmdFlags & cmdMask)==0 ) continue; |
| 989 | if( zPrefix && memcmp(zPrefix, z, nPrefix)!=0 ) continue; |
| 990 | aCmd[nCmd++] = aCommand[i].zName; |
| 991 | } |
| 992 | multi_column_list(aCmd, nCmd); |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | ** Documentation on universal command-line options. |
| 997 | */ |
| @@ -1032,11 +1033,11 @@ | |
| 1032 | ** |
| 1033 | ** -a|--all List both common and auxiliary commands |
| 1034 | ** -o|--options List command-line options common to all commands |
| 1035 | ** -s|--setting List setting names |
| 1036 | ** -t|--test List unsupported "test" commands |
| 1037 | ** -v|--verbose List both names and verbose details where possible |
| 1038 | ** -x|--aux List only auxiliary commands |
| 1039 | ** -w|--www List all web pages |
| 1040 | ** -f|--full List full set of commands (including auxiliary |
| 1041 | ** and unsupported "test" commands), options, |
| 1042 | ** settings, and web pages |
| @@ -1050,81 +1051,82 @@ | |
| 1050 | void help_cmd(void){ |
| 1051 | int rc; |
| 1052 | int mask = CMDFLAG_ANY; |
| 1053 | int isPage = 0; |
| 1054 | int verboseFlag = 0; |
| 1055 | const char *z; |
| 1056 | const char *zCmdOrPage; |
| 1057 | const CmdOrPage *pCmd = 0; |
| 1058 | int useHtml = 0; |
| 1059 | Blob txt; |
| 1060 | if( g.argc<3 ){ |
| 1061 | z = g.argv[0]; |
| 1062 | fossil_print( |
| 1063 | "Usage: %s help TOPIC\n" |
| 1064 | "Try \"%s help help\" or \"%s help -a\" for more options\n" |
| 1065 | "Frequently used commands:\n", |
| 1066 | z, z, z); |
| 1067 | command_list(0, CMDFLAG_1ST_TIER); |
| 1068 | version_cmd(); |
| 1069 | return; |
| 1070 | } |
| 1071 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1072 | if( find_option("options","o",0) ){ |
| 1073 | fossil_print("%s", zOptions); |
| 1074 | return; |
| 1075 | } |
| 1076 | else if( find_option("all","a",0) ){ |
| 1077 | command_list(0, CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER); |
| 1078 | return; |
| 1079 | } |
| 1080 | else if( find_option("www","w",0) ){ |
| 1081 | command_list(0, CMDFLAG_WEBPAGE); |
| 1082 | return; |
| 1083 | } |
| 1084 | else if( find_option("aux","x",0) ){ |
| 1085 | command_list(0, CMDFLAG_2ND_TIER); |
| 1086 | return; |
| 1087 | } |
| 1088 | else if( find_option("test","t",0) ){ |
| 1089 | command_list(0, CMDFLAG_TEST); |
| 1090 | return; |
| 1091 | } |
| 1092 | else if( find_option("setting","s",0) ){ |
| 1093 | if( verboseFlag ){ |
| 1094 | display_all_help(CMDFLAG_SETTING, 0, 0); |
| 1095 | }else{ |
| 1096 | command_list(0, CMDFLAG_SETTING); |
| 1097 | } |
| 1098 | return; |
| 1099 | } |
| 1100 | else if( find_option("full","f",0) ){ |
| 1101 | fossil_print("fossil commands:\n\n"); |
| 1102 | command_list(0, CMDFLAG_1ST_TIER); |
| 1103 | fossil_print("\nfossil auxiliary commands:\n\n"); |
| 1104 | command_list(0, CMDFLAG_2ND_TIER); |
| 1105 | fossil_print("\n%s", zOptions); |
| 1106 | fossil_print("\nfossil settings:\n\n"); |
| 1107 | command_list(0, CMDFLAG_SETTING); |
| 1108 | fossil_print("\nfossil web pages:\n\n"); |
| 1109 | command_list(0, CMDFLAG_WEBPAGE); |
| 1110 | fossil_print("\nfossil test commands (unsupported):\n\n"); |
| 1111 | command_list(0, CMDFLAG_TEST); |
| 1112 | fossil_print("\n"); |
| 1113 | version_cmd(); |
| 1114 | return; |
| 1115 | } |
| 1116 | else if( find_option("everything","e",0) ){ |
| 1117 | display_all_help(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | |
| 1118 | CMDFLAG_SETTING | CMDFLAG_TEST, 0, 0); |
| 1119 | return; |
| 1120 | } |
| 1121 | useHtml = find_option("html","h",0)!=0; |
| 1122 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 1123 | if(isPage){ |
| 1124 | zCmdOrPage = "page"; |
| 1125 | }else if( find_option("commands","c",0)!=0 ){ |
| 1126 | mask = CMDFLAG_COMMAND; |
| 1127 | zCmdOrPage = "command"; |
| 1128 | }else{ |
| 1129 | zCmdOrPage = "command or setting"; |
| 1130 | } |
| 1131 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -977,21 +977,22 @@ | |
| 977 | |
| 978 | |
| 979 | /* |
| 980 | ** List of commands starting with zPrefix, or all commands if zPrefix is NULL. |
| 981 | */ |
| 982 | static void command_list(int cmdMask, int verboseFlag, int useHtml){ |
| 983 | if( verboseFlag ){ |
| 984 | display_all_help(cmdMask, useHtml, 0); |
| 985 | }else{ |
| 986 | int i, nCmd; |
| 987 | const char *aCmd[MX_COMMAND]; |
| 988 | for(i=nCmd=0; i<MX_COMMAND; i++){ |
| 989 | if( (aCommand[i].eCmdFlags & cmdMask)==0 ) continue; |
| 990 | aCmd[nCmd++] = aCommand[i].zName; |
| 991 | } |
| 992 | multi_column_list(aCmd, nCmd); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /* |
| 997 | ** Documentation on universal command-line options. |
| 998 | */ |
| @@ -1032,11 +1033,11 @@ | |
| 1033 | ** |
| 1034 | ** -a|--all List both common and auxiliary commands |
| 1035 | ** -o|--options List command-line options common to all commands |
| 1036 | ** -s|--setting List setting names |
| 1037 | ** -t|--test List unsupported "test" commands |
| 1038 | ** -v|--verbose List both names and help text |
| 1039 | ** -x|--aux List only auxiliary commands |
| 1040 | ** -w|--www List all web pages |
| 1041 | ** -f|--full List full set of commands (including auxiliary |
| 1042 | ** and unsupported "test" commands), options, |
| 1043 | ** settings, and web pages |
| @@ -1050,81 +1051,82 @@ | |
| 1051 | void help_cmd(void){ |
| 1052 | int rc; |
| 1053 | int mask = CMDFLAG_ANY; |
| 1054 | int isPage = 0; |
| 1055 | int verboseFlag = 0; |
| 1056 | int commandsFlag = 0; |
| 1057 | const char *z; |
| 1058 | const char *zCmdOrPage; |
| 1059 | const CmdOrPage *pCmd = 0; |
| 1060 | int useHtml = 0; |
| 1061 | const char *zTopic; |
| 1062 | Blob txt; |
| 1063 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1064 | commandsFlag = find_option("commands","c",0)!=0; |
| 1065 | useHtml = find_option("html","h",0)!=0; |
| 1066 | if( find_option("options","o",0) ){ |
| 1067 | fossil_print("%s", zOptions); |
| 1068 | return; |
| 1069 | } |
| 1070 | else if( find_option("all","a",0) ){ |
| 1071 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1072 | return; |
| 1073 | } |
| 1074 | else if( find_option("www","w",0) ){ |
| 1075 | command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
| 1076 | return; |
| 1077 | } |
| 1078 | else if( find_option("aux","x",0) ){ |
| 1079 | command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1080 | return; |
| 1081 | } |
| 1082 | else if( find_option("test","t",0) ){ |
| 1083 | command_list(CMDFLAG_TEST, verboseFlag, useHtml); |
| 1084 | return; |
| 1085 | } |
| 1086 | else if( find_option("setting","s",0) ){ |
| 1087 | command_list(CMDFLAG_SETTING, verboseFlag, useHtml); |
| 1088 | return; |
| 1089 | } |
| 1090 | else if( find_option("full","f",0) ){ |
| 1091 | fossil_print("fossil commands:\n\n"); |
| 1092 | command_list(CMDFLAG_1ST_TIER, verboseFlag, useHtml); |
| 1093 | fossil_print("\nfossil auxiliary commands:\n\n"); |
| 1094 | command_list(CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1095 | fossil_print("\n%s", zOptions); |
| 1096 | fossil_print("\nfossil settings:\n\n"); |
| 1097 | command_list(CMDFLAG_SETTING, verboseFlag, useHtml); |
| 1098 | fossil_print("\nfossil web pages:\n\n"); |
| 1099 | command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
| 1100 | fossil_print("\nfossil test commands (unsupported):\n\n"); |
| 1101 | command_list(CMDFLAG_TEST, verboseFlag, useHtml); |
| 1102 | fossil_print("\n"); |
| 1103 | version_cmd(); |
| 1104 | return; |
| 1105 | } |
| 1106 | else if( find_option("everything","e",0) ){ |
| 1107 | display_all_help(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE | |
| 1108 | CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0); |
| 1109 | return; |
| 1110 | } |
| 1111 | verify_all_options(); |
| 1112 | if( g.argc<3 ){ |
| 1113 | z = g.argv[0]; |
| 1114 | fossil_print( |
| 1115 | "Usage: %s help TOPIC\n" |
| 1116 | "Try \"%s help help\" or \"%s help -a\" for more options\n" |
| 1117 | "Frequently used commands:\n", |
| 1118 | z, z, z); |
| 1119 | command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml); |
| 1120 | if( !verboseFlag ) version_cmd(); |
| 1121 | return; |
| 1122 | } |
| 1123 | zTopic = g.argv[2]; |
| 1124 | isPage = ('/' == zTopic[0]) ? 1 : 0; |
| 1125 | if(isPage){ |
| 1126 | zCmdOrPage = "page"; |
| 1127 | }else if( commandsFlag ){ |
| 1128 | mask = CMDFLAG_COMMAND; |
| 1129 | zCmdOrPage = "command"; |
| 1130 | }else{ |
| 1131 | zCmdOrPage = "command or setting"; |
| 1132 | } |
| 1133 |