// // Created by gmgauthier on 05/09/25. // // main.cpp #include "passwdgen.h" #include #include int main(int argc, char *argv[]) { int passwordLength = 0; bool punc = false; if (argc < 1) { std::cout << random_string(32, false) << std::endl; return 0; } for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if ((arg == "-h") || (arg == "--help")) { show_usage(argv[0]); return 0; } if (arg == "-p") { punc = true; } else if ((arg == "-l") || (arg == "--length")) { if (not argv[i +1]) { std::cerr << "Specify a password length" << std::endl; return 1; } std::string passwordLengthStr = argv[i + 1]; try { passwordLength = std::stoi(passwordLengthStr); } catch ([[maybe_unused]] const std::invalid_argument& e){ std::cerr << "Length must be a valid integer" << std::endl; return 1; } } } if (passwordLength == 0) { passwordLength = 32; } std::string password = random_string(passwordLength, punc); std::cout << password << std::endl; return 0; }