MythTV  master
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CommandLineArg Class Reference

Definition for a single command line option. More...

#include <mythcommandlineparser.h>

Inheritance diagram for CommandLineArg:
Inheritance graph
[legend]
Collaboration diagram for CommandLineArg:
Collaboration graph
[legend]

Public Member Functions

 CommandLineArg (const QString &name, QVariant::Type type, QVariant def, QString help, QString longhelp)
 Default constructor for CommandLineArg class. More...
 
 CommandLineArg (const QString &name, QVariant::Type type, QVariant def)
 Reduced constructor for CommandLineArg class. More...
 
 CommandLineArg (const QString &name)
 Dummy constructor for CommandLineArg class. More...
 
 ~CommandLineArg () override=default
 
CommandLineArgSetGroup (const QString &group)
 
void AddKeyword (const QString &keyword)
 
QString GetName (void) const
 
QString GetUsedKeyword (void) const
 
int GetKeywordLength (void) const
 Return length of full keyword string for use in determining indent of help text. More...
 
QString GetHelpString (int off, const QString &group="", bool force=false) const
 Return string containing help text with desired offset. More...
 
QString GetLongHelpString (QString keyword) const
 Return string containing extended help text. More...
 
bool Set (const QString &opt)
 Set option as provided on command line with no value. More...
 
bool Set (const QString &opt, const QByteArray &val)
 Set option as provided on command line with value. More...
 
void Set (QVariant val)
 
CommandLineArgSetParent (const QString &opt)
 Set argument as child of given parent. More...
 
CommandLineArgSetParent (const QStringList &opts)
 Set argument as child of multiple parents. More...
 
CommandLineArgSetParentOf (const QString &opt)
 Set argument as parent of given child. More...
 
CommandLineArgSetParentOf (const QStringList &opts)
 Set argument as parent of multiple children. More...
 
CommandLineArgSetChild (const QString &opt)
 Set argument as parent of given child. More...
 
CommandLineArgSetChild (const QStringList &opt)
 Set argument as parent of multiple children. More...
 
CommandLineArgSetChildOf (const QString &opt)
 Set argument as child of given parent. More...
 
CommandLineArgSetChildOf (const QStringList &opts)
 Set argument as child of multiple parents. More...
 
CommandLineArgSetRequiredChild (const QString &opt)
 Set argument as parent of given child and mark as required. More...
 
CommandLineArgSetRequiredChild (const QStringList &opt)
 Set argument as parent of multiple children and mark as required. More...
 
CommandLineArgSetRequiredChildOf (const QString &opt)
 Set argument as child required by given parent. More...
 
CommandLineArgSetRequiredChildOf (const QStringList &opt)
 Set argument as child required by multiple parents. More...
 
CommandLineArgSetRequires (const QString &opt)
 Set argument as requiring given option. More...
 
CommandLineArgSetRequires (const QStringList &opts)
 Set argument as requiring multiple options. More...
 
CommandLineArgSetBlocks (const QString &opt)
 Set argument as incompatible with given option. More...
 
CommandLineArgSetBlocks (const QStringList &opts)
 Set argument as incompatible with multiple options. More...
 
CommandLineArgSetDeprecated (QString depstr="")
 Set option as deprecated. More...
 
CommandLineArgSetRemoved (QString remstr="", QString remver="")
 Set option as removed. More...
 
void PrintVerbose (void) const
 Internal use. More...
 
- Public Member Functions inherited from ReferenceCounter
 ReferenceCounter (const QString &debugName, bool logDebug=true)
 Creates reference counter with an initial value of 1. More...
 
virtual int IncrRef (void)
 Increments reference count. More...
 
virtual int DecrRef (void)
 Decrements reference count and deletes on 0. More...
 

Static Public Member Functions

static void AllowOneOf (const QList< CommandLineArg * > &args)
 Mark a list of arguments as mutually exclusive. More...
 
- Static Public Member Functions inherited from ReferenceCounter
static void PrintDebug (void)
 Print out any leaks if that level of debugging is enabled. More...
 

Private Member Functions

QString GetKeywordString (void) const
 Return string containing all possible keyword triggers for this argument. More...
 
void SetParentOf (CommandLineArg *other, bool forward=true)
 Internal use, set argument as parent of given child. More...
 
