28 std::map<std::string, std::string> args;
29 std::vector<std::string> positionalArgs;
30 bool hasError =
false;
31 std::string errorMessage;
37 static const std::vector<std::string>
validFlags;
49 parseArgs(argc, argv);
52 std::cerr <<
"\033[31mError: " << errorMessage <<
"\033[0m\n\n";
67 auto get(
const std::string& flag,
const std::string& defaultValue =
"") const -> std::
string
69 auto it = args.find(flag);
70 return (it != args.end()) ? it->second : defaultValue;
80 auto hasFlag(
const std::string& flag)
const ->
bool
82 return args.find(flag) != args.end();
92 return positionalArgs;
105 std::cout <<
"\033[1mMusic player that keeps you in Limbo.\033[0m\n";
106 std::cout <<
"\033[1mUsage:\033[0m " << programName <<
" [options] [positional arguments]\n\n";
110 std::cout <<
"\033[1mValid options:\033[0m\n";
113 std::cout <<
" " << flag <<
"\n";
120 std::cout <<
"\033[1mProject Information:\033[0m\n";
121 std::cout <<
"- Name: inLimbo - Terminal-based Music Player\n";
122 std::cout <<
"- Author: Siddharth Karnam (nots1dd)\n";
123 std::cout <<
"- License: GNU GPL v3\n";
124 std::cout <<
"- Website: https://nots1dd.github.io/inLimbo/ (has Doxygen documentation)\n";
125 std::cout <<
"For any issues visit <https://github.com/nots1dd/inLimbo>\n";
126 std::cout << std::endl;
128 std::cout <<
"\033[1mDescription:\033[0m\n";
129 std::cout <<
" inLimbo is a TUI music player that supports seamless playback and efficient "
130 "metadata handling.\n Designed for minimalism and ease of use.\n";
145 void parseArgs(
int argc,
char* argv[])
147 for (
int i = 1; i < argc; ++i)
149 std::string arg = argv[i];
153 std::string flag, value;
154 size_t eqPos = arg.find(
'=');
156 if (eqPos != std::string::npos)
159 flag = arg.substr(0, eqPos);
160 value = arg.substr(eqPos + 1);
166 if (i + 1 < argc && argv[i + 1][0] !=
'-')
178 std::string closestMatch = findClosestMatch(flag);
179 if (!closestMatch.empty())
181 errorMessage =
"Invalid flag: '" + flag +
"'. Did you mean '" + closestMatch +
"'?";
185 errorMessage =
"Invalid flag: '" + flag +
"'";
194 positionalArgs.push_back(arg);
210 auto findClosestMatch(
const std::string& invalidFlag)
const -> std::string
212 std::string bestMatch;
213 size_t minDist = std::string::npos;
224 bestMatch = validFlag;
229 return (minDist <= 3) ? bestMatch :
"";
238 "--show-config-file",
240 "--update-cache-run",
242 "--print-songs-by-artist",
243 "--print-songs-by-genre-all",
245 "--print-artists-all"};
auto getPositionalArgs() const -> const std::vector< std::string > &
Retrieves the list of positional arguments.
Definition cmd-line-args.hpp:90
CommandLineArgs(int argc, char *argv[])
Constructs a CommandLineArgs object and parses command-line arguments.
Definition cmd-line-args.hpp:47
void printUsage(const std::string &programName) const
Prints usage information and program details.
Definition cmd-line-args.hpp:103
static const std::vector< std::string > validFlags
List of valid flags supported by the application.
Definition cmd-line-args.hpp:234
auto hasFlag(const std::string &flag) const -> bool
Checks if a specific flag was provided.
Definition cmd-line-args.hpp:80
auto get(const std::string &flag, const std::string &defaultValue="") const -> std::string
Retrieves the value associated with a flag.
Definition cmd-line-args.hpp:67
auto levenshteinDistance(const std::string &s1, const std::string &s2) -> size_t
Computes the Levenshtein distance between two strings.
Definition levenshtein.hpp:36