| ︙ | | | ︙ | |
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
/*
** Format help text for TTY display.
*/
static void help_to_text(const char *zHelp, Blob *pText){
int i, x;
char c;
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;
i = -1;
continue;
|
>
>
>
>
|
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
/*
** Format help text for TTY display.
*/
static void help_to_text(const char *zHelp, Blob *pText){
int i, x;
char c;
if( 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;
i = -1;
continue;
|
| ︙ | | | ︙ | |
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
occHelp[aCommand[i].iHelp] = 0;
}
}
@ </dl>
blob_reset(&buf);
style_finish_page();
}
static void multi_column_list(const char **azWord, int nWord){
int i, j, len;
int mxLen = 0;
int nCol;
int nRow;
for(i=0; i<nWord; i++){
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1061
1062
1063
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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
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
1139
1140
1141
1142
1143
1144
|
occHelp[aCommand[i].iHelp] = 0;
}
}
@ </dl>
blob_reset(&buf);
style_finish_page();
}
/*
** 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
** pOut.
**
** Return the number of lines of z[] written into pOut. A return of
** zero means no simplification occurred.
*/
static int simplify_to_subtopic(
const char *z, /* Full original help text */
Blob *pOut, /* Write simplified help text here */
const char *zTopic, /* TOPIC */
const char *zSubtopic /* SUBTOPIC */
){
Blob in, line;
int n = 0;
char *zGlob = mprintf("> fossil %s *%s*", zTopic, zSubtopic);
blob_init(&in, z, -1);
while( blob_line(&in, &line) ){
if( sqlite3_strglob(zGlob, blob_str(&line))==0 ){
blob_appendb(pOut, &line);
n++;
while( blob_line(&in, &line) && blob_str(&line)[0]!='>' ){
blob_appendb(pOut, &line);
n++;
}
break;
}
}
fossil_free(zGlob);
if( n ) blob_trim(pOut);
return n;
return 0;
}
/*
** Input z[] is help text for a command zTopic. Write into pOut all lines of
** z[] that show the command-line syntax for that command. Lines written
** to pOut are lines that begin with out of:
**
** Usage:
** or:
** > fossil TOPIC
**
** Return the number of lines written into pOut.
*/
static int simplify_to_usage(
const char *z, /* Full original help text */
Blob *pOut, /* Write simplified help text here */
const char *zTopic /* The command for which z[] is full help text */
){
ReCompiled *pRe = 0;
Blob in, line;
int n = 0;
re_compile(&pRe, "^(Usage: | *[Oo]r: +%fossi |> fossil )", 0);
blob_init(&in, z, -1);
while( blob_line(&in, &line) ){
if( re_match(pRe, (unsigned char*)blob_str(&line), blob_strlen(&line)) ){
blob_appendb(pOut, &line);
n++;
}
}
re_free(pRe);
if( n ) blob_trim(pOut);
return n;
}
static void multi_column_list(const char **azWord, int nWord){
int i, j, len;
int mxLen = 0;
int nCol;
int nRow;
for(i=0; i<nWord; i++){
|
| ︙ | | | ︙ | |
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
|
@ --sshtrace Trace SSH activity
@ --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]
**
** 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
** topics is returned.
**
** The following options can be used when TOPIC is omitted:
**
** -a|--all List both common and auxiliary commands
** -o|--options List command-line options common to all commands
** -s|--setting List setting names
** -t|--test List unsupported "test" commands
** -v|--verbose List both names and help text
** -x|--aux List only auxiliary commands
** -w|--www List all web pages
** -f|--full List full set of commands (including auxiliary
** and unsupported "test" commands), options,
** settings, and web pages
** -e|--everything List all help on all topics
**
** These options can be used when TOPIC is present:
**
** -h|--html Format output as HTML rather than plain text
** -c|--commands Restrict TOPIC search to commands
*/
void help_cmd(void){
int rc;
int mask = CMDFLAG_ANY;
int isPage = 0;
int verboseFlag = 0;
int commandsFlag = 0;
const char *z;
const char *zCmdOrPage;
const CmdOrPage *pCmd = 0;
int useHtml = 0;
const char *zTopic;
Blob txt;
verboseFlag = find_option("verbose","v",0)!=0;
commandsFlag = find_option("commands","c",0)!=0;
useHtml = find_option("html","h",0)!=0;
if( find_option("options","o",0) ){
fossil_print("%s", zOptions);
return;
}
else if( find_option("all","a",0) ){
command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml);
return;
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
<
<
<
<
>
|
>
|
|
|
|
|
|
|
|
>
>
|
>
>
|
>
>
>
|
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
|
@ --sshtrace Trace SSH activity
@ --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: usage
**
** Usage: %fossil usage COMMAND [SUBCOMMAND]
**
** Show succinct usage instruction for a Fossil command. Shorthand
** for "fossil help --usage COMMAND [SUBCOMMAND]"
*/
void usage_cmd(void){
help_cmd();
}
/*
** 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
** topics is returned.
**
** The following options can be used when TOPIC is omitted:
**
** -a|--all List both common and auxiliary commands
** -e|--everything List all help on all topics
** -f|--full List full set of commands (including auxiliary
** and unsupported "test" commands), options,
** settings, and web pages
** -o|--options List command-line options common to all commands
** -s|--setting List setting names
** -t|--test List unsupported "test" commands
** -v|--verbose List both names and help text
** -x|--aux List only auxiliary commands
** -w|--www List all web pages
**
** These options can be used when TOPIC is present:
**
** -c|--commands Restrict TOPIC search to commands
** -h|--html Format output as HTML rather than plain text
** --raw Output raw, unformatted help text
** -u|--usage Show a succinct usage summary, not full help text
*/
void help_cmd(void){
int rc;
int mask = CMDFLAG_ANY; /* Mask of help topic types */
int isPage = 0; /* True if TOPIC is a page */
int verboseFlag = 0; /* -v option */
int commandsFlag = 0; /* -c option */
const char *z; /* Original, untranslated help text */
const char *zCmdOrPage; /* "command" or "page" or "setting" */
const CmdOrPage *pCmd = 0; /* ptr to aCommand[] entry for TOPIC */
int useHtml = 0; /* -h option */
int bUsage = g.zCmdName[0]=='u'; /* --usage or "fossil usage TOPIC" */
int bRaw; /* --raw option */
const char *zTopic; /* TOPIC argument */
const char *zSubtopic = 0; /* SUBTOPIC argument */
Blob subtext1, subtext2; /* Subsets of z[] containing subtopic/usage */
Blob txt; /* Text after rendering */
verboseFlag = find_option("verbose","v",0)!=0;
commandsFlag = find_option("commands","c",0)!=0;
useHtml = find_option("html","h",0)!=0;
bRaw = find_option("raw",0,0)!=0;
if( find_option("usage","u",0)!=0 ) bUsage = 1;
if( find_option("options","o",0) ){
fossil_print("%s", zOptions);
return;
}
else if( find_option("all","a",0) ){
command_list(CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER, verboseFlag, useHtml);
return;
|
| ︙ | | | ︙ | |
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
|
"Frequently used commands:\n",
z, z, z);
command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml);
if( !verboseFlag ) version_cmd();
return;
}
zTopic = g.argv[2];
isPage = ('/' == zTopic[0]) ? 1 : 0;
if(isPage){
zCmdOrPage = "page";
}else if( commandsFlag ){
mask = CMDFLAG_COMMAND;
zCmdOrPage = "command";
}else{
|
>
|
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
|
"Frequently used commands:\n",
z, z, z);
command_list(CMDFLAG_1ST_TIER,verboseFlag,useHtml);
if( !verboseFlag ) version_cmd();
return;
}
zTopic = g.argv[2];
zSubtopic = g.argc>=4 ? g.argv[3] : 0;
isPage = ('/' == zTopic[0]) ? 1 : 0;
if(isPage){
zCmdOrPage = "page";
}else if( commandsFlag ){
mask = CMDFLAG_COMMAND;
zCmdOrPage = "command";
}else{
|
| ︙ | | | ︙ | |
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
|
zCmdOrPage, g.argv[2]);
}
fossil_print("Did you mean one of these TOPICs:\n");
n = dispatch_approx_match(g.argv[2], 5, az);
for(i=0; i<n; i++){
fossil_print(" * %s\n", az[i]);
}
fossil_print("Also consider using:\n");
fossil_print(" fossil search -h PATTERN ;# search all help text\n");
fossil_print(" fossil help -a ;# show all commands\n");
fossil_print(" fossil help -w ;# show all web-pages\n");
fossil_print(" fossil help -s ;# show all settings\n");
fossil_print(" fossil help -o ;# show global options\n");
fossil_exit(1);
}
z = pCmd->zHelp;
if( z==0 ){
fossil_fatal("no help available for the %s %s",
pCmd->zName, zCmdOrPage);
}
if( pCmd->eCmdFlags & CMDFLAG_SETTING ){
const Setting *pSetting = db_find_setting(pCmd->zName, 0);
char *zDflt = 0;
if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){
zDflt = mprintf(" (default: %s)", pSetting->def);
}
fossil_print("Setting: \"%s\"%s%s\n\n",
pCmd->zName, zDflt!=0 ? zDflt : "",
(pCmd->eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ? " (versionable)" : ""
);
fossil_free(zDflt);
}
blob_init(&txt, 0, 0);
if( useHtml ){
help_to_html(z, &txt);
}else{
help_to_text(z, &txt);
}
fossil_print("%s\n", blob_str(&txt));
blob_reset(&txt);
}
/*
** Return a pointer to the setting information array.
**
** This routine provides access to the aSetting[] array which is created
** by the mkindex utility program and included with <page_index.h>.
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
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
|
zCmdOrPage, g.argv[2]);
}
fossil_print("Did you mean one of these TOPICs:\n");
n = dispatch_approx_match(g.argv[2], 5, az);
for(i=0; i<n; i++){
fossil_print(" * %s\n", az[i]);
}
fossil_print("Other commands to try:\n");
fossil_print(" fossil search -h PATTERN ;# search all help text\n");
fossil_print(" fossil help -a ;# show all commands\n");
fossil_print(" fossil help -w ;# show all web-pages\n");
fossil_print(" fossil help -s ;# show all settings\n");
fossil_print(" fossil help -o ;# show global options\n");
return;
}
blob_init(&subtext1, 0, 0);
blob_init(&subtext2, 0, 0);
z = pCmd->zHelp;
if( z==0 ){
fossil_fatal("no help available for the %s %s",
pCmd->zName, zCmdOrPage);
}
if( zSubtopic!=0 ){
if( simplify_to_subtopic(z, &subtext1, zTopic, zSubtopic) ){
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 && simplify_to_usage(z, &subtext2, zTopic) ){
z = blob_str(&subtext2);
}
if( pCmd->eCmdFlags & CMDFLAG_SETTING ){
const Setting *pSetting = db_find_setting(pCmd->zName, 0);
char *zDflt = 0;
if( pSetting!=0 && pSetting->def!=0 && *pSetting->def!=0 ){
zDflt = mprintf(" (default: %s)", pSetting->def);
}
fossil_print("Setting: \"%s\"%s%s\n\n",
pCmd->zName, zDflt!=0 ? zDflt : "",
(pCmd->eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ? " (versionable)" : ""
);
fossil_free(zDflt);
}
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);
}
fossil_print("%s\n", blob_str(&txt));
blob_reset(&txt);
blob_reset(&subtext1);
blob_reset(&subtext2);
}
/*
** Return a pointer to the setting information array.
**
** This routine provides access to the aSetting[] array which is created
** by the mkindex utility program and included with <page_index.h>.
|
| ︙ | | | ︙ | |