[help] add an option to just display the internal help text

Fixes #67
This commit is contained in:
Timothy Stack 2014-02-10 07:53:56 -08:00
parent fcaae6af0e
commit 8c086c06ae
3 changed files with 19 additions and 6 deletions

3
lnav.1
View File

@ -46,6 +46,9 @@ Quit the program.
\fB\-h\fR
Print help and exit
.TP
\fB\-H\fR
Display the internal help text.
.TP
\fB\-d\fR file
Write debug messages to the given file.
.TP

View File

@ -2323,6 +2323,7 @@ static void usage(void)
"\n"
"Options:\n"
" -h Print this message, then exit.\n"
" -H Display the internal help text.\n"
" -C Check configuration and then exit.\n"
" -d file Write debug messages to the given file.\n"
" -V Print version information.\n"
@ -3082,6 +3083,10 @@ static void looper(void)
HELP_MSG_2(f, F,
"to switch to the next/previous file"));
}
if (!initial_build && lnav_data.ld_flags & LNF_HELP) {
toggle_view(&lnav_data.ld_views[LNV_HELP]);
initial_build = true;
}
if (lnav_data.ld_log_source.text_line_count() > 0 ||
lnav_data.ld_text_source.text_line_count() > 0) {
initial_build = true;
@ -3655,13 +3660,17 @@ int main(int argc, char *argv[])
lnav_data.ld_looping = true;
lnav_data.ld_mode = LNM_PAGING;
lnav_data.ld_debug_log_name = "/dev/null";
while ((c = getopt(argc, argv, "harsCd:tw:V")) != -1) {
while ((c = getopt(argc, argv, "hHarsCd:tw:V")) != -1) {
switch (c) {
case 'h':
usage();
exit(retval);
break;
case 'H':
lnav_data.ld_flags |= LNF_HELP;
break;
case 'C':
exit(0);
break;
@ -3779,7 +3788,7 @@ int main(int argc, char *argv[])
}
}
if (lnav_data.ld_file_names.empty()) {
if (lnav_data.ld_file_names.empty() && !lnav_data.ld_flags & LNF_HELP) {
fprintf(stderr, "error: no log files given/found.\n");
retval = EXIT_FAILURE;
}

View File

@ -70,11 +70,11 @@ typedef enum {
enum {
LNB_SYSLOG,
LNB_TIMESTAMP,
LNB__MAX,
LNB_ROTATED
LNB_TIMESTAMP,
LNB_HELP,
LNB_ROTATED,
};
/** Flags set on the lnav command-line. */
@ -84,8 +84,9 @@ typedef enum {
LNF_ROTATED = (1L << LNB_ROTATED),
LNF_TIMESTAMP = (1L << LNB_TIMESTAMP),
LNF_HELP = (1L << LNB_HELP),
LNF__ALL = (LNF_SYSLOG)
LNF__ALL = (LNF_SYSLOG|LNF_HELP)
} lnav_flags_t;
/** The different views available. */