yat  0.21pre
Public Member Functions | Protected Member Functions | List of all members
theplu::yat::utility::OptionHelp Class Reference

Class for help option. More...

#include <yat/utility/OptionHelp.h>

Inheritance diagram for theplu::yat::utility::OptionHelp:
theplu::yat::utility::OptionSwitch theplu::yat::utility::Option

Public Member Functions

 OptionHelp (CommandLine &cmd, std::string name="h,help", std::string desc="display this help and exit")
 Constructor. More...
 
std::string & post_arguments (void)
 
std::string & synopsis (void)
 
std::string & usage (void)
 
bool value (void) const
 return value
 
std::string description (void) const
 
void description (const std::string &description)
 set description More...
 
std::string long_name (void) const
 
void parse (std::vector< std::string >::iterator &, const std::vector< std::string >::iterator &)
 parsing the commandline
 
bool present (void) const
 Get if option was found in cmd. More...
 
std::string print (void)
 print help output More...
 
void reset (void)
 sets present to false
 
char short_name (void) const
 
void validate (void)
 Validate the Option. More...
 

Protected Member Functions

const CommandLinecmd (void) const
 

Detailed Description

Class for help option.

When this option is found in parsing of commandline, it displays a help output and exits. A typical output looks like:

Usage: foo [OPTION]...

SYNOPSIS

Available options are:
-h, --help      display this help and exit
-v, --verbose   explain what is being done

Some extra information explaining something.

The output consist of four blocks. The first block can be modified with usage(void) function. The second is block is typically a one-liner explaining the application and can be modified with the synopsis(void) function. The third block contain the description of the different options, see operator<<(std::ostream&, const CommandLine&) for further details. The last block can be modified with post_arguments(void) function.

Constructor & Destructor Documentation

◆ OptionHelp()

theplu::yat::utility::OptionHelp::OptionHelp ( CommandLine cmd,
std::string  name = "h,help",
std::string  desc = "display this help and exit" 
)

Constructor.

Parameters
cmdCommandline Option is associated with
namestring such as "help" for –help, "h" for -h or "h,help" (default) for having both short and long option name
descstring used in help display

Member Function Documentation

◆ cmd()

const CommandLine& theplu::yat::utility::Option::cmd ( void  ) const
protectedinherited
Returns
const reference to CommandLine Option belongs to.

◆ description() [1/2]

std::string theplu::yat::utility::Option::description ( void  ) const
inherited
Returns
description

◆ description() [2/2]

void theplu::yat::utility::Option::description ( const std::string &  description)
inherited

set description

Since
New in yat 0.7

◆ long_name()

std::string theplu::yat::utility::Option::long_name ( void  ) const
inherited
Returns
long name e.g. 'help' for –help option.

◆ post_arguments()

std::string& theplu::yat::utility::OptionHelp::post_arguments ( void  )

Text to be displayed after list of arguments.

◆ present()

bool theplu::yat::utility::Option::present ( void  ) const
inherited

Get if option was found in cmd.

Returns
true if option has been detected in parsing

◆ print()

std::string theplu::yat::utility::Option::print ( void  )
inherited

print help output

This function calls the four virtual private functions print1, print2, print3, and print4. This allows an inherited class to implement one (or several) of these functions and keep the default output of the others. The default behavior is that:

◆ short_name()

char theplu::yat::utility::Option::short_name ( void  ) const
inherited
Returns
short name e.g. 'h' for -h option.

◆ synopsis()

std::string& theplu::yat::utility::OptionHelp::synopsis ( void  )

Text to be displayed in help output after usage()

◆ usage()

std::string& theplu::yat::utility::OptionHelp::usage ( void  )

First line to be displayed in help output. Default this string is set to "Usage: <program_name> [OPTION]...\n\n"

◆ validate()

void theplu::yat::utility::Option::validate ( void  )
inherited

Validate the Option.

This function is called by CommandLine::parse() after all options have been detected and parsed (see Option::parse()).


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

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14