Bladeren bron

Merge branch 'cli_base64' of public/ls-standard-library into development

Lynar Studios - Public Repositories 2 jaren geleden
bovenliggende
commit
c548bf7757
3 gewijzigde bestanden met toevoegingen van 71 en 0 verwijderingen
  1. 6 0
      CMakeLists.txt
  2. 1 0
      README.md
  3. 64 0
      source/ls_std/encoding/cli/cli_base64_main.cpp

+ 6 - 0
CMakeLists.txt

@@ -438,6 +438,12 @@ if (${LS_STD_BUILD_MODULE})
     set_target_properties("${MODULE_NAME_ENCODING}" PROPERTIES DEBUG_POSTFIX "_d")
 endif ()
 
+# CLI base64
+
+add_executable(cli_base64
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/encoding/cli/cli_base64_main.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/encoding/Base64.cpp)
+
 ##########################################################
 # Build Library (event)
 ##########################################################

+ 1 - 0
README.md

@@ -41,6 +41,7 @@ A __Date__ class comes with this submodule, which you can use to represent a dat
 - this library is now being compiled with C++ 17 standard
 - this library can now build shared libraries by using MSVC
 - Clang support has been added to this library
+- added Base64 CLI Tool, which enables a user to use Base64 encoding and decoding functionalities via CLI
 
 #### Improvements ####
 

+ 64 - 0
source/ls_std/encoding/cli/cli_base64_main.cpp

@@ -0,0 +1,64 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-07-03
+ * Changed:         2022-07-03
+ *
+ * */
+
+#include <iostream>
+#include <vector>
+#include <string>
+#include <ls_std/ls_std_encoding.hpp>
+#include <ls_std/ls_std_core.hpp>
+
+using CLICommand = std::vector<std::string>;
+
+void printHelp();
+bool isValidCommand(const CLICommand &_command);
+
+int main(int argc, char *argv[])
+{
+  CLICommand command(argv, argv + argc);
+
+  if (isValidCommand(command))
+  {
+    if (command[1] == "--encode")
+    {
+      std::cout << ls::std::encoding::Base64{}.encode(command[2]) << std::endl;
+    }
+
+    if (command[1] == "--decode")
+    {
+      std::cout << ls::std::encoding::Base64{}.decode(command[2]) << std::endl;
+    }
+
+    if (command[1] == "--help")
+    {
+      printHelp();
+    }
+  }
+  else
+  {
+    std::cerr << "There is an error in this command. Please use \"--help\" to get more information." << std::endl;
+  }
+
+  exit(0);
+}
+
+void printHelp()
+{
+  std::string help = "Base 64 CLI - " + ls::std::core::getVersion() + "\n\n";
+  help += "(1) encode a string:\t\t";
+  help += "--encode [string]\n";
+  help += "(2) decode a string:\t\t";
+  help += "--decode [string]";
+
+  std::cout << help << std::endl;
+}
+
+bool isValidCommand(const CLICommand &_command)
+{
+  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";
+}