Fossil SCM

Make "fossil help --options" work the same as "fossil options".

drh 2025-03-01 11:14 trunk
Commit 692a28394e25f9b36295d06aad1c9f7e13cad935d8d670ac353c0321a3291c68
1 file changed +53 -49
+53 -49
--- src/dispatch.c
+++ src/dispatch.c
@@ -1143,10 +1143,45 @@
11431143
}
11441144
re_free(pRe);
11451145
if( n ) blob_trim(pOut);
11461146
return n;
11471147
}
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
+
11481183
11491184
static void multi_column_list(const char **azWord, int nWord){
11501185
int i, j, len;
11511186
int mxLen = 0;
11521187
int nCol;
@@ -1249,13 +1284,12 @@
12491284
** fossil options COMMAND SUBCMD Show options specific to SUBCMD
12501285
**
12511286
** See also: [[help]], [[usage]]
12521287
*/
12531288
void options_cmd(void){
1254
- Blob s1, s2, txt, subsection, out, line;
1289
+ Blob s1, s2, out;
12551290
const char *z;
1256
- ReCompiled *pRe = 0;
12571291
12581292
verify_all_options();
12591293
if( g.argc>4 ){
12601294
usage("[COMMAND] [SUBCOMMAND]");
12611295
}
@@ -1287,37 +1321,18 @@
12871321
}else{
12881322
fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic);
12891323
}
12901324
}
12911325
}
1292
- blob_init(&txt, z, -1);
1293
- blob_init(&subsection, 0, 0);
12941326
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);
13091328
blob_init(&out, 0, 0);
1310
- blob_trim(&s2);
13111329
help_to_text(blob_str(&s2), &out);
13121330
fossil_print("%s\n", blob_str(&out));
13131331
blob_reset(&out);
13141332
blob_reset(&s1);
13151333
blob_reset(&s2);
1316
- blob_reset(&line);
1317
- blob_reset(&txt);
1318
- blob_reset(&subsection);
13191334
}
13201335
13211336
/*
13221337
** COMMAND: usage
13231338
**
@@ -1379,33 +1394,10 @@
13791394
blob_reset(&out);
13801395
blob_reset(&s1);
13811396
blob_reset(&s2);
13821397
}
13831398
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
-
14071399
/*
14081400
** COMMAND: help
14091401
**
14101402
** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND]
14111403
**
@@ -1431,10 +1423,11 @@
14311423
**
14321424
** These options can be used when TOPIC is present:
14331425
**
14341426
** -c|--commands Restrict TOPIC search to commands
14351427
** -h|--html Format output as HTML rather than plain text
1428
+** -o|--options Show command-line options for TOPIC
14361429
** --raw Output raw, unformatted help text
14371430
** -u|--usage Show a succinct usage summary, not full help text
14381431
**
14391432
** See also: [[usage]], [[options]], [[search]] with the -h option
14401433
*/
@@ -1446,23 +1439,25 @@
14461439
int commandsFlag = 0; /* -c option */
14471440
const char *z; /* Original, untranslated help text */
14481441
const char *zCmdOrPage; /* "command" or "page" or "setting" */
14491442
const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */
14501443
int useHtml = 0; /* -h option */
1451
- int bUsage = g.zCmdName[0]=='u'; /* --usage or "fossil usage TOPIC" */
1444
+ int bUsage; /* --usage */
14521445
int bRaw; /* --raw option */
1446
+ int bOptions; /* --options */
14531447
const char *zTopic; /* TOPIC argument */
14541448
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 */
14561450
Blob txt; /* Text after rendering */
14571451
14581452
verboseFlag = find_option("verbose","v",0)!=0;
14591453
commandsFlag = find_option("commands","c",0)!=0;
14601454
useHtml = find_option("html","h",0)!=0;
14611455
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) ){
14641459
command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml);
14651460
return;
14661461
}
14671462
else if( find_option("www","w",0) ){
14681463
command_list(CMDFLAG_WEBPAGE, verboseFlag, useHtml);
@@ -1501,10 +1496,14 @@
15011496
CMDFLAG_SETTING | CMDFLAG_TEST, useHtml, 0);
15021497
return;
15031498
}
15041499
verify_all_options();
15051500
if( g.argc<3 ){
1501
+ if( bOptions ){
1502
+ fossil_print("%s", zOptions);
1503
+ return;
1504
+ }
15061505
z = g.argv[0];
15071506
fossil_print(
15081507
"Usage: %s help TOPIC\n"
15091508
"Things to try:\n\n"
15101509
" %s help help\n"
@@ -1556,10 +1555,11 @@
15561555
fossil_fatal("no help available for the %s %s",
15571556
pCmd->zName, zCmdOrPage);
15581557
}
15591558
blob_init(&subtext1, 0, 0);
15601559
blob_init(&subtext2, 0, 0);
1560
+ blob_init(&s3, 0, 0);
15611561
if( zSubtopic!=0 ){
15621562
if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){
15631563
z = blob_str(&subtext1);
15641564
}else{
15651565
fossil_print("No subtopic \"%s\" for \"%s\".\n", zTopic, zSubtopic);
@@ -1569,10 +1569,14 @@
15691569
}
15701570
}
15711571
if( bUsage && simplify_to_usage(z, &subtext2, zTopic) ){
15721572
z = blob_str(&subtext2);
15731573
}
1574
+ if( bOptions ){
1575
+ simplify_to_options(z, &s3);
1576
+ z = blob_str(&s3);
1577
+ }
15741578
if( pCmd && pCmd->eCmdFlags & CMDFLAG_SETTING ){
15751579
const Setting *pSetting = db_find_setting(pCmd->zName, 0);
15761580
char *zDflt = 0;
15771581
if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){
15781582
zDflt = mprintf(" (default: %s)", pSetting->def);
15791583
--- 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

Keyboard Shortcuts

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