journalctl: make the argument to -n optional

This commit is contained in:
Lennart Poettering 2012-09-21 22:33:02 +02:00
parent f801968466
commit 1705594f59
2 changed files with 21 additions and 14 deletions

View file

@ -161,11 +161,14 @@
<listitem><para>Controls the number of <listitem><para>Controls the number of
journal lines to show, counting from journal lines to show, counting from
the most recent ones. Takes a positive the most recent ones. The argument is
integer argument. In follow mode optional, and if specified is a
defaults to 10, otherwise is unset positive integer. If not specified and
thus not limiting how many lines are in follow mode defaults to 10. If this
shown.</para></listitem> option is not passed and follow mode
is not enabled, how many lines are
shown is not
limited.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -87,7 +87,7 @@ static int help(void) {
" --no-pager Do not pipe output into a pager\n" " --no-pager Do not pipe output into a pager\n"
" -a --all Show all fields, including long and unprintable\n" " -a --all Show all fields, including long and unprintable\n"
" -f --follow Follow journal\n" " -f --follow Follow journal\n"
" -n --lines=INTEGER Journal entries to show\n" " -n --lines[=INTEGER] Number of journal entries to show\n"
" --no-tail Show all lines, even in follow mode\n" " --no-tail Show all lines, even in follow mode\n"
" -o --output=STRING Change journal output mode (short, short-monotonic,\n" " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
" verbose, export, json, json-pretty, cat)\n" " verbose, export, json, json-pretty, cat)\n"
@ -133,7 +133,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "follow", no_argument, NULL, 'f' }, { "follow", no_argument, NULL, 'f' },
{ "output", required_argument, NULL, 'o' }, { "output", required_argument, NULL, 'o' },
{ "all", no_argument, NULL, 'a' }, { "all", no_argument, NULL, 'a' },
{ "lines", required_argument, NULL, 'n' }, { "lines", optional_argument, NULL, 'n' },
{ "no-tail", no_argument, NULL, ARG_NO_TAIL }, { "no-tail", no_argument, NULL, ARG_NO_TAIL },
{ "new-id128", no_argument, NULL, ARG_NEW_ID128 }, { "new-id128", no_argument, NULL, ARG_NEW_ID128 },
{ "quiet", no_argument, NULL, 'q' }, { "quiet", no_argument, NULL, 'q' },
@ -155,7 +155,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0); assert(argc >= 0);
assert(argv); assert(argv);
while ((c = getopt_long(argc, argv, "hfo:an:qmbD:p:", options, NULL)) >= 0) { while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:", options, NULL)) >= 0) {
switch (c) { switch (c) {
@ -178,7 +178,7 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'o': case 'o':
arg_output = output_mode_from_string(optarg); arg_output = output_mode_from_string(optarg);
if (arg_output < 0) { if (arg_output < 0) {
log_error("Unknown output '%s'.", optarg); log_error("Unknown output '%s'.", optarg);
return -EINVAL; return -EINVAL;
@ -191,11 +191,15 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'n': case 'n':
r = safe_atoi(optarg, &arg_lines); if (optarg) {
if (r < 0 || arg_lines < 0) { r = safe_atoi(optarg, &arg_lines);
log_error("Failed to parse lines '%s'", optarg); if (r < 0 || arg_lines < 0) {
return -EINVAL; log_error("Failed to parse lines '%s'", optarg);
} return -EINVAL;
}
} else
arg_lines = 10;
break; break;
case ARG_NO_TAIL: case ARG_NO_TAIL: