diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b92d763 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,48 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/include/argParser.hpp b/include/argParser.hpp new file mode 100644 index 0000000..d2ddd74 --- /dev/null +++ b/include/argParser.hpp @@ -0,0 +1,24 @@ +#ifndef ARGPARSER_H +#define ARGPARSER_H +#include +#include +#include +#include +#include +#include + +class ArgParser { + private: + std::vector tokens; + + public: + ArgParser(int &argc, char **argv); + + // Returns the command line option value if it exists + std::optional getCmdOption(std::string_view option) const; + + // Checks if a command line option exists + bool cmdOptionExists(std::string_view option) const; +}; + +#endif \ No newline at end of file diff --git a/src/argParser.cpp b/src/argParser.cpp new file mode 100644 index 0000000..7e266a5 --- /dev/null +++ b/src/argParser.cpp @@ -0,0 +1,22 @@ +#include <../include/argParser.hpp> + +ArgParser::ArgParser(int &argc, char **argv) { + for (int i = 0; i < argc; i++) { + tokens.push_back(argv[i]); + } +} + +// Returns the command line option value if it exists +std::optional ArgParser::getCmdOption( + std::string_view option) const { + auto itr = std::find(tokens.begin(), tokens.end(), option); + if (itr != tokens.end() && ++itr != tokens.end()) { + return *itr; + } + return std::nullopt; // Indicate no option found +} + +// Checks if a command line option exists +bool ArgParser::cmdOptionExists(std::string_view option) const { + return std::find(tokens.begin(), tokens.end(), option) != tokens.end(); +} diff --git a/src/main.cpp b/src/main.cpp index cd6493e..ec551fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,35 @@ +#include <../include/argParser.hpp> #include -using namespace std; -int main() {} \ No newline at end of file + +int main(int argc, char* argv[]) { + if (argc == 1) { + std::cout << "No arguments provided.!!!" << std::endl; + return -1; + } + + ArgParser argParser(argc, argv); + + if (argc == 2 && std::string_view(argv[1]) == "init") { + std::cout << "Initialize empty gitlite repository in " + << std::endl; + // Add logic for initialization + return 0; // Exit after handling "init" + } + + // Check for "-h" flag + if (argParser.cmdOptionExists("-h")) { + std::cout << "Help requested" << std::endl; + // Show help message + return 0; // Exit after showing help + } + + // Get filename after "-f" option + auto filename = argParser.getCmdOption("-f"); + if (filename) { + std::cout << "Filename: " << *filename << std::endl; + // Do something with the filename + return 0; + } + + std::cout << "Unknown command entered!!!" << std::endl; +}