Fixes & implementation of formatHelp
This commit is contained in:
parent
d3740b0b10
commit
f9d9eae92f
|
|
@ -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
|
||||
|
|
@ -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<int>(std::ranges::count(timeInput.cbegin(), timeInput.cend(), ' '));
|
||||
|
||||
if (spaceCheck != 4) {
|
||||
|
|
|
|||
28
src/main.cpp
28
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: <t:" << std::mktime(&resultTime) << ':' << timeFormat << '>';
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const std::invalid_argument &e) {
|
||||
std::cerr << "Error: " << e.what();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user