void SetChildOf (CommandLineArg *other, bool forward=true)
 Internal use, set argument as child of given parent. More...
 
void SetRequires (CommandLineArg *other, bool forward=true)
 Internal use, set argument as requiring given option. More...
 
void SetBlocks (CommandLineArg *other, bool forward=true)
 Internal use, set argument as incompatible with given option. More...
 
void Convert (void)
 Convert stored string value from QByteArray to QString. More...
 
QString GetPreferredKeyword (void) const
 Return the longest keyword for the argument. More...
 
bool TestLinks (void) const
 Test all related arguments to make sure specified requirements are fulfilled. More...
 
void CleanupLinks (void)
 Clear out references to other arguments in preparation for deletion. More...
 
void PrintRemovedWarning (QString &keyword) const
 Internal use. More...
 
void PrintDeprecatedWarning (QString &keyword) const
 Internal use. More...
 

Private Attributes

bool m_given {false}
 
bool m_converted {false}
 
QString m_name
 
QString m_group
 
QString m_deprecated
 
QString m_removed
 
QString m_removedversion
 
QVariant::Type m_type {QVariant::Invalid}
 
QVariant m_default
 
QVariant m_stored
 
QStringList m_keywords
 
QString m_usedKeyword
 
QList< CommandLineArg * > m_parents
 
QList< CommandLineArg * > m_children
 
QList< CommandLineArg * > m_requires
 
QList< CommandLineArg * > m_requiredby
 
QList< CommandLineArg * > m_blocks
 
QString m_help
 
QString m_longhelp
 

Friends

class MythCommandLineParser
 

Additional Inherited Members

- Protected Member Functions inherited from ReferenceCounter
virtual ~ReferenceCounter (void)
 Called on destruction, will warn if object deleted with references in place. More...
 
- Protected Attributes inherited from ReferenceCounter
bool m_logDebug
 This is used to suppress creating LoggingItem classes for LoggingItem reference count changes. More...
 
QAtomicInt m_referenceCount {1}
 

Detailed Description

Definition for a single command line option.

This class contains instructions for the command line parser about what options to process from the command line. Each instance can correspond to multiple argument keywords, and stores a default value, whether it has been supplied, help text, and optional interdependencies with other CommandLineArgs.

Definition at line 20 of file mythcommandlineparser.h.

Constructor & Destructor Documentation

◆ CommandLineArg() [1/3]

CommandLineArg::CommandLineArg ( const QString &  name,
QVariant::Type  type,
QVariant  def,
QString  help,
QString  longhelp 
)

Default constructor for CommandLineArg class.

This constructor is for use with command line parser, defining an option that can be used on the command line, and should be reported in –help printouts

Definition at line 172 of file mythcommandlineparser.cpp.

Referenced by SetBlocks(), SetChild(), SetChildOf(), SetParent(), SetParentOf(), SetRequiredChild(), SetRequiredChildOf(), and SetRequires().

◆ CommandLineArg() [2/3]

CommandLineArg::CommandLineArg ( const QString &  name,
QVariant::Type  type,
QVariant  def 
)

Reduced constructor for CommandLineArg class.

This constructor is for internal use within the command line parser. It is intended for use in supplementary data storage for information not supplied directly on the command line.

Definition at line 189 of file mythcommandlineparser.cpp.

◆ CommandLineArg() [3/3]

CommandLineArg::CommandLineArg ( const QString &  name)
explicit

Dummy constructor for CommandLineArg class.

This constructor is for internal use within the command line parser. It is used as a placeholder for defining relations between different command line arguments, and is reconciled with the proper argument of the same name prior to parsing inputs.

Definition at line 205 of file mythcommandlineparser.cpp.

◆ ~CommandLineArg()

CommandLineArg::~CommandLineArg ( )
overridedefault

Member Function Documentation

◆ SetGroup()

CommandLineArg* CommandLineArg::SetGroup ( const QString &  group)
inline

◆ AddKeyword()

void CommandLineArg::AddKeyword ( const QString &  keyword)
inline

Definition at line 31 of file mythcommandlineparser.h.

◆ GetName()

QString CommandLineArg::GetName ( void  ) const
inline

Definition at line 33 of file mythcommandlineparser.h.

Referenced by MythCommandLineParser::Parse().

◆ GetUsedKeyword()

QString CommandLineArg::GetUsedKeyword ( void  ) const
inline

Definition at line 34 of file mythcommandlineparser.h.

◆ GetKeywordLength()

int CommandLineArg::GetKeywordLength ( void  ) const

Return length of full keyword string for use in determining indent of help text.

Definition at line 224 of file mythcommandlineparser.cpp.

◆ GetHelpString()

QString CommandLineArg::GetHelpString ( int  off,
const QString &  group = "",
bool  force = false 
) const

Return string containing help text with desired offset.

This function returns a string containing all usable keywords and the shortened help text, for use with the general help printout showing all options. It automatically accounts for terminal width, and wraps the text accordingly.

The group option acts as a filter, only returning text if the argument is part of the group the parser is currently printing options for.

Child arguments will not produce help text on their own, but only indented beneath each of the marked parent arguments. The force option specifies that the function is being called by the parent argument, and help should be output.

Definition at line 250 of file mythcommandlineparser.cpp.

◆ GetLongHelpString()

QString CommandLineArg::GetLongHelpString ( QString  keyword) const

Return string containing extended help text.

This function returns a longer version of the help text than that provided with the list of arguments, intended for more detailed, specific information. This also documents the type of argument it takes, default value, and any relational dependencies with other arguments it might have.

Definition at line 326 of file mythcommandlineparser.cpp.

◆ Set() [1/3]

bool CommandLineArg::Set ( const QString &  opt)

Set option as provided on command line with no value.

This specifies that an option is given, but there is no corresponding value, meaning this can only be used on a boolean, integer, and string arguments. All other will return false.

Definition at line 433 of file mythcommandlineparser.cpp.

Referenced by MythCommandLineParser::Parse().

◆ Set() [2/3]

bool CommandLineArg::Set ( const QString &  opt,
const QByteArray &  val 
)

Set option as provided on command line with value.

Definition at line 466 of file mythcommandlineparser.cpp.

◆ Set() [3/3]

void CommandLineArg::Set ( QVariant  val)
inline

Definition at line 42 of file mythcommandlineparser.h.

◆ SetParent() [1/2]

CommandLineArg * CommandLineArg::SetParent ( const QString &  opt)

Set argument as child of given parent.

Definition at line 566 of file mythcommandlineparser.cpp.

◆ SetParent() [2/2]

CommandLineArg * CommandLineArg::SetParent ( const QStringList &  opts)

Set argument as child of multiple parents.

Definition at line 574 of file mythcommandlineparser.cpp.

◆ SetParentOf() [1/3]

CommandLineArg * CommandLineArg::SetParentOf ( const QString &  opt)

Set argument as parent of given child.

Definition at line 549 of file mythcommandlineparser.cpp.

Referenced by MythTVSetupCommandLineParser::LoadArguments(), and SetChildOf().

◆ SetParentOf() [2/3]

CommandLineArg * CommandLineArg::SetParentOf ( const QStringList &  opts)

Set argument as parent of multiple children.

Definition at line 557 of file mythcommandlineparser.cpp.

◆ SetChild() [1/2]

CommandLineArg * CommandLineArg::SetChild ( const QString &  opt)

Set argument as parent of given child.

Definition at line 600 of file mythcommandlineparser.cpp.

◆ SetChild() [2/2]

CommandLineArg * CommandLineArg::SetChild ( const QStringList &  opt)

Set argument as parent of multiple children.

Definition at line 608 of file mythcommandlineparser.cpp.

◆ SetChildOf() [1/3]

CommandLineArg * CommandLineArg::SetChildOf ( const QString &  opt)

◆ SetChildOf() [2/3]

CommandLineArg * CommandLineArg::SetChildOf ( const QStringList &  opts)

Set argument as child of multiple parents.

Definition at line 591 of file mythcommandlineparser.cpp.

◆ SetRequiredChild() [1/2]

CommandLineArg * CommandLineArg::SetRequiredChild ( const QString &  opt)

Set argument as parent of given child and mark as required.

Definition at line 617 of file mythcommandlineparser.cpp.

Referenced by MythAVTestCommandLineParser::LoadArguments().

◆ SetRequiredChild() [2/2]

CommandLineArg * CommandLineArg::SetRequiredChild ( const QStringList &  opt)

Set argument as parent of multiple children and mark as required.

Definition at line 626 of file mythcommandlineparser.cpp.

◆ SetRequiredChildOf() [1/2]

CommandLineArg * CommandLineArg::SetRequiredChildOf ( const QString &  opt)

Set argument as child required by given parent.

Definition at line 638 of file mythcommandlineparser.cpp.

Referenced by MythFillDatabaseCommandLineParser::LoadArguments(), and MythUtilCommandLineParser::LoadArguments().

◆ SetRequiredChildOf() [2/2]

CommandLineArg * CommandLineArg::SetRequiredChildOf ( const QStringList &  opt)

Set argument as child required by multiple parents.

Definition at line 647 of file mythcommandlineparser.cpp.

◆ SetRequires() [1/3]

CommandLineArg * CommandLineArg::SetRequires ( const QString &  opt)

◆ SetRequires() [2/3]

CommandLineArg * CommandLineArg::SetRequires ( const QStringList &  opts)

Set argument as requiring multiple options.

Definition at line 667 of file mythcommandlineparser.cpp.

◆ SetBlocks() [1/3]

CommandLineArg * CommandLineArg::SetBlocks ( const QString &  opt)

◆ SetBlocks() [2/3]

CommandLineArg * CommandLineArg::SetBlocks ( const QStringList &  opts)

Set argument as incompatible with multiple options.

Definition at line 684 of file mythcommandlineparser.cpp.

◆ SetDeprecated()

CommandLineArg * CommandLineArg::SetDeprecated ( QString  depstr = "")

Set option as deprecated.

Definition at line 693 of file mythcommandlineparser.cpp.

Referenced by MythCommandLineParser::addLogging(), and MythFillDatabaseCommandLineParser::LoadArguments().

◆ SetRemoved()

CommandLineArg * CommandLineArg::SetRemoved ( QString  remstr = "",
QString  remver = "" 
)

◆ AllowOneOf()

void CommandLineArg::AllowOneOf ( const QList< CommandLineArg * > &  args)
static

◆ PrintVerbose()

void CommandLineArg::PrintVerbose ( void  ) const

Internal use.

Print processed input in verbose mode.

Definition at line 1028 of file mythcommandlineparser.cpp.

◆ GetKeywordString()

QString CommandLineArg::GetKeywordString ( void  ) const
private

Return string containing all possible keyword triggers for this argument.

Definition at line 214 of file mythcommandlineparser.cpp.

Referenced by GetHelpString(), and GetKeywordLength().

◆ SetParentOf() [3/3]

void CommandLineArg::SetParentOf ( CommandLineArg other,
bool  forward = true 
)
private

Internal use, set argument as parent of given child.

This option is intended for internal use only, as part of reconciling dummy options with their matched real counterparts.

Definition at line 717 of file mythcommandlineparser.cpp.

◆ SetChildOf() [3/3]

void CommandLineArg::SetChildOf ( CommandLineArg other,
bool  forward = true 
)
private

Internal use, set argument as child of given parent.

This option is intended for internal use only, as part of reconciling dummy options with their matched real counterparts.

Definition at line 745 of file mythcommandlineparser.cpp.

◆ SetRequires() [3/3]

void CommandLineArg::SetRequires ( CommandLineArg other,
bool  forward = true 
)
private

Internal use, set argument as requiring given option.

This option is intended for internal use only, as part of reconciling dummy options with their matched real counterparts.

Definition at line 773 of file mythcommandlineparser.cpp.

◆ SetBlocks() [3/3]

void CommandLineArg::SetBlocks ( CommandLineArg other,
bool  forward = true 
)
private

Internal use, set argument as incompatible with given option.

This option is intended for internal use only, as part of reconciling dummy options with their matched real counterparts.

Definition at line 802 of file mythcommandlineparser.cpp.

◆ Convert()

void CommandLineArg::Convert ( void  )
private

Convert stored string value from QByteArray to QString.

This is a work around to delay string processing until after QApplication has been initialized, to allow the locale to be configured and unicode handling to work properly

Definition at line 855 of file mythcommandlineparser.cpp.

◆ GetPreferredKeyword()

QString CommandLineArg::GetPreferredKeyword ( void  ) const
private

Return the longest keyword for the argument.

This is used to determine which keyword to use when listing relations to other options. The longest keyword is presumed to be the most descriptive.

Definition at line 913 of file mythcommandlineparser.cpp.

◆ TestLinks()

bool CommandLineArg::TestLinks ( void  ) const
private

Test all related arguments to make sure specified requirements are fulfilled.

Definition at line 935 of file mythcommandlineparser.cpp.

◆ CleanupLinks()

void CommandLineArg::CleanupLinks ( void  )
private

Clear out references to other arguments in preparation for deletion.

Definition at line 1007 of file mythcommandlineparser.cpp.

◆ PrintRemovedWarning()

void CommandLineArg::PrintRemovedWarning ( QString &  keyword) const
private

Internal use.

Print warning for removed option.

Definition at line 1121 of file mythcommandlineparser.cpp.

Referenced by GetLongHelpString(), and MythCommandLineParser::Parse().

◆ PrintDeprecatedWarning()

void CommandLineArg::PrintDeprecatedWarning ( QString &  keyword) const
private

Internal use.

Print warning for deprecated option.

Definition at line 1137 of file mythcommandlineparser.cpp.

Referenced by GetLongHelpString(), and MythCommandLineParser::Parse().

Friends And Related Function Documentation

◆ MythCommandLineParser

friend class MythCommandLineParser
friend

Definition at line 72 of file mythcommandlineparser.h.

Member Data Documentation

◆ m_given

bool CommandLineArg::m_given {false}
private

Definition at line 91 of file mythcommandlineparser.h.

Referenced by Convert(), PrintVerbose(), Set(), and TestLinks().

◆ m_converted

bool CommandLineArg::m_converted {false}
private

Definition at line 92 of file mythcommandlineparser.h.

Referenced by CommandLineArg(), and Convert().

◆ m_name

QString CommandLineArg::m_name
private

Definition at line 93 of file mythcommandlineparser.h.

Referenced by PrintVerbose(), SetBlocks(), SetChildOf(), SetParentOf(), and SetRequires().

◆ m_group

QString CommandLineArg::m_group
private

Definition at line 94 of file mythcommandlineparser.h.

Referenced by GetHelpString().

◆ m_deprecated

QString CommandLineArg::m_deprecated
private

◆ m_removed

QString CommandLineArg::m_removed
private

◆ m_removedversion

QString CommandLineArg::m_removedversion
private

Definition at line 97 of file mythcommandlineparser.h.

Referenced by PrintRemovedWarning(), and SetRemoved().

◆ m_type

QVariant::Type CommandLineArg::m_type {QVariant::Invalid}
private

Definition at line 98 of file mythcommandlineparser.h.

Referenced by CommandLineArg(), Convert(), GetLongHelpString(), PrintVerbose(), and Set().

◆ m_default

QVariant CommandLineArg::m_default
private

Definition at line 99 of file mythcommandlineparser.h.

Referenced by GetLongHelpString(), and Set().

◆ m_stored

QVariant CommandLineArg::m_stored
private

Definition at line 100 of file mythcommandlineparser.h.

Referenced by Convert(), MythCommandLineParser::Parse(), PrintVerbose(), and Set().

◆ m_keywords

QStringList CommandLineArg::m_keywords
private

◆ m_usedKeyword

QString CommandLineArg::m_usedKeyword
private

Definition at line 103 of file mythcommandlineparser.h.

Referenced by Set(), and TestLinks().

◆ m_parents

QList<CommandLineArg*> CommandLineArg::m_parents
private

◆ m_children

QList<CommandLineArg*> CommandLineArg::m_children
private

◆ m_requires

QList<CommandLineArg*> CommandLineArg::m_requires
private

◆ m_requiredby

QList<CommandLineArg*> CommandLineArg::m_requiredby
private

Definition at line 108 of file mythcommandlineparser.h.

Referenced by CleanupLinks(), and SetRequiredChildOf().

◆ m_blocks

QList<CommandLineArg*> CommandLineArg::m_blocks
private

Definition at line 109 of file mythcommandlineparser.h.

Referenced by CleanupLinks(), GetLongHelpString(), SetBlocks(), and TestLinks().

◆ m_help

QString CommandLineArg::m_help
private

Definition at line 111 of file mythcommandlineparser.h.

Referenced by GetHelpString(), and GetLongHelpString().

◆ m_longhelp

QString CommandLineArg::m_longhelp
private

Definition at line 112 of file mythcommandlineparser.h.

Referenced by GetLongHelpString().


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