Parses and validates command-line arguments.
More...
#include <cmd-line-args.hpp>
|
| CommandLineArgs (int argc, char *argv[]) |
| Constructs a CommandLineArgs object and parses command-line arguments.
|
|
auto | get (const std::string &flag, const std::string &defaultValue="") const -> std::string |
| Retrieves the value associated with a flag.
|
|
auto | hasFlag (const std::string &flag) const -> bool |
| Checks if a specific flag was provided.
|
|
auto | getPositionalArgs () const -> const std::vector< std::string > & |
| Retrieves the list of positional arguments.
|
|
void | printUsage (const std::string &programName) const |
| Prints usage information and program details.
|
|
|
static const std::vector< std::string > | validFlags |
| List of valid flags supported by the application.
|
|
Parses and validates command-line arguments.
The CommandLineArgs
class handles parsing flags, extracting positional arguments, and providing detailed error messages for invalid flags. It is designed for the inLimbo TUI music player and includes project-specific details in its usage output.
◆ CommandLineArgs()
CommandLineArgs::CommandLineArgs |
( |
int | argc, |
|
|
char * | argv[] ) |
|
inline |
Constructs a CommandLineArgs object and parses command-line arguments.
If parsing fails, an error message is displayed, usage information is printed, and the program exits with an error code.
- Parameters
-
argc | The number of command-line arguments. |
argv | The array of command-line arguments. |
◆ get()
auto CommandLineArgs::get |
( |
const std::string & | flag, |
|
|
const std::string & | defaultValue = "" ) const -> std::string
|
|
inlinenodiscard |
Retrieves the value associated with a flag.
If the flag is not present, a default value is returned.
- Parameters
-
flag | The flag to look up. |
defaultValue | The value to return if the flag is not found (default is an empty string). |
- Returns
- The value associated with the flag or the default value if the flag is not found.
◆ getPositionalArgs()
auto CommandLineArgs::getPositionalArgs |
( |
| ) |
const -> const std::vector<std::string>&
|
|
inlinenodiscard |
Retrieves the list of positional arguments.
- Returns
- A reference to a vector containing the positional arguments.
◆ hasFlag()
auto CommandLineArgs::hasFlag |
( |
const std::string & | flag | ) |
const -> bool
|
|
inlinenodiscard |
Checks if a specific flag was provided.
- Parameters
-
- Returns
true
if the flag is present, otherwise false
.
◆ printUsage()
void CommandLineArgs::printUsage |
( |
const std::string & | programName | ) |
const |
|
inline |
Prints usage information and program details.
The output includes a description of the program, valid options, and helpful links for project documentation and support.
- Parameters
-
programName | The name of the program (typically argv[0] ). |
◆ validFlags
const std::vector< std::string > CommandLineArgs::validFlags |
|
static |
Initial value:= {"--help",
"--show-dbus-name",
"--version",
"--clear-cache",
"--show-config-file",
"--show-log-dir",
"--update-cache-run",
"--print-song-tree",
"--print-songs-by-artist",
"--print-songs-by-genre-all",
"--print-song-info",
"--print-artists-all"}
List of valid flags supported by the application.
The documentation for this class was generated from the following file: