Luna/apps/date.cpp
apio e99ba4df36
All checks were successful
continuous-integration/drone/push Build is passing
date: Make the --date option require a value
2023-03-30 21:39:42 +02:00

22 lines
435 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;
ArgumentParser parser;
parser.add_value_argument(date, 'd', "date"_sv, true);
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);
}