Fixes & implementation of formatHelp

This commit is contained in:
theskywinds 2025-06-27 10:20:24 +02:00
parent d3740b0b10
commit f9d9eae92f
3 changed files with 26 additions and 9 deletions

View File

@ -23,6 +23,6 @@ Allow for the user to pass the output into a file for use in the longer term.
Directly allow input using the parser alone. Directly allow input using the parser alone.
## progress ## progress
- [ ] Set up the startup sequence & basic input (and output) - [x] Set up the startup sequence & basic input (and output)
- [ ] Add a basic system for inputting time and outputting (correct) epoch time - [ ] Add a basic system for inputting time and outputting (correct) epoch time
- [ ] Properly implement commandline parsing as stated in the plan - [ ] Properly implement commandline parsing as stated in the plan

View File

@ -19,6 +19,11 @@ namespace distime {
std::getline(std::cin, timeInput); std::getline(std::cin, timeInput);
if (std::ranges::any_of(timeInput.cbegin(), timeInput.cend(), [] (char input) {return !isdigit(input) && !isspace(input);})) {
std::cout << "Cannot contain non-numbers";
continue;
}
int spaceCheck = static_cast<int>(std::ranges::count(timeInput.cbegin(), timeInput.cend(), ' ')); int spaceCheck = static_cast<int>(std::ranges::count(timeInput.cbegin(), timeInput.cend(), ' '));
if (spaceCheck != 4) { if (spaceCheck != 4) {

View File

@ -14,6 +14,7 @@ void validateTimeFormatSelection(char timeFormat) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
try {
CLI::App app{}; CLI::App app{};
app.usage("USAGE: distime [OPTIONS]"); app.usage("USAGE: distime [OPTIONS]");
@ -22,16 +23,23 @@ int main(int argc, char **argv) {
->multi_option_policy (CLI::MultiOptionPolicy::Throw) ->multi_option_policy (CLI::MultiOptionPolicy::Throw)
->default_val('f'); ->default_val('f');
// auto formatHelp { [] () { auto formatHelp { [] () {
// std::cout std::cout
// << "" << "F - Long format [Friday, June 27, 2025 at 9:00]\n"
// } }; << "f - Short Long Format [June 27, 2025 at 9:00]\n"
<< "D - Short Format [June 27, 2025]\n"
<< "d - Compact Format [06/27/2025]\n"
<< "T - Long Time Format [9:00:00]\n"
<< "t - Short Time Format [9:00]\n"
<< "R - Relative Time Format [51 seconds ago]\n";
// app.add_flag_callback("-fh, --format-help", , "Help with formats"); std::exit(EXIT_SUCCESS);
} };
app.add_flag_callback("--format-help", formatHelp , "Help with formats");
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);
// TODO: Catch the exception it can throw.
validateTimeFormatSelection(timeFormat); validateTimeFormatSelection(timeFormat);
std::time_t result = std::time(nullptr); std::time_t result = std::time(nullptr);
@ -40,8 +48,12 @@ int main(int argc, char **argv) {
distime::parseTimeInput(resultTime, currentTime); distime::parseTimeInput(resultTime, currentTime);
std::cout << std::put_time(&resultTime, "%d-%m-%Y %H:%M\n"); std::cout << "Resulting time: " << std::put_time(&resultTime, "%d-%m-%Y %H:%M\n");
std::cout << "Time since epoch: " << std::mktime(&resultTime); std::cout << "Time stamp: <t:" << std::mktime(&resultTime) << ':' << timeFormat << '>';
return EXIT_SUCCESS; return EXIT_SUCCESS;
}
catch (const std::invalid_argument &e) {
std::cerr << "Error: " << e.what();
}
} }