Fossil SCM
Add new command "fossil options" that shows command-line options only from help text.
Commit
aff179d89f9bee713c3e584c3ce04b70f0caa9cd0cdcc0858bb52cfd80d5523d
Parent
638c98d360ce4a4…
1 file changed
+171
-99
+171
-99
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -1079,11 +1079,11 @@ | ||
| 1079 | 1079 | const char *z, /* Full original help text */ |
| 1080 | 1080 | Blob *pOut, /* Write simplified help text here */ |
| 1081 | 1081 | const char *zTopic, /* TOPIC */ |
| 1082 | 1082 | const char *zSubtopic /* SUBTOPIC */ |
| 1083 | 1083 | ){ |
| 1084 | - Blob in, line, subsection; | |
| 1084 | + Blob in, line; //, subsection; | |
| 1085 | 1085 | int n = 0; |
| 1086 | 1086 | char *zQTop = re_quote(zTopic); |
| 1087 | 1087 | char *zQSub = re_quote(zSubtopic); |
| 1088 | 1088 | char *zPattern = mprintf("> fossil %s .*\\b%s\\b", zQTop, zQSub); |
| 1089 | 1089 | ReCompiled *pRe = 0; |
| @@ -1107,64 +1107,10 @@ | ||
| 1107 | 1107 | blob_reset(&line); |
| 1108 | 1108 | re_free(pRe); |
| 1109 | 1109 | if( n ){ |
| 1110 | 1110 | blob_trim(pOut); |
| 1111 | 1111 | blob_reset(&in); |
| 1112 | - return n; | |
| 1113 | - } | |
| 1114 | - | |
| 1115 | - /* No subtopic found. If zSubtopic is "options", print all command-line | |
| 1116 | - ** options in the help text. | |
| 1117 | - */ | |
| 1118 | - if( fossil_strcmp("options",zSubtopic)==0 ){ | |
| 1119 | - blob_rewind(&in); | |
| 1120 | - blob_init(&subsection, 0, 0); | |
| 1121 | - re_compile(&pRe, "^ +-.* ", 0); | |
| 1122 | - while( blob_line(&in, &line) ){ | |
| 1123 | - size_t len = blob_strlen(&line); | |
| 1124 | - if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ | |
| 1125 | - if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ | |
| 1126 | - blob_appendb(pOut, &subsection); | |
| 1127 | - blob_reset(&subsection); | |
| 1128 | - } | |
| 1129 | - blob_appendb(pOut, &line); | |
| 1130 | - n++; | |
| 1131 | - }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ | |
| 1132 | - subsection = line; | |
| 1133 | - } | |
| 1134 | - } | |
| 1135 | - re_free(pRe); | |
| 1136 | - if( n ){ | |
| 1137 | - blob_trim(pOut); | |
| 1138 | - blob_reset(&in); | |
| 1139 | - return n; | |
| 1140 | - } | |
| 1141 | - } | |
| 1142 | - | |
| 1143 | - | |
| 1144 | - /* If no subtopic name zSubtopic if found, try to match any text. | |
| 1145 | - */ | |
| 1146 | - blob_rewind(&in); | |
| 1147 | - blob_init(&subsection, 0, 0); | |
| 1148 | - while( blob_line(&in, &line) ){ | |
| 1149 | - size_t len = blob_strlen(&line); | |
| 1150 | - if( strstr(blob_str(&line), zSubtopic)!=0 ){ | |
| 1151 | - if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ | |
| 1152 | - blob_appendb(pOut, &subsection); | |
| 1153 | - blob_reset(&subsection); | |
| 1154 | - } | |
| 1155 | - blob_appendb(pOut, &line); | |
| 1156 | - n++; | |
| 1157 | - }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ | |
| 1158 | - subsection = line; | |
| 1159 | - } | |
| 1160 | - } | |
| 1161 | - blob_reset(&in); | |
| 1162 | - if( n ){ | |
| 1163 | - blob_trim(pOut); | |
| 1164 | - }else{ | |
| 1165 | - blob_reset(pOut); | |
| 1166 | 1112 | } |
| 1167 | 1113 | return n; |
| 1168 | 1114 | } |
| 1169 | 1115 | |
| 1170 | 1116 | /* |
| @@ -1285,21 +1231,156 @@ | ||
| 1285 | 1231 | @ --systemtrace Trace calls to system() |
| 1286 | 1232 | @ -U|--user USER Make the default user be USER |
| 1287 | 1233 | @ --utc Display times using UTC |
| 1288 | 1234 | @ --vfs NAME Cause SQLite to use the NAME VFS |
| 1289 | 1235 | ; |
| 1236 | + | |
| 1237 | +/* | |
| 1238 | +** COMMAND: options | |
| 1239 | +** | |
| 1240 | +** Usage: %fossil options [COMMAND] [SUBCOMMAND] | |
| 1241 | +** | |
| 1242 | +** Show available command-line options | |
| 1243 | +** | |
| 1244 | +** fossil options Show command-line options available | |
| 1245 | +** on all commands. | |
| 1246 | +** | |
| 1247 | +** fossil options COMMAND Show options available on COMMAND | |
| 1248 | +** | |
| 1249 | +** fossil options COMMAND SUBCMD Show options specific to SUBCMD | |
| 1250 | +** | |
| 1251 | +** See also: [[help]], [[usage]] | |
| 1252 | +*/ | |
| 1253 | +void options_cmd(void){ | |
| 1254 | + Blob s1, s2, txt, subsection, out, line; | |
| 1255 | + const char *z; | |
| 1256 | + ReCompiled *pRe = 0; | |
| 1257 | + | |
| 1258 | + verify_all_options(); | |
| 1259 | + if( g.argc>4 ){ | |
| 1260 | + usage("[COMMAND] [SUBCOMMAND]"); | |
| 1261 | + } | |
| 1262 | + blob_init(&s1, 0, 0); | |
| 1263 | + if( g.argc==2 ){ | |
| 1264 | + fossil_print("%s", zOptions); | |
| 1265 | + return; | |
| 1266 | + }else{ | |
| 1267 | + int rc; | |
| 1268 | + const char *zTopic = g.argv[2]; | |
| 1269 | + const char *zSubtopic = g.argc==4 ? g.argv[3] : 0; | |
| 1270 | + const CmdOrPage *pCmd = 0; | |
| 1271 | + rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); | |
| 1272 | + if( rc ){ | |
| 1273 | + if( rc==1 ){ | |
| 1274 | + fossil_print("unknown command: %s\n", zTopic); | |
| 1275 | + }else{ | |
| 1276 | + fossil_print("ambiguous command prefix: %s\n", zTopic); | |
| 1277 | + } | |
| 1278 | + return; | |
| 1279 | + } | |
| 1280 | + z = pCmd->zHelp; | |
| 1281 | + if( z==0 ){ | |
| 1282 | + fossil_fatal("no help available for the %s", pCmd->zName); | |
| 1283 | + } | |
| 1284 | + if( zSubtopic ){ | |
| 1285 | + if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic) ){ | |
| 1286 | + z = blob_str(&s1); | |
| 1287 | + }else{ | |
| 1288 | + fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); | |
| 1289 | + } | |
| 1290 | + } | |
| 1291 | + } | |
| 1292 | + blob_init(&txt, z, -1); | |
| 1293 | + blob_init(&subsection, 0, 0); | |
| 1294 | + blob_init(&s2, 0, 0); | |
| 1295 | + re_compile(&pRe, "^ +-.* ", 0); | |
| 1296 | + while( blob_line(&txt, &line) ){ | |
| 1297 | + size_t len = blob_strlen(&line); | |
| 1298 | + if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ | |
| 1299 | + if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ | |
| 1300 | + blob_appendb(&s2, &subsection); | |
| 1301 | + blob_reset(&subsection); | |
| 1302 | + } | |
| 1303 | + blob_appendb(&s2, &line); | |
| 1304 | + }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ | |
| 1305 | + subsection = line; | |
| 1306 | + } | |
| 1307 | + } | |
| 1308 | + re_free(pRe); | |
| 1309 | + blob_init(&out, 0, 0); | |
| 1310 | + blob_trim(&s2); | |
| 1311 | + help_to_text(blob_str(&s2), &out); | |
| 1312 | + fossil_print("%s\n", blob_str(&out)); | |
| 1313 | + blob_reset(&out); | |
| 1314 | + blob_reset(&s1); | |
| 1315 | + blob_reset(&s2); | |
| 1316 | + blob_reset(&line); | |
| 1317 | + blob_reset(&txt); | |
| 1318 | + blob_reset(&subsection); | |
| 1319 | +} | |
| 1290 | 1320 | |
| 1291 | 1321 | /* |
| 1292 | 1322 | ** COMMAND: usage |
| 1293 | 1323 | ** |
| 1294 | 1324 | ** Usage: %fossil usage COMMAND [SUBCOMMAND] |
| 1295 | 1325 | ** |
| 1296 | -** Show succinct usage instruction for a Fossil command. Shorthand | |
| 1297 | -** for "fossil help --usage COMMAND [SUBCOMMAND]" | |
| 1326 | +** Show succinct usage instructions for a Fossil command. | |
| 1327 | +** | |
| 1328 | +** See also: [[help]], [[options]] | |
| 1298 | 1329 | */ |
| 1299 | 1330 | void usage_cmd(void){ |
| 1300 | - help_cmd(); | |
| 1331 | + int rc; | |
| 1332 | + const char *zTopic; | |
| 1333 | + const char *zSubtopic; | |
| 1334 | + const CmdOrPage *pCmd = 0; | |
| 1335 | + Blob s1, s2, out; | |
| 1336 | + const char *z; | |
| 1337 | + | |
| 1338 | + verify_all_options(); | |
| 1339 | + if( g.argc<3 || g.argc>4 ){ | |
| 1340 | + usage("COMMAND [SUBCOMMAND]"); | |
| 1341 | + } | |
| 1342 | + zTopic = g.argv[2]; | |
| 1343 | + zSubtopic = g.argc==4 ? g.argv[3] : 0; | |
| 1344 | + rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); | |
| 1345 | + if( rc ){ | |
| 1346 | + int i, n; | |
| 1347 | + const char *az[5]; | |
| 1348 | + if( rc==1 ){ | |
| 1349 | + fossil_print("unknown command: %s\n", zTopic); | |
| 1350 | + }else{ | |
| 1351 | + fossil_print("ambiguous command prefix: %s\n", zTopic); | |
| 1352 | + } | |
| 1353 | + fossil_print("Did you mean one of these TOPICs:\n"); | |
| 1354 | + n = dispatch_approx_match(zTopic, 5, az); | |
| 1355 | + for(i=0; i<n; i++){ | |
| 1356 | + fossil_print(" * %s\n", az[i]); | |
| 1357 | + } | |
| 1358 | + return; | |
| 1359 | + } | |
| 1360 | + z = pCmd->zHelp; | |
| 1361 | + if( z==0 ){ | |
| 1362 | + fossil_fatal("no help available for the %s", pCmd->zName); | |
| 1363 | + } | |
| 1364 | + blob_init(&s1, 0, 0); | |
| 1365 | + blob_init(&s2, 0, 0); | |
| 1366 | + if( zSubtopic!=0 ){ | |
| 1367 | + if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic) ){ | |
| 1368 | + z = blob_str(&s1); | |
| 1369 | + }else{ | |
| 1370 | + fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); | |
| 1371 | + } | |
| 1372 | + } | |
| 1373 | + if( simplify_to_usage(z, &s2, zTopic) ){ | |
| 1374 | + z = blob_str(&s2); | |
| 1375 | + } | |
| 1376 | + blob_init(&out, 0, 0); | |
| 1377 | + help_to_text(z, &out); | |
| 1378 | + fossil_print("%s\n", blob_str(&out)); | |
| 1379 | + blob_reset(&out); | |
| 1380 | + blob_reset(&s1); | |
| 1381 | + blob_reset(&s2); | |
| 1301 | 1382 | } |
| 1302 | 1383 | |
| 1303 | 1384 | #if 0 |
| 1304 | 1385 | /* |
| 1305 | 1386 | ** off-COMMAND: apropos |
| @@ -1324,19 +1405,17 @@ | ||
| 1324 | 1405 | #endif |
| 1325 | 1406 | |
| 1326 | 1407 | /* |
| 1327 | 1408 | ** COMMAND: help |
| 1328 | 1409 | ** |
| 1329 | -** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND|options|PATTERN] | |
| 1410 | +** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] | |
| 1330 | 1411 | ** |
| 1331 | 1412 | ** Display information on how to use TOPIC, which may be a command, webpage, or |
| 1332 | 1413 | ** setting. Webpage names begin with "/". If TOPIC is omitted, a list of |
| 1333 | -** topics is returned. If there is an extra argument after TOPIC it is either | |
| 1414 | +** topics is returned. If there is an extra argument after TOPIC, it is | |
| 1334 | 1415 | ** the name of a subcommand, in which case only the help text for that one |
| 1335 | -** subcommand is shown, or it is the keyword "options" which displays all | |
| 1336 | -** command-line options for TOPIC, or it is a text pattern which causes all | |
| 1337 | -** lines of the help text that match that pattern to be shown. | |
| 1416 | +** subcommand is shown. | |
| 1338 | 1417 | ** |
| 1339 | 1418 | ** The following options can be used when TOPIC is omitted: |
| 1340 | 1419 | ** |
| 1341 | 1420 | ** -a|--all List both common and auxiliary commands |
| 1342 | 1421 | ** -e|--everything List all help on all topics |
| @@ -1354,10 +1433,12 @@ | ||
| 1354 | 1433 | ** |
| 1355 | 1434 | ** -c|--commands Restrict TOPIC search to commands |
| 1356 | 1435 | ** -h|--html Format output as HTML rather than plain text |
| 1357 | 1436 | ** --raw Output raw, unformatted help text |
| 1358 | 1437 | ** -u|--usage Show a succinct usage summary, not full help text |
| 1438 | +** | |
| 1439 | +** See also: [[usage]], [[options]], [[search]] with the -h option | |
| 1359 | 1440 | */ |
| 1360 | 1441 | void help_cmd(void){ |
| 1361 | 1442 | int rc; |
| 1362 | 1443 | int mask = CMDFLAG_ANY; /* Mask of help topic types */ |
| 1363 | 1444 | int isPage = 0; /* True if TOPIC is a page */ |
| @@ -1377,14 +1458,10 @@ | ||
| 1377 | 1458 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1378 | 1459 | commandsFlag = find_option("commands","c",0)!=0; |
| 1379 | 1460 | useHtml = find_option("html","h",0)!=0; |
| 1380 | 1461 | bRaw = find_option("raw",0,0)!=0; |
| 1381 | 1462 | if( find_option("usage","u",0)!=0 ) bUsage = 1; |
| 1382 | - if( find_option("options","o",0) ){ | |
| 1383 | - fossil_print("%s", zOptions); | |
| 1384 | - return; | |
| 1385 | - } | |
| 1386 | 1463 | else if( find_option("all","a",0) ){ |
| 1387 | 1464 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1388 | 1465 | return; |
| 1389 | 1466 | } |
| 1390 | 1467 | else if( find_option("www","w",0) ){ |
| @@ -1449,42 +1526,37 @@ | ||
| 1449 | 1526 | mask = CMDFLAG_COMMAND; |
| 1450 | 1527 | zCmdOrPage = "command"; |
| 1451 | 1528 | }else{ |
| 1452 | 1529 | zCmdOrPage = "command or setting"; |
| 1453 | 1530 | } |
| 1454 | - if( fossil_strcmp(zTopic,"options")==0 ){ | |
| 1455 | - z = zOptions; | |
| 1456 | - pCmd = 0; | |
| 1457 | - }else{ | |
| 1458 | - rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); | |
| 1459 | - if( rc ){ | |
| 1460 | - int i, n; | |
| 1461 | - const char *az[5]; | |
| 1462 | - if( rc==1 ){ | |
| 1463 | - fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); | |
| 1464 | - }else{ | |
| 1465 | - fossil_print("ambiguous %s prefix: %s\n", | |
| 1466 | - zCmdOrPage, g.argv[2]); | |
| 1467 | - } | |
| 1468 | - fossil_print("Did you mean one of these TOPICs:\n"); | |
| 1469 | - n = dispatch_approx_match(g.argv[2], 5, az); | |
| 1470 | - for(i=0; i<n; i++){ | |
| 1471 | - fossil_print(" * %s\n", az[i]); | |
| 1472 | - } | |
| 1473 | - fossil_print("Other commands to try:\n"); | |
| 1474 | - fossil_print(" fossil search -h PATTERN ;# search all help text\n"); | |
| 1475 | - fossil_print(" fossil help -a ;# show all commands\n"); | |
| 1476 | - fossil_print(" fossil help -w ;# show all web-pages\n"); | |
| 1477 | - fossil_print(" fossil help -s ;# show all settings\n"); | |
| 1478 | - fossil_print(" fossil help -o ;# show global options\n"); | |
| 1479 | - return; | |
| 1480 | - } | |
| 1481 | - z = pCmd->zHelp; | |
| 1482 | - if( z==0 ){ | |
| 1483 | - fossil_fatal("no help available for the %s %s", | |
| 1484 | - pCmd->zName, zCmdOrPage); | |
| 1485 | - } | |
| 1531 | + rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); | |
| 1532 | + if( rc ){ | |
| 1533 | + int i, n; | |
| 1534 | + const char *az[5]; | |
| 1535 | + if( rc==1 ){ | |
| 1536 | + fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); | |
| 1537 | + }else{ | |
| 1538 | + fossil_print("ambiguous %s prefix: %s\n", | |
| 1539 | + zCmdOrPage, g.argv[2]); | |
| 1540 | + } | |
| 1541 | + fossil_print("Did you mean one of these TOPICs:\n"); | |
| 1542 | + n = dispatch_approx_match(g.argv[2], 5, az); | |
| 1543 | + for(i=0; i<n; i++){ | |
| 1544 | + fossil_print(" * %s\n", az[i]); | |
| 1545 | + } | |
| 1546 | + fossil_print("Other commands to try:\n"); | |
| 1547 | + fossil_print(" fossil search -h PATTERN ;# search all help text\n"); | |
| 1548 | + fossil_print(" fossil help -a ;# show all commands\n"); | |
| 1549 | + fossil_print(" fossil help -w ;# show all web-pages\n"); | |
| 1550 | + fossil_print(" fossil help -s ;# show all settings\n"); | |
| 1551 | + fossil_print(" fossil help -o ;# show global options\n"); | |
| 1552 | + return; | |
| 1553 | + } | |
| 1554 | + z = pCmd->zHelp; | |
| 1555 | + if( z==0 ){ | |
| 1556 | + fossil_fatal("no help available for the %s %s", | |
| 1557 | + pCmd->zName, zCmdOrPage); | |
| 1486 | 1558 | } |
| 1487 | 1559 | blob_init(&subtext1, 0, 0); |
| 1488 | 1560 | blob_init(&subtext2, 0, 0); |
| 1489 | 1561 | if( zSubtopic!=0 ){ |
| 1490 | 1562 | if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){ |
| 1491 | 1563 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1079,11 +1079,11 @@ | |
| 1079 | const char *z, /* Full original help text */ |
| 1080 | Blob *pOut, /* Write simplified help text here */ |
| 1081 | const char *zTopic, /* TOPIC */ |
| 1082 | const char *zSubtopic /* SUBTOPIC */ |
| 1083 | ){ |
| 1084 | Blob in, line, subsection; |
| 1085 | int n = 0; |
| 1086 | char *zQTop = re_quote(zTopic); |
| 1087 | char *zQSub = re_quote(zSubtopic); |
| 1088 | char *zPattern = mprintf("> fossil %s .*\\b%s\\b", zQTop, zQSub); |
| 1089 | ReCompiled *pRe = 0; |
| @@ -1107,64 +1107,10 @@ | |
| 1107 | blob_reset(&line); |
| 1108 | re_free(pRe); |
| 1109 | if( n ){ |
| 1110 | blob_trim(pOut); |
| 1111 | blob_reset(&in); |
| 1112 | return n; |
| 1113 | } |
| 1114 | |
| 1115 | /* No subtopic found. If zSubtopic is "options", print all command-line |
| 1116 | ** options in the help text. |
| 1117 | */ |
| 1118 | if( fossil_strcmp("options",zSubtopic)==0 ){ |
| 1119 | blob_rewind(&in); |
| 1120 | blob_init(&subsection, 0, 0); |
| 1121 | re_compile(&pRe, "^ +-.* ", 0); |
| 1122 | while( blob_line(&in, &line) ){ |
| 1123 | size_t len = blob_strlen(&line); |
| 1124 | if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ |
| 1125 | if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ |
| 1126 | blob_appendb(pOut, &subsection); |
| 1127 | blob_reset(&subsection); |
| 1128 | } |
| 1129 | blob_appendb(pOut, &line); |
| 1130 | n++; |
| 1131 | }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ |
| 1132 | subsection = line; |
| 1133 | } |
| 1134 | } |
| 1135 | re_free(pRe); |
| 1136 | if( n ){ |
| 1137 | blob_trim(pOut); |
| 1138 | blob_reset(&in); |
| 1139 | return n; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | /* If no subtopic name zSubtopic if found, try to match any text. |
| 1145 | */ |
| 1146 | blob_rewind(&in); |
| 1147 | blob_init(&subsection, 0, 0); |
| 1148 | while( blob_line(&in, &line) ){ |
| 1149 | size_t len = blob_strlen(&line); |
| 1150 | if( strstr(blob_str(&line), zSubtopic)!=0 ){ |
| 1151 | if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ |
| 1152 | blob_appendb(pOut, &subsection); |
| 1153 | blob_reset(&subsection); |
| 1154 | } |
| 1155 | blob_appendb(pOut, &line); |
| 1156 | n++; |
| 1157 | }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ |
| 1158 | subsection = line; |
| 1159 | } |
| 1160 | } |
| 1161 | blob_reset(&in); |
| 1162 | if( n ){ |
| 1163 | blob_trim(pOut); |
| 1164 | }else{ |
| 1165 | blob_reset(pOut); |
| 1166 | } |
| 1167 | return n; |
| 1168 | } |
| 1169 | |
| 1170 | /* |
| @@ -1285,21 +1231,156 @@ | |
| 1285 | @ --systemtrace Trace calls to system() |
| 1286 | @ -U|--user USER Make the default user be USER |
| 1287 | @ --utc Display times using UTC |
| 1288 | @ --vfs NAME Cause SQLite to use the NAME VFS |
| 1289 | ; |
| 1290 | |
| 1291 | /* |
| 1292 | ** COMMAND: usage |
| 1293 | ** |
| 1294 | ** Usage: %fossil usage COMMAND [SUBCOMMAND] |
| 1295 | ** |
| 1296 | ** Show succinct usage instruction for a Fossil command. Shorthand |
| 1297 | ** for "fossil help --usage COMMAND [SUBCOMMAND]" |
| 1298 | */ |
| 1299 | void usage_cmd(void){ |
| 1300 | help_cmd(); |
| 1301 | } |
| 1302 | |
| 1303 | #if 0 |
| 1304 | /* |
| 1305 | ** off-COMMAND: apropos |
| @@ -1324,19 +1405,17 @@ | |
| 1324 | #endif |
| 1325 | |
| 1326 | /* |
| 1327 | ** COMMAND: help |
| 1328 | ** |
| 1329 | ** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND|options|PATTERN] |
| 1330 | ** |
| 1331 | ** Display information on how to use TOPIC, which may be a command, webpage, or |
| 1332 | ** setting. Webpage names begin with "/". If TOPIC is omitted, a list of |
| 1333 | ** topics is returned. If there is an extra argument after TOPIC it is either |
| 1334 | ** the name of a subcommand, in which case only the help text for that one |
| 1335 | ** subcommand is shown, or it is the keyword "options" which displays all |
| 1336 | ** command-line options for TOPIC, or it is a text pattern which causes all |
| 1337 | ** lines of the help text that match that pattern to be shown. |
| 1338 | ** |
| 1339 | ** The following options can be used when TOPIC is omitted: |
| 1340 | ** |
| 1341 | ** -a|--all List both common and auxiliary commands |
| 1342 | ** -e|--everything List all help on all topics |
| @@ -1354,10 +1433,12 @@ | |
| 1354 | ** |
| 1355 | ** -c|--commands Restrict TOPIC search to commands |
| 1356 | ** -h|--html Format output as HTML rather than plain text |
| 1357 | ** --raw Output raw, unformatted help text |
| 1358 | ** -u|--usage Show a succinct usage summary, not full help text |
| 1359 | */ |
| 1360 | void help_cmd(void){ |
| 1361 | int rc; |
| 1362 | int mask = CMDFLAG_ANY; /* Mask of help topic types */ |
| 1363 | int isPage = 0; /* True if TOPIC is a page */ |
| @@ -1377,14 +1458,10 @@ | |
| 1377 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1378 | commandsFlag = find_option("commands","c",0)!=0; |
| 1379 | useHtml = find_option("html","h",0)!=0; |
| 1380 | bRaw = find_option("raw",0,0)!=0; |
| 1381 | if( find_option("usage","u",0)!=0 ) bUsage = 1; |
| 1382 | if( find_option("options","o",0) ){ |
| 1383 | fossil_print("%s", zOptions); |
| 1384 | return; |
| 1385 | } |
| 1386 | else if( find_option("all","a",0) ){ |
| 1387 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1388 | return; |
| 1389 | } |
| 1390 | else if( find_option("www","w",0) ){ |
| @@ -1449,42 +1526,37 @@ | |
| 1449 | mask = CMDFLAG_COMMAND; |
| 1450 | zCmdOrPage = "command"; |
| 1451 | }else{ |
| 1452 | zCmdOrPage = "command or setting"; |
| 1453 | } |
| 1454 | if( fossil_strcmp(zTopic,"options")==0 ){ |
| 1455 | z = zOptions; |
| 1456 | pCmd = 0; |
| 1457 | }else{ |
| 1458 | rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); |
| 1459 | if( rc ){ |
| 1460 | int i, n; |
| 1461 | const char *az[5]; |
| 1462 | if( rc==1 ){ |
| 1463 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1464 | }else{ |
| 1465 | fossil_print("ambiguous %s prefix: %s\n", |
| 1466 | zCmdOrPage, g.argv[2]); |
| 1467 | } |
| 1468 | fossil_print("Did you mean one of these TOPICs:\n"); |
| 1469 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1470 | for(i=0; i<n; i++){ |
| 1471 | fossil_print(" * %s\n", az[i]); |
| 1472 | } |
| 1473 | fossil_print("Other commands to try:\n"); |
| 1474 | fossil_print(" fossil search -h PATTERN ;# search all help text\n"); |
| 1475 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 1476 | fossil_print(" fossil help -w ;# show all web-pages\n"); |
| 1477 | fossil_print(" fossil help -s ;# show all settings\n"); |
| 1478 | fossil_print(" fossil help -o ;# show global options\n"); |
| 1479 | return; |
| 1480 | } |
| 1481 | z = pCmd->zHelp; |
| 1482 | if( z==0 ){ |
| 1483 | fossil_fatal("no help available for the %s %s", |
| 1484 | pCmd->zName, zCmdOrPage); |
| 1485 | } |
| 1486 | } |
| 1487 | blob_init(&subtext1, 0, 0); |
| 1488 | blob_init(&subtext2, 0, 0); |
| 1489 | if( zSubtopic!=0 ){ |
| 1490 | if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){ |
| 1491 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1079,11 +1079,11 @@ | |
| 1079 | const char *z, /* Full original help text */ |
| 1080 | Blob *pOut, /* Write simplified help text here */ |
| 1081 | const char *zTopic, /* TOPIC */ |
| 1082 | const char *zSubtopic /* SUBTOPIC */ |
| 1083 | ){ |
| 1084 | Blob in, line; //, subsection; |
| 1085 | int n = 0; |
| 1086 | char *zQTop = re_quote(zTopic); |
| 1087 | char *zQSub = re_quote(zSubtopic); |
| 1088 | char *zPattern = mprintf("> fossil %s .*\\b%s\\b", zQTop, zQSub); |
| 1089 | ReCompiled *pRe = 0; |
| @@ -1107,64 +1107,10 @@ | |
| 1107 | blob_reset(&line); |
| 1108 | re_free(pRe); |
| 1109 | if( n ){ |
| 1110 | blob_trim(pOut); |
| 1111 | blob_reset(&in); |
| 1112 | } |
| 1113 | return n; |
| 1114 | } |
| 1115 | |
| 1116 | /* |
| @@ -1285,21 +1231,156 @@ | |
| 1231 | @ --systemtrace Trace calls to system() |
| 1232 | @ -U|--user USER Make the default user be USER |
| 1233 | @ --utc Display times using UTC |
| 1234 | @ --vfs NAME Cause SQLite to use the NAME VFS |
| 1235 | ; |
| 1236 | |
| 1237 | /* |
| 1238 | ** COMMAND: options |
| 1239 | ** |
| 1240 | ** Usage: %fossil options [COMMAND] [SUBCOMMAND] |
| 1241 | ** |
| 1242 | ** Show available command-line options |
| 1243 | ** |
| 1244 | ** fossil options Show command-line options available |
| 1245 | ** on all commands. |
| 1246 | ** |
| 1247 | ** fossil options COMMAND Show options available on COMMAND |
| 1248 | ** |
| 1249 | ** fossil options COMMAND SUBCMD Show options specific to SUBCMD |
| 1250 | ** |
| 1251 | ** See also: [[help]], [[usage]] |
| 1252 | */ |
| 1253 | void options_cmd(void){ |
| 1254 | Blob s1, s2, txt, subsection, out, line; |
| 1255 | const char *z; |
| 1256 | ReCompiled *pRe = 0; |
| 1257 | |
| 1258 | verify_all_options(); |
| 1259 | if( g.argc>4 ){ |
| 1260 | usage("[COMMAND] [SUBCOMMAND]"); |
| 1261 | } |
| 1262 | blob_init(&s1, 0, 0); |
| 1263 | if( g.argc==2 ){ |
| 1264 | fossil_print("%s", zOptions); |
| 1265 | return; |
| 1266 | }else{ |
| 1267 | int rc; |
| 1268 | const char *zTopic = g.argv[2]; |
| 1269 | const char *zSubtopic = g.argc==4 ? g.argv[3] : 0; |
| 1270 | const CmdOrPage *pCmd = 0; |
| 1271 | rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 1272 | if( rc ){ |
| 1273 | if( rc==1 ){ |
| 1274 | fossil_print("unknown command: %s\n", zTopic); |
| 1275 | }else{ |
| 1276 | fossil_print("ambiguous command prefix: %s\n", zTopic); |
| 1277 | } |
| 1278 | return; |
| 1279 | } |
| 1280 | z = pCmd->zHelp; |
| 1281 | if( z==0 ){ |
| 1282 | fossil_fatal("no help available for the %s", pCmd->zName); |
| 1283 | } |
| 1284 | if( zSubtopic ){ |
| 1285 | if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic) ){ |
| 1286 | z = blob_str(&s1); |
| 1287 | }else{ |
| 1288 | fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | blob_init(&txt, z, -1); |
| 1293 | blob_init(&subsection, 0, 0); |
| 1294 | blob_init(&s2, 0, 0); |
| 1295 | re_compile(&pRe, "^ +-.* ", 0); |
| 1296 | while( blob_line(&txt, &line) ){ |
| 1297 | size_t len = blob_strlen(&line); |
| 1298 | if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ |
| 1299 | if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ |
| 1300 | blob_appendb(&s2, &subsection); |
| 1301 | blob_reset(&subsection); |
| 1302 | } |
| 1303 | blob_appendb(&s2, &line); |
| 1304 | }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ |
| 1305 | subsection = line; |
| 1306 | } |
| 1307 | } |
| 1308 | re_free(pRe); |
| 1309 | blob_init(&out, 0, 0); |
| 1310 | blob_trim(&s2); |
| 1311 | help_to_text(blob_str(&s2), &out); |
| 1312 | fossil_print("%s\n", blob_str(&out)); |
| 1313 | blob_reset(&out); |
| 1314 | blob_reset(&s1); |
| 1315 | blob_reset(&s2); |
| 1316 | blob_reset(&line); |
| 1317 | blob_reset(&txt); |
| 1318 | blob_reset(&subsection); |
| 1319 | } |
| 1320 | |
| 1321 | /* |
| 1322 | ** COMMAND: usage |
| 1323 | ** |
| 1324 | ** Usage: %fossil usage COMMAND [SUBCOMMAND] |
| 1325 | ** |
| 1326 | ** Show succinct usage instructions for a Fossil command. |
| 1327 | ** |
| 1328 | ** See also: [[help]], [[options]] |
| 1329 | */ |
| 1330 | void usage_cmd(void){ |
| 1331 | int rc; |
| 1332 | const char *zTopic; |
| 1333 | const char *zSubtopic; |
| 1334 | const CmdOrPage *pCmd = 0; |
| 1335 | Blob s1, s2, out; |
| 1336 | const char *z; |
| 1337 | |
| 1338 | verify_all_options(); |
| 1339 | if( g.argc<3 || g.argc>4 ){ |
| 1340 | usage("COMMAND [SUBCOMMAND]"); |
| 1341 | } |
| 1342 | zTopic = g.argv[2]; |
| 1343 | zSubtopic = g.argc==4 ? g.argv[3] : 0; |
| 1344 | rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 1345 | if( rc ){ |
| 1346 | int i, n; |
| 1347 | const char *az[5]; |
| 1348 | if( rc==1 ){ |
| 1349 | fossil_print("unknown command: %s\n", zTopic); |
| 1350 | }else{ |
| 1351 | fossil_print("ambiguous command prefix: %s\n", zTopic); |
| 1352 | } |
| 1353 | fossil_print("Did you mean one of these TOPICs:\n"); |
| 1354 | n = dispatch_approx_match(zTopic, 5, az); |
| 1355 | for(i=0; i<n; i++){ |
| 1356 | fossil_print(" * %s\n", az[i]); |
| 1357 | } |
| 1358 | return; |
| 1359 | } |
| 1360 | z = pCmd->zHelp; |
| 1361 | if( z==0 ){ |
| 1362 | fossil_fatal("no help available for the %s", pCmd->zName); |
| 1363 | } |
| 1364 | blob_init(&s1, 0, 0); |
| 1365 | blob_init(&s2, 0, 0); |
| 1366 | if( zSubtopic!=0 ){ |
| 1367 | if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic) ){ |
| 1368 | z = blob_str(&s1); |
| 1369 | }else{ |
| 1370 | fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); |
| 1371 | } |
| 1372 | } |
| 1373 | if( simplify_to_usage(z, &s2, zTopic) ){ |
| 1374 | z = blob_str(&s2); |
| 1375 | } |
| 1376 | blob_init(&out, 0, 0); |
| 1377 | help_to_text(z, &out); |
| 1378 | fossil_print("%s\n", blob_str(&out)); |
| 1379 | blob_reset(&out); |
| 1380 | blob_reset(&s1); |
| 1381 | blob_reset(&s2); |
| 1382 | } |
| 1383 | |
| 1384 | #if 0 |
| 1385 | /* |
| 1386 | ** off-COMMAND: apropos |
| @@ -1324,19 +1405,17 @@ | |
| 1405 | #endif |
| 1406 | |
| 1407 | /* |
| 1408 | ** COMMAND: help |
| 1409 | ** |
| 1410 | ** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] |
| 1411 | ** |
| 1412 | ** Display information on how to use TOPIC, which may be a command, webpage, or |
| 1413 | ** setting. Webpage names begin with "/". If TOPIC is omitted, a list of |
| 1414 | ** topics is returned. If there is an extra argument after TOPIC, it is |
| 1415 | ** the name of a subcommand, in which case only the help text for that one |
| 1416 | ** subcommand is shown. |
| 1417 | ** |
| 1418 | ** The following options can be used when TOPIC is omitted: |
| 1419 | ** |
| 1420 | ** -a|--all List both common and auxiliary commands |
| 1421 | ** -e|--everything List all help on all topics |
| @@ -1354,10 +1433,12 @@ | |
| 1433 | ** |
| 1434 | ** -c|--commands Restrict TOPIC search to commands |
| 1435 | ** -h|--html Format output as HTML rather than plain text |
| 1436 | ** --raw Output raw, unformatted help text |
| 1437 | ** -u|--usage Show a succinct usage summary, not full help text |
| 1438 | ** |
| 1439 | ** See also: [[usage]], [[options]], [[search]] with the -h option |
| 1440 | */ |
| 1441 | void help_cmd(void){ |
| 1442 | int rc; |
| 1443 | int mask = CMDFLAG_ANY; /* Mask of help topic types */ |
| 1444 | int isPage = 0; /* True if TOPIC is a page */ |
| @@ -1377,14 +1458,10 @@ | |
| 1458 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1459 | commandsFlag = find_option("commands","c",0)!=0; |
| 1460 | useHtml = find_option("html","h",0)!=0; |
| 1461 | bRaw = find_option("raw",0,0)!=0; |
| 1462 | if( find_option("usage","u",0)!=0 ) bUsage = 1; |
| 1463 | else if( find_option("all","a",0) ){ |
| 1464 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1465 | return; |
| 1466 | } |
| 1467 | else if( find_option("www","w",0) ){ |
| @@ -1449,42 +1526,37 @@ | |
| 1526 | mask = CMDFLAG_COMMAND; |
| 1527 | zCmdOrPage = "command"; |
| 1528 | }else{ |
| 1529 | zCmdOrPage = "command or setting"; |
| 1530 | } |
| 1531 | rc = dispatch_name_search(g.argv[2], mask|CMDFLAG_PREFIX, &pCmd); |
| 1532 | if( rc ){ |
| 1533 | int i, n; |
| 1534 | const char *az[5]; |
| 1535 | if( rc==1 ){ |
| 1536 | fossil_print("unknown %s: %s\n", zCmdOrPage, g.argv[2]); |
| 1537 | }else{ |
| 1538 | fossil_print("ambiguous %s prefix: %s\n", |
| 1539 | zCmdOrPage, g.argv[2]); |
| 1540 | } |
| 1541 | fossil_print("Did you mean one of these TOPICs:\n"); |
| 1542 | n = dispatch_approx_match(g.argv[2], 5, az); |
| 1543 | for(i=0; i<n; i++){ |
| 1544 | fossil_print(" * %s\n", az[i]); |
| 1545 | } |
| 1546 | fossil_print("Other commands to try:\n"); |
| 1547 | fossil_print(" fossil search -h PATTERN ;# search all help text\n"); |
| 1548 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 1549 | fossil_print(" fossil help -w ;# show all web-pages\n"); |
| 1550 | fossil_print(" fossil help -s ;# show all settings\n"); |
| 1551 | fossil_print(" fossil help -o ;# show global options\n"); |
| 1552 | return; |
| 1553 | } |
| 1554 | z = pCmd->zHelp; |
| 1555 | if( z==0 ){ |
| 1556 | fossil_fatal("no help available for the %s %s", |
| 1557 | pCmd->zName, zCmdOrPage); |
| 1558 | } |
| 1559 | blob_init(&subtext1, 0, 0); |
| 1560 | blob_init(&subtext2, 0, 0); |
| 1561 | if( zSubtopic!=0 ){ |
| 1562 | if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){ |
| 1563 |