Fossil SCM
Make "fossil help --options" work the same as "fossil options".
Commit
692a28394e25f9b36295d06aad1c9f7e13cad935d8d670ac353c0321a3291c68
Parent
aff179d89f9bee7…
1 file changed
+53
-49
+53
-49
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -1143,10 +1143,45 @@ | ||
| 1143 | 1143 | } |
| 1144 | 1144 | re_free(pRe); |
| 1145 | 1145 | if( n ) blob_trim(pOut); |
| 1146 | 1146 | return n; |
| 1147 | 1147 | } |
| 1148 | + | |
| 1149 | +/* | |
| 1150 | +** Input z[] is help text. Write into pOut all lines of z[] that show | |
| 1151 | +** command-line options. Return the number of lines written. | |
| 1152 | +*/ | |
| 1153 | +static int simplify_to_options( | |
| 1154 | + const char *z, /* Full original help text */ | |
| 1155 | + Blob *pOut /* Write simplified help text here */ | |
| 1156 | +){ | |
| 1157 | + ReCompiled *pRe = 0; | |
| 1158 | + Blob txt, line, subsection; | |
| 1159 | + int n = 0; | |
| 1160 | + | |
| 1161 | + blob_init(&txt, z, -1); | |
| 1162 | + blob_init(&subsection, 0, 0); | |
| 1163 | + re_compile(&pRe, "^ +-.* ", 0); | |
| 1164 | + while( blob_line(&txt, &line) ){ | |
| 1165 | + size_t len = blob_strlen(&line); | |
| 1166 | + if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ | |
| 1167 | + if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ | |
| 1168 | + blob_appendb(pOut, &subsection); | |
| 1169 | + blob_reset(&subsection); | |
| 1170 | + } | |
| 1171 | + blob_appendb(pOut, &line); | |
| 1172 | + }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ | |
| 1173 | + subsection = line; | |
| 1174 | + } | |
| 1175 | + } | |
| 1176 | + re_free(pRe); | |
| 1177 | + blob_trim(pOut); | |
| 1178 | + blob_reset(&subsection); | |
| 1179 | + return n; | |
| 1180 | +} | |
| 1181 | + | |
| 1182 | + | |
| 1148 | 1183 | |
| 1149 | 1184 | static void multi_column_list(const char **azWord, int nWord){ |
| 1150 | 1185 | int i, j, len; |
| 1151 | 1186 | int mxLen = 0; |
| 1152 | 1187 | int nCol; |
| @@ -1249,13 +1284,12 @@ | ||
| 1249 | 1284 | ** fossil options COMMAND SUBCMD Show options specific to SUBCMD |
| 1250 | 1285 | ** |
| 1251 | 1286 | ** See also: [[help]], [[usage]] |
| 1252 | 1287 | */ |
| 1253 | 1288 | void options_cmd(void){ |
| 1254 | - Blob s1, s2, txt, subsection, out, line; | |
| 1289 | + Blob s1, s2, out; | |
| 1255 | 1290 | const char *z; |
| 1256 | - ReCompiled *pRe = 0; | |
| 1257 | 1291 | |
| 1258 | 1292 | verify_all_options(); |
| 1259 | 1293 | if( g.argc>4 ){ |
| 1260 | 1294 | usage("[COMMAND] [SUBCOMMAND]"); |
| 1261 | 1295 | } |
| @@ -1287,37 +1321,18 @@ | ||
| 1287 | 1321 | }else{ |
| 1288 | 1322 | fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); |
| 1289 | 1323 | } |
| 1290 | 1324 | } |
| 1291 | 1325 | } |
| 1292 | - blob_init(&txt, z, -1); | |
| 1293 | - blob_init(&subsection, 0, 0); | |
| 1294 | 1326 | 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); | |
| 1327 | + simplify_to_options(z, &s2); | |
| 1309 | 1328 | blob_init(&out, 0, 0); |
| 1310 | - blob_trim(&s2); | |
| 1311 | 1329 | help_to_text(blob_str(&s2), &out); |
| 1312 | 1330 | fossil_print("%s\n", blob_str(&out)); |
| 1313 | 1331 | blob_reset(&out); |
| 1314 | 1332 | blob_reset(&s1); |
| 1315 | 1333 | blob_reset(&s2); |
| 1316 | - blob_reset(&line); | |
| 1317 | - blob_reset(&txt); | |
| 1318 | - blob_reset(&subsection); | |
| 1319 | 1334 | } |
| 1320 | 1335 | |
| 1321 | 1336 | /* |
| 1322 | 1337 | ** COMMAND: usage |
| 1323 | 1338 | ** |
| @@ -1379,33 +1394,10 @@ | ||
| 1379 | 1394 | blob_reset(&out); |
| 1380 | 1395 | blob_reset(&s1); |
| 1381 | 1396 | blob_reset(&s2); |
| 1382 | 1397 | } |
| 1383 | 1398 | |
| 1384 | -#if 0 | |
| 1385 | -/* | |
| 1386 | -** off-COMMAND: apropos | |
| 1387 | -** | |
| 1388 | -** Usage: %fossil apropos KEYWORD ... | |
| 1389 | -** | |
| 1390 | -** Search the built-in help pages for Fossil for topics that | |
| 1391 | -** match the KEYWORD(s) | |
| 1392 | -*/ | |
| 1393 | -void usage_apropos(void){ | |
| 1394 | - char **azNewArgv = fossil_malloc( (g.argc+2)*sizeof(char*) ); | |
| 1395 | - memcpy(azNewArgv, g.argv, g.argc); | |
| 1396 | - azNewArgv[0] = g.argv[0]; | |
| 1397 | - azNewArgv[1] = "apropos"; | |
| 1398 | - azNewArgv[2] = "-h"; | |
| 1399 | - memcpy(&azNewArgv[3], &g.argv[2], (g.argc-2) * sizeof(char*)); | |
| 1400 | - g.argc++; | |
| 1401 | - azNewArgv[g.argc] = 0; | |
| 1402 | - g.argv = azNewArgv; | |
| 1403 | - search_cmd(); | |
| 1404 | -} | |
| 1405 | -#endif | |
| 1406 | - | |
| 1407 | 1399 | /* |
| 1408 | 1400 | ** COMMAND: help |
| 1409 | 1401 | ** |
| 1410 | 1402 | ** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] |
| 1411 | 1403 | ** |
| @@ -1431,10 +1423,11 @@ | ||
| 1431 | 1423 | ** |
| 1432 | 1424 | ** These options can be used when TOPIC is present: |
| 1433 | 1425 | ** |
| 1434 | 1426 | ** -c|--commands Restrict TOPIC search to commands |
| 1435 | 1427 | ** -h|--html Format output as HTML rather than plain text |
| 1428 | +** -o|--options Show command-line options for TOPIC | |
| 1436 | 1429 | ** --raw Output raw, unformatted help text |
| 1437 | 1430 | ** -u|--usage Show a succinct usage summary, not full help text |
| 1438 | 1431 | ** |
| 1439 | 1432 | ** See also: [[usage]], [[options]], [[search]] with the -h option |
| 1440 | 1433 | */ |
| @@ -1446,23 +1439,25 @@ | ||
| 1446 | 1439 | int commandsFlag = 0; /* -c option */ |
| 1447 | 1440 | const char *z; /* Original, untranslated help text */ |
| 1448 | 1441 | const char *zCmdOrPage; /* "command" or "page" or "setting" */ |
| 1449 | 1442 | const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */ |
| 1450 | 1443 | int useHtml = 0; /* -h option */ |
| 1451 | - int bUsage = g.zCmdName[0]=='u'; /* --usage or "fossil usage TOPIC" */ | |
| 1444 | + int bUsage; /* --usage */ | |
| 1452 | 1445 | int bRaw; /* --raw option */ |
| 1446 | + int bOptions; /* --options */ | |
| 1453 | 1447 | const char *zTopic; /* TOPIC argument */ |
| 1454 | 1448 | const char *zSubtopic = 0; /* SUBTOPIC argument */ |
| 1455 | - Blob subtext1, subtext2; /* Subsets of z[] containing subtopic/usage */ | |
| 1449 | + Blob subtext1, subtext2, s3; /* Subsets of z[] containing subtopic/usage */ | |
| 1456 | 1450 | Blob txt; /* Text after rendering */ |
| 1457 | 1451 | |
| 1458 | 1452 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1459 | 1453 | commandsFlag = find_option("commands","c",0)!=0; |
| 1460 | 1454 | useHtml = find_option("html","h",0)!=0; |
| 1461 | 1455 | 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) ){ | |
| 1456 | + bOptions = find_option("options","o",0)!=0; | |
| 1457 | + bUsage = find_option("usage","u",0)!=0; | |
| 1458 | + if( find_option("all","a",0) ){ | |
| 1464 | 1459 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1465 | 1460 | return; |
| 1466 | 1461 | } |
| 1467 | 1462 | else if( find_option("www","w",0) ){ |
| 1468 | 1463 | command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
| @@ -1501,10 +1496,14 @@ | ||
| 1501 | 1496 | CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0); |
| 1502 | 1497 | return; |
| 1503 | 1498 | } |
| 1504 | 1499 | verify_all_options(); |
| 1505 | 1500 | if( g.argc<3 ){ |
| 1501 | + if( bOptions ){ | |
| 1502 | + fossil_print("%s", zOptions); | |
| 1503 | + return; | |
| 1504 | + } | |
| 1506 | 1505 | z = g.argv[0]; |
| 1507 | 1506 | fossil_print( |
| 1508 | 1507 | "Usage: %s help TOPIC\n" |
| 1509 | 1508 | "Things to try:\n\n" |
| 1510 | 1509 | " %s help help\n" |
| @@ -1556,10 +1555,11 @@ | ||
| 1556 | 1555 | fossil_fatal("no help available for the %s %s", |
| 1557 | 1556 | pCmd->zName, zCmdOrPage); |
| 1558 | 1557 | } |
| 1559 | 1558 | blob_init(&subtext1, 0, 0); |
| 1560 | 1559 | blob_init(&subtext2, 0, 0); |
| 1560 | + blob_init(&s3, 0, 0); | |
| 1561 | 1561 | if( zSubtopic!=0 ){ |
| 1562 | 1562 | if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){ |
| 1563 | 1563 | z = blob_str(&subtext1); |
| 1564 | 1564 | }else{ |
| 1565 | 1565 | fossil_print("No subtopic \"%s\" for \"%s\".\n", zTopic, zSubtopic); |
| @@ -1569,10 +1569,14 @@ | ||
| 1569 | 1569 | } |
| 1570 | 1570 | } |
| 1571 | 1571 | if( bUsage && simplify_to_usage(z, &subtext2, zTopic) ){ |
| 1572 | 1572 | z = blob_str(&subtext2); |
| 1573 | 1573 | } |
| 1574 | + if( bOptions ){ | |
| 1575 | + simplify_to_options(z, &s3); | |
| 1576 | + z = blob_str(&s3); | |
| 1577 | + } | |
| 1574 | 1578 | if( pCmd && pCmd->eCmdFlags & CMDFLAG_SETTING ){ |
| 1575 | 1579 | const Setting *pSetting = db_find_setting(pCmd->zName, 0); |
| 1576 | 1580 | char *zDflt = 0; |
| 1577 | 1581 | if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){ |
| 1578 | 1582 | zDflt = mprintf(" (default: %s)", pSetting->def); |
| 1579 | 1583 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1143,10 +1143,45 @@ | |
| 1143 | } |
| 1144 | re_free(pRe); |
| 1145 | if( n ) blob_trim(pOut); |
| 1146 | return n; |
| 1147 | } |
| 1148 | |
| 1149 | static void multi_column_list(const char **azWord, int nWord){ |
| 1150 | int i, j, len; |
| 1151 | int mxLen = 0; |
| 1152 | int nCol; |
| @@ -1249,13 +1284,12 @@ | |
| 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 | } |
| @@ -1287,37 +1321,18 @@ | |
| 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 | ** |
| @@ -1379,33 +1394,10 @@ | |
| 1379 | blob_reset(&out); |
| 1380 | blob_reset(&s1); |
| 1381 | blob_reset(&s2); |
| 1382 | } |
| 1383 | |
| 1384 | #if 0 |
| 1385 | /* |
| 1386 | ** off-COMMAND: apropos |
| 1387 | ** |
| 1388 | ** Usage: %fossil apropos KEYWORD ... |
| 1389 | ** |
| 1390 | ** Search the built-in help pages for Fossil for topics that |
| 1391 | ** match the KEYWORD(s) |
| 1392 | */ |
| 1393 | void usage_apropos(void){ |
| 1394 | char **azNewArgv = fossil_malloc( (g.argc+2)*sizeof(char*) ); |
| 1395 | memcpy(azNewArgv, g.argv, g.argc); |
| 1396 | azNewArgv[0] = g.argv[0]; |
| 1397 | azNewArgv[1] = "apropos"; |
| 1398 | azNewArgv[2] = "-h"; |
| 1399 | memcpy(&azNewArgv[3], &g.argv[2], (g.argc-2) * sizeof(char*)); |
| 1400 | g.argc++; |
| 1401 | azNewArgv[g.argc] = 0; |
| 1402 | g.argv = azNewArgv; |
| 1403 | search_cmd(); |
| 1404 | } |
| 1405 | #endif |
| 1406 | |
| 1407 | /* |
| 1408 | ** COMMAND: help |
| 1409 | ** |
| 1410 | ** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] |
| 1411 | ** |
| @@ -1431,10 +1423,11 @@ | |
| 1431 | ** |
| 1432 | ** These options can be used when TOPIC is present: |
| 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 | */ |
| @@ -1446,23 +1439,25 @@ | |
| 1446 | int commandsFlag = 0; /* -c option */ |
| 1447 | const char *z; /* Original, untranslated help text */ |
| 1448 | const char *zCmdOrPage; /* "command" or "page" or "setting" */ |
| 1449 | const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */ |
| 1450 | int useHtml = 0; /* -h option */ |
| 1451 | int bUsage = g.zCmdName[0]=='u'; /* --usage or "fossil usage TOPIC" */ |
| 1452 | int bRaw; /* --raw option */ |
| 1453 | const char *zTopic; /* TOPIC argument */ |
| 1454 | const char *zSubtopic = 0; /* SUBTOPIC argument */ |
| 1455 | Blob subtext1, subtext2; /* Subsets of z[] containing subtopic/usage */ |
| 1456 | Blob txt; /* Text after rendering */ |
| 1457 | |
| 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) ){ |
| 1468 | command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
| @@ -1501,10 +1496,14 @@ | |
| 1501 | CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0); |
| 1502 | return; |
| 1503 | } |
| 1504 | verify_all_options(); |
| 1505 | if( g.argc<3 ){ |
| 1506 | z = g.argv[0]; |
| 1507 | fossil_print( |
| 1508 | "Usage: %s help TOPIC\n" |
| 1509 | "Things to try:\n\n" |
| 1510 | " %s help help\n" |
| @@ -1556,10 +1555,11 @@ | |
| 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 | z = blob_str(&subtext1); |
| 1564 | }else{ |
| 1565 | fossil_print("No subtopic \"%s\" for \"%s\".\n", zTopic, zSubtopic); |
| @@ -1569,10 +1569,14 @@ | |
| 1569 | } |
| 1570 | } |
| 1571 | if( bUsage && simplify_to_usage(z, &subtext2, zTopic) ){ |
| 1572 | z = blob_str(&subtext2); |
| 1573 | } |
| 1574 | if( pCmd && pCmd->eCmdFlags & CMDFLAG_SETTING ){ |
| 1575 | const Setting *pSetting = db_find_setting(pCmd->zName, 0); |
| 1576 | char *zDflt = 0; |
| 1577 | if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){ |
| 1578 | zDflt = mprintf(" (default: %s)", pSetting->def); |
| 1579 |
| --- src/dispatch.c | |
| +++ src/dispatch.c | |
| @@ -1143,10 +1143,45 @@ | |
| 1143 | } |
| 1144 | re_free(pRe); |
| 1145 | if( n ) blob_trim(pOut); |
| 1146 | return n; |
| 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | ** Input z[] is help text. Write into pOut all lines of z[] that show |
| 1151 | ** command-line options. Return the number of lines written. |
| 1152 | */ |
| 1153 | static int simplify_to_options( |
| 1154 | const char *z, /* Full original help text */ |
| 1155 | Blob *pOut /* Write simplified help text here */ |
| 1156 | ){ |
| 1157 | ReCompiled *pRe = 0; |
| 1158 | Blob txt, line, subsection; |
| 1159 | int n = 0; |
| 1160 | |
| 1161 | blob_init(&txt, z, -1); |
| 1162 | blob_init(&subsection, 0, 0); |
| 1163 | re_compile(&pRe, "^ +-.* ", 0); |
| 1164 | while( blob_line(&txt, &line) ){ |
| 1165 | size_t len = blob_strlen(&line); |
| 1166 | if( re_match(pRe, (unsigned char*)blob_buffer(&line), (int)len) ){ |
| 1167 | if( blob_strlen(&subsection) && blob_buffer(&line)[0]!='>' ){ |
| 1168 | blob_appendb(pOut, &subsection); |
| 1169 | blob_reset(&subsection); |
| 1170 | } |
| 1171 | blob_appendb(pOut, &line); |
| 1172 | }else if( len>9 && strncmp(blob_buffer(&line),"> fossil ",9)==0 ){ |
| 1173 | subsection = line; |
| 1174 | } |
| 1175 | } |
| 1176 | re_free(pRe); |
| 1177 | blob_trim(pOut); |
| 1178 | blob_reset(&subsection); |
| 1179 | return n; |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | static void multi_column_list(const char **azWord, int nWord){ |
| 1185 | int i, j, len; |
| 1186 | int mxLen = 0; |
| 1187 | int nCol; |
| @@ -1249,13 +1284,12 @@ | |
| 1284 | ** fossil options COMMAND SUBCMD Show options specific to SUBCMD |
| 1285 | ** |
| 1286 | ** See also: [[help]], [[usage]] |
| 1287 | */ |
| 1288 | void options_cmd(void){ |
| 1289 | Blob s1, s2, out; |
| 1290 | const char *z; |
| 1291 | |
| 1292 | verify_all_options(); |
| 1293 | if( g.argc>4 ){ |
| 1294 | usage("[COMMAND] [SUBCOMMAND]"); |
| 1295 | } |
| @@ -1287,37 +1321,18 @@ | |
| 1321 | }else{ |
| 1322 | fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic); |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | blob_init(&s2, 0, 0); |
| 1327 | simplify_to_options(z, &s2); |
| 1328 | blob_init(&out, 0, 0); |
| 1329 | help_to_text(blob_str(&s2), &out); |
| 1330 | fossil_print("%s\n", blob_str(&out)); |
| 1331 | blob_reset(&out); |
| 1332 | blob_reset(&s1); |
| 1333 | blob_reset(&s2); |
| 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | ** COMMAND: usage |
| 1338 | ** |
| @@ -1379,33 +1394,10 @@ | |
| 1394 | blob_reset(&out); |
| 1395 | blob_reset(&s1); |
| 1396 | blob_reset(&s2); |
| 1397 | } |
| 1398 | |
| 1399 | /* |
| 1400 | ** COMMAND: help |
| 1401 | ** |
| 1402 | ** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND] |
| 1403 | ** |
| @@ -1431,10 +1423,11 @@ | |
| 1423 | ** |
| 1424 | ** These options can be used when TOPIC is present: |
| 1425 | ** |
| 1426 | ** -c|--commands Restrict TOPIC search to commands |
| 1427 | ** -h|--html Format output as HTML rather than plain text |
| 1428 | ** -o|--options Show command-line options for TOPIC |
| 1429 | ** --raw Output raw, unformatted help text |
| 1430 | ** -u|--usage Show a succinct usage summary, not full help text |
| 1431 | ** |
| 1432 | ** See also: [[usage]], [[options]], [[search]] with the -h option |
| 1433 | */ |
| @@ -1446,23 +1439,25 @@ | |
| 1439 | int commandsFlag = 0; /* -c option */ |
| 1440 | const char *z; /* Original, untranslated help text */ |
| 1441 | const char *zCmdOrPage; /* "command" or "page" or "setting" */ |
| 1442 | const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */ |
| 1443 | int useHtml = 0; /* -h option */ |
| 1444 | int bUsage; /* --usage */ |
| 1445 | int bRaw; /* --raw option */ |
| 1446 | int bOptions; /* --options */ |
| 1447 | const char *zTopic; /* TOPIC argument */ |
| 1448 | const char *zSubtopic = 0; /* SUBTOPIC argument */ |
| 1449 | Blob subtext1, subtext2, s3; /* Subsets of z[] containing subtopic/usage */ |
| 1450 | Blob txt; /* Text after rendering */ |
| 1451 | |
| 1452 | verboseFlag = find_option("verbose","v",0)!=0; |
| 1453 | commandsFlag = find_option("commands","c",0)!=0; |
| 1454 | useHtml = find_option("html","h",0)!=0; |
| 1455 | bRaw = find_option("raw",0,0)!=0; |
| 1456 | bOptions = find_option("options","o",0)!=0; |
| 1457 | bUsage = find_option("usage","u",0)!=0; |
| 1458 | if( find_option("all","a",0) ){ |
| 1459 | command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml); |
| 1460 | return; |
| 1461 | } |
| 1462 | else if( find_option("www","w",0) ){ |
| 1463 | command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml); |
| @@ -1501,10 +1496,14 @@ | |
| 1496 | CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0); |
| 1497 | return; |
| 1498 | } |
| 1499 | verify_all_options(); |
| 1500 | if( g.argc<3 ){ |
| 1501 | if( bOptions ){ |
| 1502 | fossil_print("%s", zOptions); |
| 1503 | return; |
| 1504 | } |
| 1505 | z = g.argv[0]; |
| 1506 | fossil_print( |
| 1507 | "Usage: %s help TOPIC\n" |
| 1508 | "Things to try:\n\n" |
| 1509 | " %s help help\n" |
| @@ -1556,10 +1555,11 @@ | |
| 1555 | fossil_fatal("no help available for the %s %s", |
| 1556 | pCmd->zName, zCmdOrPage); |
| 1557 | } |
| 1558 | blob_init(&subtext1, 0, 0); |
| 1559 | blob_init(&subtext2, 0, 0); |
| 1560 | blob_init(&s3, 0, 0); |
| 1561 | if( zSubtopic!=0 ){ |
| 1562 | if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){ |
| 1563 | z = blob_str(&subtext1); |
| 1564 | }else{ |
| 1565 | fossil_print("No subtopic \"%s\" for \"%s\".\n", zTopic, zSubtopic); |
| @@ -1569,10 +1569,14 @@ | |
| 1569 | } |
| 1570 | } |
| 1571 | if( bUsage && simplify_to_usage(z, &subtext2, zTopic) ){ |
| 1572 | z = blob_str(&subtext2); |
| 1573 | } |
| 1574 | if( bOptions ){ |
| 1575 | simplify_to_options(z, &s3); |
| 1576 | z = blob_str(&s3); |
| 1577 | } |
| 1578 | if( pCmd && pCmd->eCmdFlags & CMDFLAG_SETTING ){ |
| 1579 | const Setting *pSetting = db_find_setting(pCmd->zName, 0); |
| 1580 | char *zDflt = 0; |
| 1581 | if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){ |
| 1582 | zDflt = mprintf(" (default: %s)", pSetting->def); |
| 1583 |