Luna/apps/date.cpp
apio eb58b4acc8
All checks were successful
continuous-integration/drone/push Build is passing
libos: Add support for --help to ArgumentParser
2023-04-19 19:16:45 +02:00

24 lines
615 B
C++

#include <os/ArgumentParser.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char** argv)
{
StringView date;
os::ArgumentParser parser;
parser.add_description("Display the current (or another) date and time."_sv);
parser.add_value_argument(date, 'd', "date"_sv, true,
"the UNIX timestamp to display instead of the current time"_sv);
parser.parse(argc, argv);
time_t now;
if (date.is_empty()) { now = time(NULL); }
else { now = strtol(date.chars(), nullptr, 10); }
fputs(ctime(&now), stdout);
}