AceUtils  0.6.0
Useful Arduino utilties which are too small as separate libraries, but complex enough to be shared among multiple projects, and often have external dependencies to other libraries.
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
ace_utils::cli::CommandHandler Class Referenceabstract

Signature for a command handler. More...

#include <CommandHandler.h>

Public Member Functions

virtual void run (Print &printer, int argc, const char *const *argv) const =0
 Run the command. More...
 
ace_common::FCString getName () const
 Return the name of the command.
 
ace_common::FCString getHelpString () const
 Return the help string of the command.
 

Protected Member Functions

 CommandHandler (const char *name, const char *helpString)
 Constructor. More...
 
 CommandHandler (const __FlashStringHelper *name, const __FlashStringHelper *helpString)
 Constructor. More...
 

Static Protected Member Functions

static void shiftArgcArgv (int &argc, const char *const *&argv)
 Increment argv and decrement argc so that it appears as if the command line arguments are shifted to the left by one position. More...
 
static void SHIFT_ARGC_ARGV (int &argc, const char *const *&argv)
 Backwards compatibility with previous macro implementation .
 
static bool isArgEqual (const char *arg, const char *token)
 Test for equality against token.
 
static bool isArgEqual (const char *arg, const __FlashStringHelper *token)
 Test for equality when token is in PROGMEM.
 

Detailed Description

Signature for a command handler.

Definition at line 38 of file CommandHandler.h.

Constructor & Destructor Documentation

◆ CommandHandler() [1/2]

ace_utils::cli::CommandHandler::CommandHandler ( const char *  name,
const char *  helpString 
)
inlineprotected

Constructor.

Using C strings.

Definition at line 93 of file CommandHandler.h.

◆ CommandHandler() [2/2]

ace_utils::cli::CommandHandler::CommandHandler ( const __FlashStringHelper *  name,
const __FlashStringHelper *  helpString 
)
inlineprotected

Constructor.

Using Flash strings.

Definition at line 98 of file CommandHandler.h.

Member Function Documentation

◆ run()

virtual void ace_utils::cli::CommandHandler::run ( Print &  printer,
int  argc,
const char *const *  argv 
) const
pure virtual

Run the command.

Parameters
printerThe output printer, normally Serial. This is not expected to change during the lifetime of the CommandHandler instance, so normally I would inject this parameter into the object. However, that would cause each instance to consume 2 more bytes, even though all instances are expected to have the same 'printer'. For an 8-bit AVR processor with only 2kB of RAM, every byte is important , so I am keeping this as a parameter passed into the run() method.
argcNumber of tokens in the input command, including the name of the command itself.
argvAn array of strings for each token.

◆ shiftArgcArgv()

static void ace_utils::cli::CommandHandler::shiftArgcArgv ( int &  argc,
const char *const *&  argv 
)
inlinestaticprotected

Increment argv and decrement argc so that it appears as if the command line arguments are shifted to the left by one position.

This is useful for processing the command line tokens one at a time. Use CommandHandler::isArgEqual() method to test for match against an expected token.

Definition at line 72 of file CommandHandler.h.


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