-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a990b40
commit eb75faf
Showing
4 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef ARGPARSER_H | ||
#define ARGPARSER_H | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <optional> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
class ArgParser { | ||
private: | ||
std::vector<std::string> tokens; | ||
|
||
public: | ||
ArgParser(int &argc, char **argv); | ||
|
||
// Returns the command line option value if it exists | ||
std::optional<std::string_view> getCmdOption(std::string_view option) const; | ||
|
||
// Checks if a command line option exists | ||
bool cmdOptionExists(std::string_view option) const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<std::string_view> 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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
#include <../include/argParser.hpp> | ||
#include <iostream> | ||
using namespace std; | ||
int main() {} | ||
|
||
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 <current_dir_path>" | ||
<< 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; | ||
} |