diff --git a/README.md b/README.md index ffd44e9..7a06c23 100644 --- a/README.md +++ b/README.md @@ -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. ## 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 - [ ] Properly implement commandline parsing as stated in the plan \ No newline at end of file diff --git a/src/distime.cpp b/src/distime.cpp index 33f9bd3..018abcc 100644 --- a/src/distime.cpp +++ b/src/distime.cpp @@ -19,6 +19,11 @@ namespace distime { 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(std::ranges::count(timeInput.cbegin(), timeInput.cend(), ' ')); if (spaceCheck != 4) { diff --git a/src/main.cpp b/src/main.cpp index 9677a70..7c0842a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ void validateTimeFormatSelection(char timeFormat) { } int main(int argc, char **argv) { + try { CLI::App app{}; app.usage("USAGE: distime [OPTIONS]"); @@ -22,16 +23,23 @@ int main(int argc, char **argv) { ->multi_option_policy (CLI::MultiOptionPolicy::Throw) ->default_val('f'); - // auto formatHelp { [] () { - // std::cout - // << "" - // } }; + auto formatHelp { [] () { + 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); - // TODO: Catch the exception it can throw. validateTimeFormatSelection(timeFormat); std::time_t result = std::time(nullptr); @@ -40,8 +48,12 @@ int main(int argc, char **argv) { distime::parseTimeInput(resultTime, currentTime); - std::cout << std::put_time(&resultTime, "%d-%m-%Y %H:%M\n"); - std::cout << "Time since epoch: " << std::mktime(&resultTime); + std::cout << "Resulting time: " << std::put_time(&resultTime, "%d-%m-%Y %H:%M\n"); + std::cout << "Time stamp: '; return EXIT_SUCCESS; +} + catch (const std::invalid_argument &e) { + std::cerr << "Error: " << e.what(); + } }