Fossil

Check-in [b097e6899e]
Login

Check-in [b097e6899e]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove the "fossil usage" and "fossil options" command. Use instead the the --usage/-u or --options/-o options on the "fossil help" command. Other improvements and fixes to the recent "fossil help" enhancement.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b097e6899e6dc0c97dce181dec2e4093789a780c1cff750f233061fb830975aa
User & Date: drh 2025-03-01 20:31:20.147
Context
2025-03-02
18:57
Remove an extraneous call of find_server_repository() in win32 implementation of server/ui, added by [0a473cd5533f5bb2]. The extra call to find_server_repository() unnecessary lock which prevent "fossil close" from deleting the checkout db while a server instance is running. (reported in forum post: [forum:e7f3472c46eae4bd]) ... (check-in: 28436ab9d5 user: mgagnon tags: trunk)
2025-03-01
20:31
Remove the "fossil usage" and "fossil options" command. Use instead the the --usage/-u or --options/-o options on the "fossil help" command. Other improvements and fixes to the recent "fossil help" enhancement. ... (check-in: b097e6899e user: drh tags: trunk)
16:02
Improvements to rendering in the "fossil help" command, especially in combination with the -u/--usage and -o/--options command-line options. ... (check-in: 62cb8ea785 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/dispatch.c.
524
525
526
527
528
529
530

531
532



533
534
535
536
537
538
539

/*
** Format help text for TTY display.
*/
static void help_to_text(const char *zHelp, Blob *pText, int bUsage){
  int i, x;
  char c;

  if( !bUsage && zHelp[0]=='>' ){
    blob_appendf(pText, "Usage:");



    zHelp++;
  }
  for(i=0; (c = zHelp[i])!=0; i++){
    if( c=='%' && strncmp(zHelp+i,"%fossil",7)==0 ){
      if( i>0 ) blob_append(pText, zHelp, i);
      blob_append(pText, "fossil", 6);
      zHelp += i+7;







>
|
|
>
>
>







524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

/*
** Format help text for TTY display.
*/
static void help_to_text(const char *zHelp, Blob *pText, int bUsage){
  int i, x;
  char c;
  if( zHelp[0]=='>' ){
    if( !bUsage ){
      blob_appendf(pText, "Usage:");
    }else{
      blob_append_char(pText, ' ');
    }
    zHelp++;
  }
  for(i=0; (c = zHelp[i])!=0; i++){
    if( c=='%' && strncmp(zHelp+i,"%fossil",7)==0 ){
      if( i>0 ) blob_append(pText, zHelp, i);
      blob_append(pText, "fossil", 6);
      zHelp += i+7;
1064
1065
1066
1067
1068
1069
1070


1071



1072
1073
1074
1075
1076
1077



1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
  }
  @ </dl>
  blob_reset(&buf);
  style_finish_page();
}

/*


** Return true if p is the first line paste the end of



** the previous subcommand.
*/
static int is_subcommand_end(Blob *p, int bAbbrevSubcmd, ReCompiled *pRe){
  if( bAbbrevSubcmd ){
    int i;
    if( re_match(pRe, (unsigned char*)blob_buffer(p), blob_strlen(p)) ){



      return 0;
    }

    if( blob_size(p)<4 ) return 1;
    for(i=0; i<4 && blob_buffer(p)[i]==' '; i++){}
    return i<4;
  }else{
    return blob_buffer(p)[0]=='>';
  }
}

/*
** Input z[] is help text for zTopic.  If zTopic has sub-command zSub,
** then cut out all portions of the original help text that do not
** directly pertain to zSub and write the zSub-relevant parts into







>
>
|
>
>
>
|

|
<
|
|
>
>
>
|
|
>
|
<
|

|







1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083

1084
1085
1086
1087
1088
1089
1090
1091
1092

1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
  }
  @ </dl>
  blob_reset(&buf);
  style_finish_page();
}

/*
** Analyze p and return one of three values:
**
**     0     p is the continuation of a prior subcommand.
**
**     1     p is text past the end of a prior subcommand.
**
**     2     p is the start of a new subcommand.
*/
static int is_subcommand(Blob *p, int bAbbrevSubcmd){

  int i, sz;
  const unsigned char *z = (const unsigned char*)blob_buffer(p);
  sz = blob_size(p);
  if( sz>6 ) sz = 6;
  for(i=0; i<sz && fossil_isspace(z[i]); i++){}
  if( i>=sz ) return 0;

  if( bAbbrevSubcmd==0 ){
    if( i>1 ) return 0;

    return z[0]=='>' ? 2 : 1;
  }else{
    return (i==3 && fossil_isalpha(z[3])) ? 2 : 1;
  }
}

/*
** Input z[] is help text for zTopic.  If zTopic has sub-command zSub,
** then cut out all portions of the original help text that do not
** directly pertain to zSub and write the zSub-relevant parts into
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125





1126
1127

1128
1129


1130

1131







1132
1133
1134
1135
1136
1137
1138
  char *zQSub = re_quote(zSubtopic);
  char *zPattern;
  ReCompiled *pRe = 0;

  if( bAbbrevSubcmd ){
    zPattern = mprintf("   ([a-z]+ ?\\| ?)*%s\\b", zQSub);
  }else{
    zPattern = mprintf(">  ?fossil %s .*\\b%s\\b", zQTop, zQSub);
  }
  fossil_free(zQTop);
  fossil_free(zQSub);
  re_compile(&pRe, zPattern, 0);
  fossil_free(zPattern);
  blob_init(&in, z, -1);
  while( blob_line(&in, &line) ){
    if( re_match(pRe, (unsigned char*)blob_buffer(&line), blob_strlen(&line)) ){

      blob_appendb(pOut, &line);
      n++;
      while( blob_line(&in, &line)





          && !is_subcommand_end(&line,bAbbrevSubcmd,pRe)
      ){

        blob_appendb(pOut, &line);
        n++;


      }

      if( !bAbbrevSubcmd ) break;







    }
  }
  blob_reset(&line);
  re_free(pRe);
  if( n ){
    blob_trim(pOut);
    blob_reset(&in);







|







|
>


|
>
>
>
>
>
|
|
>
|
|
>
>
|
>
|
>
>
>
>
>
>
>







1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
  char *zQSub = re_quote(zSubtopic);
  char *zPattern;
  ReCompiled *pRe = 0;

  if( bAbbrevSubcmd ){
    zPattern = mprintf("   ([a-z]+ ?\\| ?)*%s\\b", zQSub);
  }else{
    zPattern = mprintf(">  ?fossil [-a-z]+ .*\\b%s\\b", zQSub);
  }
  fossil_free(zQTop);
  fossil_free(zQSub);
  re_compile(&pRe, zPattern, 0);
  fossil_free(zPattern);
  blob_init(&in, z, -1);
  while( blob_line(&in, &line) ){
    if( re_match(pRe, (unsigned char*)blob_buffer(&line), blob_size(&line)) ){
      int atStart = 1;
      blob_appendb(pOut, &line);
      n++;
      while( blob_line(&in, &line) ){
        if( re_match(pRe,(unsigned char*)blob_buffer(&line),blob_size(&line)) ){
          blob_appendb(pOut, &line);
          n++;
          atStart = 1;
        }else{
          int x = is_subcommand(&line,bAbbrevSubcmd);
          if( x==2 ){
            if( atStart ){
              blob_appendb(pOut, &line);
              n++;
            }else{
              break;
            }
          }else if( x==1 ){
            break;
          }else{
            blob_appendb(pOut, &line);
            n++;
            atStart = 0;
          }
        }
      }
    }
  }
  blob_reset(&line);
  re_free(pRe);
  if( n ){
    blob_trim(pOut);
    blob_reset(&in);
1238
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
        blob_reset(&subsection);
      }
      blob_appendb(pOut, &line);
    }else if( len>7 && !fossil_isspace(zLine[0]) && bSubsectionSeen 
           && sqlite3_strlike("%options:%",blob_str(&line),0)==0 ){
      subsection = line;
    }else if( !bAbbrevSubcmd && len>9
           && (memcmp(zLine,"> fossil ",9)==0 || memcmp(zLine,">  fossil",9)) ){

      subsection = line;
      bSubsectionSeen = 1;
    }else if( bAbbrevSubcmd && len>5 && memcmp(zLine,"   ",3)==0
           && fossil_isalpha(zLine[3]) ){
      subsection = line;
      bSubsectionSeen = 1;
    }else if( len>1 && !fossil_isspace(zLine[0]) && bSubsectionSeen ){







|
>







1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
        blob_reset(&subsection);
      }
      blob_appendb(pOut, &line);
    }else if( len>7 && !fossil_isspace(zLine[0]) && bSubsectionSeen 
           && sqlite3_strlike("%options:%",blob_str(&line),0)==0 ){
      subsection = line;
    }else if( !bAbbrevSubcmd && len>9
           && (memcmp(zLine,"> fossil ",9)==0 
               || memcmp(zLine,">  fossil",9)==0) ){
      subsection = line;
      bSubsectionSeen = 1;
    }else if( bAbbrevSubcmd && len>5 && memcmp(zLine,"   ",3)==0
           && fossil_isalpha(zLine[3]) ){
      subsection = line;
      bSubsectionSeen = 1;
    }else if( len>1 && !fossil_isspace(zLine[0]) && bSubsectionSeen ){
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
@   --ssl-identity NAME     Set the SSL identity to NAME
@   --systemtrace           Trace calls to system()
@   -U|--user USER          Make the default user be USER
@   --utc                   Display times using UTC
@   --vfs NAME              Cause SQLite to use the NAME VFS
;

/*
** COMMAND: options
**
** Usage: %fossil options [COMMAND] [SUBCOMMAND]
**
** Show available command-line options
**
**    fossil options                  Show command-line options available
**                                    on all commands.
**
**    fossil options COMMAND          Show options available on COMMAND
**
**    fossil options COMMAND SUBCMD   Show options specific to SUBCMD
**
** See also: [[help]], [[usage]]
*/
void options_cmd(void){
  Blob s1, s2, out;
  const char *z;
  const char *zTopic;
  int bAbbrevSubcmd = 0;

  verify_all_options();
  if( g.argc>4 ){
    usage("[COMMAND] [SUBCOMMAND]");
  }
  blob_init(&s1, 0, 0);
  if( g.argc==2 ){
    fossil_print("%s", zOptions);
    return;
  }else{
    int rc;
    const char *zSubtopic = g.argc==4 ? g.argv[3] : 0;
    const CmdOrPage *pCmd = 0;
    zTopic = g.argv[2];
    rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd);
    if( rc ){
      if( rc==1 ){
        fossil_print("unknown command: %s\n", zTopic);
      }else{
        fossil_print("ambiguous command prefix: %s\n", zTopic);
      }
      return;
    }
    z = pCmd->zHelp;
    if( z==0 ){
      fossil_fatal("no help available for the %s", pCmd->zName);
    }
    bAbbrevSubcmd = (pCmd->eCmdFlags & CMDFLAG_ABBREVSUBCMD)!=0;
    if( zSubtopic ){
      if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic, bAbbrevSubcmd) ){
        z = blob_str(&s1);
      }else{
        fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic);
      }
    }
  }
  blob_init(&s2, 0, 0);
  simplify_to_options(z, &s2, bAbbrevSubcmd, zTopic);
  blob_init(&out, 0, 0);
  help_to_text(blob_str(&s2), &out, 1);
  fossil_print("%s\n", blob_str(&out));
  blob_reset(&out);
  blob_reset(&s1);
  blob_reset(&s2);
}

/*
** COMMAND: usage
**
** Usage: %fossil usage COMMAND [SUBCOMMAND]
**
** Show succinct usage instructions for a Fossil command.
**
** See also:  [[help]], [[options]]
*/
void usage_cmd(void){
  int rc;
  const char *zTopic;
  const char *zSubtopic;
  const CmdOrPage *pCmd = 0;
  Blob s1, s2, out;
  const char *z;
  int bAbbrevSubcmd = 0;

  verify_all_options();
  if( g.argc<3 || g.argc>4 ){
    usage("COMMAND [SUBCOMMAND]");
  }
  zTopic = g.argv[2];
  zSubtopic = g.argc==4 ? g.argv[3] : 0;
  rc = dispatch_name_search(zTopic, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd);
  if( rc ){
    int i, n;
    const char *az[5];
    if( rc==1 ){
      fossil_print("unknown command: %s\n", zTopic);
    }else{
      fossil_print("ambiguous command prefix: %s\n", zTopic);
    }
    fossil_print("Did you mean one of these TOPICs:\n");
    n = dispatch_approx_match(zTopic, 5, az);
    for(i=0; i<n; i++){
      fossil_print("  *  %s\n", az[i]);
    }
    return;
  }
  bAbbrevSubcmd = (pCmd->eCmdFlags & CMDFLAG_ABBREVSUBCMD)!=0;
  z = pCmd->zHelp;
  if( z==0 ){
    fossil_fatal("no help available for the %s", pCmd->zName);
  }
  blob_init(&s1, 0, 0);
  blob_init(&s2, 0, 0);
  if( zSubtopic!=0 ){
    if( simplify_to_subtopic(z, &s1, zTopic, zSubtopic, bAbbrevSubcmd) ){
      z = blob_str(&s1);
    }else{
      fossil_print("No subcommand \"%s\" for \"%s\".\n", zSubtopic, zTopic);
    }
  }
  if( simplify_to_usage(z, &s2, zTopic, bAbbrevSubcmd) ){
    z = blob_str(&s2);
  }
  blob_init(&out, 0, 0);
  help_to_text(z, &out, 1);
  fossil_print("%s\n", blob_str(&out));
  blob_reset(&out);
  blob_reset(&s1);
  blob_reset(&s2);
}

/*
** COMMAND: help
**
** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND]
**
** Display information on how to use TOPIC, which may be a command, webpage, or
** setting.  Webpage names begin with "/".  If TOPIC is omitted, a list of







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1374
1375
1376
1377
1378
1379
1380




































































































































1381
1382
1383
1384
1385
1386
1387
@   --ssl-identity NAME     Set the SSL identity to NAME
@   --systemtrace           Trace calls to system()
@   -U|--user USER          Make the default user be USER
@   --utc                   Display times using UTC
@   --vfs NAME              Cause SQLite to use the NAME VFS
;





































































































































/*
** COMMAND: help
**
** Usage: %fossil help [OPTIONS] [TOPIC] [SUBCOMMAND]
**
** Display information on how to use TOPIC, which may be a command, webpage, or
** setting.  Webpage names begin with "/".  If TOPIC is omitted, a list of
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
      return;
    }
    z = g.argv[0];
    fossil_print(
      "Usage: %s help TOPIC\n"
      "Things to try:\n\n"
      "   %s help help\n"
      "   %s help options\n"
      "   %s help -a\n"
      "   %s search -h TOPIC\n\n"
      "Other common values for TOPIC:\n\n",
      z, z, z, z, z);
    command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml);
    if( !verboseFlag ) version_cmd();
    return;







|







1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
      return;
    }
    z = g.argv[0];
    fossil_print(
      "Usage: %s help TOPIC\n"
      "Things to try:\n\n"
      "   %s help help\n"
      "   %s help -o\n"
      "   %s help -a\n"
      "   %s search -h TOPIC\n\n"
      "Other common values for TOPIC:\n\n",
      z, z, z, z, z);
    command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml);
    if( !verboseFlag ) version_cmd();
    return;
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655

1656
1657
1658
1659
1660
1661
1662
  blob_init(&subtext1, 0, 0);
  blob_init(&subtext2, 0, 0);
  blob_init(&s3, 0, 0);
  if( zSubtopic!=0 ){
    if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic, bAbbrevSubcmd) ){
      z = blob_str(&subtext1);
    }else{
      fossil_print("No subtopic \"%s\" for \"%s\".\n", zTopic, zSubtopic);
      if( strstr(z, "Usage:")!=0 || strstr(z, "\n>  ?fossil")!=0 ){
        bUsage = 1;
      }

    }
  }
  if( bUsage ){
    if( simplify_to_usage(z, &subtext2, zTopic, bAbbrevSubcmd) ){
      z = blob_str(&subtext2);
    }else{
      bUsage = 0;







|
<
|
<
>







1542
1543
1544
1545
1546
1547
1548
1549

1550

1551
1552
1553
1554
1555
1556
1557
1558
  blob_init(&subtext1, 0, 0);
  blob_init(&subtext2, 0, 0);
  blob_init(&s3, 0, 0);
  if( zSubtopic!=0 ){
    if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic, bAbbrevSubcmd) ){
      z = blob_str(&subtext1);
    }else{
      fossil_print("No subtopic \"%s\" for \"%s\".\n", zSubtopic, zTopic);

      bUsage = 1;

      zSubtopic = 0;
    }
  }
  if( bUsage ){
    if( simplify_to_usage(z, &subtext2, zTopic, bAbbrevSubcmd) ){
      z = blob_str(&subtext2);
    }else{
      bUsage = 0;
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
  }
  blob_init(&txt, 0, 0);
  if( bRaw ){
    blob_append(&txt, z, -1);
  }else if( useHtml ){
    help_to_html(z, &txt);
  }else{
    help_to_text(z, &txt, bUsage);
  }
  if( blob_strlen(&txt)>0 ) fossil_print("%s\n", blob_str(&txt));
  blob_reset(&txt);
  blob_reset(&subtext1);
  blob_reset(&subtext2);
}








|







1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
  }
  blob_init(&txt, 0, 0);
  if( bRaw ){
    blob_append(&txt, z, -1);
  }else if( useHtml ){
    help_to_html(z, &txt);
  }else{
    help_to_text(z, &txt, bUsage || zSubtopic!=0);
  }
  if( blob_strlen(&txt)>0 ) fossil_print("%s\n", blob_str(&txt));
  blob_reset(&txt);
  blob_reset(&subtext1);
  blob_reset(&subtext2);
}

Changes to src/export.c.
478
479
480
481
482
483
484


485
486
487
488
489
490
491
**   --rename-trunk NAME          Use NAME as name of exported trunk branch
**   -R|--repository REPO         Export the given REPOSITORY
**
** See also: import
*/
/*
** COMMAND: export*


**
** This command is deprecated.  Use "fossil git export" instead.
*/
void export_cmd(void){
  Stmt q, q2, q3;
  Bag blobs, vers;
  unsigned int unused_mark = 1;







>
>







478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
**   --rename-trunk NAME          Use NAME as name of exported trunk branch
**   -R|--repository REPO         Export the given REPOSITORY
**
** See also: import
*/
/*
** COMMAND: export*
**
** Usage: %fossil export --git [REPOSITORY]
**
** This command is deprecated.  Use "fossil git export" instead.
*/
void export_cmd(void){
  Stmt q, q2, q3;
  Bag blobs, vers;
  unsigned int unused_mark = 1;