mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Related Functions | List of all members
Options Class Reference

#include <Options.hpp>

Collaboration diagram for Options:
Collaboration graph

Public Member Functions

 Options (int argc, const char *argv[], const Filesystem &filesystem=Filesystem())
 
bool ast ()
 
unsigned int loglevel ()
 
std::string config_file ()
 
bool run ()
 
 operator bool () const
 

Related Functions

(Note that these are not member functions.)

std::optional< std::string > find_config (const Filesystem &filesystem)
 

Detailed Description

An options class which is used to parse the command line arguments.

This class is what provides the command line help for mavtables.

usage: mavtables:
-h [ --help ] print this message
--config arg specify configuration file
--ast print AST of configuration file (do not run)
--version print version and license information
--loglevel arg level of logging, between 0 and 3

Definition at line 42 of file Options.hpp.

Constructor & Destructor Documentation

◆ Options()

Options::Options ( int  argc,
const char *  argv[],
const Filesystem filesystem = Filesystem() 
)

Construct an options object.

This will parse the command line arguments and construct an object for passing the result of these arguments to the application.

The first two arguments are designed to be taken directly from the inputs to the standard main function.

Parameters
argcThe number of command line arguments given.
argvThe command line arguments, as given in the arguments to the main function.
filesystemA filesystem instance. The default is to construct an instance. This exists for testing purposes.
Exceptions
std::runtime_errorif no configuration file can be found.

Definition at line 46 of file Options.cpp.

References config_file(), Filesystem::exists(), and find_config().

Here is the call graph for this function:

Member Function Documentation

◆ ast()

bool Options::ast ( )

Determine whether to print the configuration file's AST or not.

Return values
truePrint abstract syntax tree of configuration file.
falseDon't print abstract syntax tree of configuration file.

Definition at line 135 of file Options.cpp.

Here is the caller graph for this function:

◆ config_file()

std::string Options::config_file ( )

Get path to an existing configuration file.

Returns
The path to an existing, but not necessarily valid configuration file.

Definition at line 146 of file Options.cpp.

Here is the caller graph for this function:

◆ loglevel()

unsigned int Options::loglevel ( )

Get the log level.

Returns
The level to log at, between 0 and 3.

Definition at line 156 of file Options.cpp.

Here is the caller graph for this function:

◆ operator bool()

Options::operator bool ( ) const
explicit

Determine if the Options object is valid.

Return values
trueIf the options object successfully parsed the command line arguments.
falseIf the program should exit immediately.

Definition at line 179 of file Options.cpp.

◆ run()

bool Options::run ( )

Determine whether to run the firewall/router or not.

Return values
trueRun the firewall/router.
falseDon't run the firewall/router.

Definition at line 167 of file Options.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ find_config()

std::optional< std::string > find_config ( const Filesystem filesystem)
related

Find the configuration file.

Find the first configuration file in the list below:

  1. The target of the MAVTABLES_CONFIG_PATH environment variable.
  2. .mavtablesrc in the current directory.
  3. .mavtablesrc at $HOME/.mavtablesrc.
  4. The main configuration file at PREFIX/etc/mavtables.conf.
Parameters
filesystemA filesystem instance. The default is to construct an instance. This exists for testing purposes.
Returns
The path to the first configuration file found. {} if no configuration file could be found.

Definition at line 199 of file Options.cpp.

References Filesystem::exists().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: