cli-base64-main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2022-07-03
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <iostream>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-encoding.hpp>
  13. #include <string>
  14. #include <vector>
  15. using ls::standard::core::LibraryVersion;
  16. using ls::standard::encoding::Base64;
  17. using std::cerr;
  18. using std::cout;
  19. using std::endl;
  20. using std::string;
  21. using std::vector;
  22. using CliCommand = vector<string>;
  23. void printHelp();
  24. bool isValidCommand(const CliCommand &_command);
  25. auto main(const int argc, char *argv[]) -> int
  26. {
  27. if (const CliCommand command(argv, argv + argc); isValidCommand(command))
  28. {
  29. if (command[1] == "--encode")
  30. {
  31. cout << Base64{}.encode(command[2]) << endl;
  32. }
  33. if (command[1] == "--decode")
  34. {
  35. cout << Base64{}.decode(command[2]) << endl;
  36. }
  37. if (command[1] == "--help")
  38. {
  39. printHelp();
  40. }
  41. }
  42. else
  43. {
  44. cerr << "There is an error in this command. Please use \"--help\" to get more information." << endl;
  45. }
  46. exit(0);
  47. }
  48. void printHelp()
  49. {
  50. string help = "Base 64 CLI - " + LibraryVersion::getVersion() + "\n\n";
  51. help += "(1) encode a string:\t\t";
  52. help += "--encode [string]\n";
  53. help += "(2) decode a string:\t\t";
  54. help += "--decode [string]";
  55. cout << help << endl;
  56. }
  57. bool isValidCommand(const CliCommand &_command)
  58. {
  59. return _command.size() == 3 && _command[1] == "--encode" && !_command[2].empty() || _command.size() == 3 && _command[1] == "--decode" && !_command[2].empty() || _command.size() == 2 && _command[1] == "--help";
  60. }