mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
cal: Add the -y
option to show the current year
Without `-y`, to show the current full year you'd have to specify which one: `cal 2023`. Adding `-y` makes it possible to see the full current year without remembering what year we are in. This option is also stolen from FreeBSD :^) Additionally, validate args: prevent passing both -3 and -y at the same time. Passing both `--three-month-mode` and `--year` to `cal` doesn't make sense. You'd either want the one or the other.
This commit is contained in:
parent
dab82e1531
commit
190a6650bd
2 changed files with 11 additions and 2 deletions
|
@ -169,6 +169,7 @@ ErrorOr<int> 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<int> 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<int> 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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue