Skip to content

Commit

Permalink
zimwriterfs: Added checks for description and longDescription length,…
Browse files Browse the repository at this point in the history
… added new option --longDescription

made the --description option mandatory (its value cannot be empty)

checking that the lengths of the short and long descriptions are below
their respective limits (80 and 4000)

the long description is optional; however, if provided, it must not be
shorter than the short description
  • Loading branch information
Onyx2406 committed Mar 21, 2023
1 parent c7f3d05 commit 80b5658
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/zimwriterfs/zimwriterfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ std::string scraper = "zimwriterfs-" VERSION;
std::string name;
std::string source;
std::string description;
std::string longDescription;
std::string welcome;
std::string illustration;
std::string redirectsPath;
Expand Down Expand Up @@ -80,6 +81,28 @@ bool thereAreMissingArguments()
|| illustration.empty();
}

bool checkDescriptionLengths() {
if (description.empty()) {
std::cerr << "Description metadata should not be empty." << std::endl;
return false;
}

if (!longDescription.empty() && longDescription.length() < description.length()) {
std::cerr << "Long description should not be shorter than the short description." << std::endl;
return false;
}

if (description.length() > 80) {
std::cerr << "Description length exceeds the 80 character limit." << std::endl;
return false;
}

if (!longDescription.empty() && longDescription.length() > 4000) {
std::cerr << "Long description length exceeds the 4000 character limit." << std::endl;
return false;
}

return true;
}

// Global flags
Expand Down Expand Up @@ -123,6 +146,8 @@ void usage()
std::cout << "\t-t, --title\t\ttitle of the ZIM file" << std::endl;
std::cout << "\t-d, --description\tshort description of the content"
<< std::endl;
std::cout << "\t-L, --longDescription\tlong description of the content"
<< std::endl;
std::cout << "\t-c, --creator\t\tcreator(s) of the content" << std::endl;
std::cout << "\t-p, --publisher\t\tcreator of the ZIM file itself"
<< std::endl;
Expand Down Expand Up @@ -189,6 +214,7 @@ void parse_args(int argc, char** argv)
= {{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"longDescription", required_argument, 0, 'L'},
{"welcome", required_argument, 0, 'w'},
{"clusterSize", required_argument, 0, 'm'},
{"name", required_argument, 0, 'n'},
Expand Down Expand Up @@ -260,6 +286,9 @@ void parse_args(int argc, char** argv)
case 'm':
clusterSize = atoi(optarg);
break;
case 'L':
longDescription = optarg;
break;
case 'n':
name = optarg;
break;
Expand Down Expand Up @@ -297,6 +326,11 @@ void parse_args(int argc, char** argv)
}
} while (c != -1);

if ( !checkDescriptionLengths() ) {
exit(1);
}


while (optind < argc) {
if (directoryPath.empty()) {
directoryPath = argv[optind++];
Expand Down

0 comments on commit 80b5658

Please sign in to comment.