SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::cli::BaseCommand Class Referenceabstract

Base class for all CLI commands. More...

#include <BaseCommand.hxx>

Inheritance diagram for svcs::cli::BaseCommand:
svcs::cli::ICommand

Public Member Functions

 BaseCommand (std::shared_ptr< ISubject > subject)
 Constructor.
 ~BaseCommand () override=default
 Virtual destructor.
virtual std::string getName () const override=0
 Gets the command name (e.g., "init", "commit").
virtual std::string getDescription () const override=0
 Gets a brief description of the command.
virtual std::string getUsage () const override=0
 Gets the command's usage syntax.
void showHelp () const override
 Displays the command's help (Usage and Description).
void logDebug (const std::string &message) const
 Generates a debug information event (DEBUG_MESSAGE).
void logInfo (const std::string &message) const
 Generates a general informational event (GENERAL_INFO).
void logError (const std::string &message) const
 Generates a runtime error event (RUNTIME_ERROR).
void logSuccess (const std::string &message) const
 Generates a successful execution event (GENERAL_INFO with SUCCESS prefix).
void logWarning (const std::string &message) const
 Generates a warning event (RUNTIME_ERROR with WARNING prefix).
Public Member Functions inherited from svcs::cli::ICommand
virtual ~ICommand ()=default
 Virtual destructor.
virtual bool execute (const std::vector< std::string > &args)=0
 Executes the main logic of the command.

Static Protected Member Functions

static std::shared_ptr< RepositoryfindRepository ()
 Finds an existing repository in the current or parent directories.
static std::shared_ptr< RepositorycreateRepository (const std::string &path=".")
 Creates a new repository instance.

Protected Attributes

std::shared_ptr< ISubjecteventSubject_
 The Event Subject (Event Bus) instance.

Detailed Description

Base class for all CLI commands.

Provides a common infrastructure for interacting with the Event Bus system (ISubject) and utility methods for working with the repository. It is responsible for logging via the Event Bus.

Constructor & Destructor Documentation

◆ BaseCommand()

svcs::cli::BaseCommand::BaseCommand ( std::shared_ptr< ISubject > subject)
inline

Constructor.

Parameters
subjectThe ISubject (Event Bus) instance that will be used for generating events and logs.

◆ ~BaseCommand()

svcs::cli::BaseCommand::~BaseCommand ( )
overridedefault

Virtual destructor.

Ensures correct cleanup of derived classes.

Member Function Documentation

◆ createRepository()

std::shared_ptr< Repository > svcs::cli::BaseCommand::createRepository ( const std::string & path = ".")
inlinestaticprotected

Creates a new repository instance.

Parameters
pathThe path where the repository should be created (defaults to '.').
Returns
A smart pointer to the new Repository.

◆ findRepository()

std::shared_ptr< Repository > svcs::cli::BaseCommand::findRepository ( )
inlinestaticprotected

Finds an existing repository in the current or parent directories.

Returns
A smart pointer to the found Repository or nullptr if no repository is found.

◆ getDescription()

virtual std::string svcs::cli::BaseCommand::getDescription ( ) const
overridepure virtual

Gets a brief description of the command.

Returns
The command's description.

Implements svcs::cli::ICommand.

◆ getName()

virtual std::string svcs::cli::BaseCommand::getName ( ) const
overridepure virtual

Gets the command name (e.g., "init", "commit").

Returns
The command name as a string.

Implements svcs::cli::ICommand.

◆ getUsage()

virtual std::string svcs::cli::BaseCommand::getUsage ( ) const
overridepure virtual

Gets the command's usage syntax.

Returns
A string with the syntax (e.g., "vcs init <path>").

Implements svcs::cli::ICommand.

◆ logDebug()

void svcs::cli::BaseCommand::logDebug ( const std::string & message) const
inline

Generates a debug information event (DEBUG_MESSAGE).

Parameters
messageThe text of the debug message.

◆ logError()

void svcs::cli::BaseCommand::logError ( const std::string & message) const
inline

Generates a runtime error event (RUNTIME_ERROR).

Parameters
messageThe text of the error message.

◆ logInfo()

void svcs::cli::BaseCommand::logInfo ( const std::string & message) const
inline

Generates a general informational event (GENERAL_INFO).

Parameters
messageThe text of the informational message.

◆ logSuccess()

void svcs::cli::BaseCommand::logSuccess ( const std::string & message) const
inline

Generates a successful execution event (GENERAL_INFO with SUCCESS prefix).

Parameters
messageThe text of the successful execution message.

◆ logWarning()

void svcs::cli::BaseCommand::logWarning ( const std::string & message) const
inline

Generates a warning event (RUNTIME_ERROR with WARNING prefix).

Parameters
messageThe text of the warning message.

◆ showHelp()

void svcs::cli::BaseCommand::showHelp ( ) const
inlineoverridevirtual

Displays the command's help (Usage and Description).

This method outputs information directly to the standard output stream (stdout).

Implements svcs::cli::ICommand.

Member Data Documentation

◆ eventSubject_

std::shared_ptr<ISubject> svcs::cli::BaseCommand::eventSubject_
protected

The Event Subject (Event Bus) instance.

Used to generate events (logs) that will be received by observers, such as the Logger.


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