diff --git a/Base/usr/share/man/man1/cal.md b/Base/usr/share/man/man1/cal.md index bdfde3d356..409a4e6d54 100644 --- a/Base/usr/share/man/man1/cal.md +++ b/Base/usr/share/man/man1/cal.md @@ -5,7 +5,7 @@ cal - Display a calendar ## Synopsis ```**sh -$ cal [--starting-day weekday] [--three-month-view] [[month] year] +$ cal [--starting-day weekday] [--three-month-view] [--year] [[month] year] ``` ## Description @@ -24,6 +24,7 @@ Days, months and years are specified with numbers. Week starts at Sunday. * `-s`, `--starting-day`: Specify which day should start the week. Accepts either short or long weekday names or indexes (0 being Sunday). * `-3`, `--three-month-view`: Display the previous, current, and next months side-by-side. +* `-y`, `--year`: Display an entire year by laying out months on a grid. If no year number is specified, the current year is used as a default. ## Examples diff --git a/Userland/Utilities/cal.cpp b/Userland/Utilities/cal.cpp index 99d4cbcc9b..39ca1ebd4c 100644 --- a/Userland/Utilities/cal.cpp +++ b/Userland/Utilities/cal.cpp @@ -169,6 +169,7 @@ ErrorOr serenity_main(Main::Arguments arguments) int year = 0; StringView week_start_day_name {}; bool three_month_mode = false; + bool year_mode = false; Core::ArgsParser args_parser; args_parser.set_general_help("Display a nice overview of a month or year, defaulting to the current month."); @@ -176,9 +177,15 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_positional_argument(month, "Month", "month", Core::ArgsParser::Required::No); args_parser.add_positional_argument(year, "Year", "year", Core::ArgsParser::Required::No); args_parser.add_option(week_start_day_name, "Day that starts the week", "starting-day", 's', "day"); + args_parser.add_option(year_mode, "Show the whole year at once", "year", 'y'); args_parser.add_option(three_month_mode, "Show the previous and next month beside the current one", "three-month-view", '3'); args_parser.parse(arguments); + if (three_month_mode && year_mode) { + warnln("cal: Cannot specify both --year and --three-month-mode at the same time"); + return 1; + } + time_t now = time(nullptr); auto* tm = localtime(&now); current_year = tm->tm_year + 1900; @@ -191,7 +198,8 @@ ErrorOr serenity_main(Main::Arguments arguments) month = 0; } - bool year_mode = !month && year; + if (!month && year) + year_mode = true; int week_start_day; if (week_start_day_name.is_empty())