Skip to content

Commit

Permalink
Refactor command line argument validation and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcaulfield committed Dec 23, 2023
1 parent 60ed393 commit fc7374d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
int main(int argc, char *argv[]) {
try {
std::srand(static_cast<unsigned>(std::time(nullptr)));
// std::cout << "Args count: " << argc << std::endl;

if (argc != 3) {
throw std::invalid_argument("Usage: lorem-gen <number> <number>");
throw std::invalid_argument(
"Usage: lorem-gen <paragraph_count> <sentence_count>");
}

int paragraph_count = std::atoi(argv[1]);
int sentence_count = std::atoi(argv[2]);

if (paragraph_count <= 0 || sentence_count <= 0) {
throw std::invalid_argument(
"Program argument is not a positive integer.");
"Invalid argument: paragraph_count and sentence_count must be "
"positive integers.");
}

// for (int i = 0; i < argc; ++i) {
// std::cout << argv[i] << std::endl;
// }

std::vector<Paragraph> paragraphs;

for (int i = 0; i < paragraph_count; ++i) {
Expand Down

0 comments on commit fc7374d

Please sign in to comment.