inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
CommandLineArgs Class Reference

Parses and validates command-line arguments. More...

#include <cmd-line-args.hpp>

Public Member Functions

 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 Public Attributes

static const std::vector< std::string > validFlags
 List of valid flags supported by the application.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
argcThe number of command-line arguments.
argvThe array of command-line arguments.

Member Function Documentation

◆ 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
flagThe flag to look up.
defaultValueThe 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
flagThe flag to check.
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
programNameThe name of the program (typically argv[0]).

Member Data Documentation

◆ 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: