Skip to content

Command

#include <tpau-cpp-kernal/Command.h>

INCLUDE FILE
#include <tpau-cpp-kernal/Command.h>

class Command

Base class for command line programs.

It only produces the output files if no errors occurred during processing.

DEFINITION
class Command;

enum Feature

Optional features a subclass can enable.

DEFINITION
enum Feature;
VALUEDESCRIPTION
OutputFile

The command creates an output file.

This adds the --output command line option and the subclass must implement the create_output() method to create the output file.

DependencyFile

The command can create a gcc style dependency file.

This option requires the OutputFile feature to be enabled.

This adds the --dependency-file command line option.

TODO: Implement the tracking of dependencies and the creation of the dependency file.

constructor Command

Create a command line program with the given options and arguments.

DEFINITION
Command ( const std::vector< Commandline::Option > & options,
std::string  arguments,
std::string_view  name,
FlagSet< Feature >  features = FlagSet< Feature >{} );
PARAMETERDESCRIPTION
options

The option definitions for the program.

arguments

The argument names for the program.

name

The name of the program.

features

The features to enable for the program.

method create_outputvirtual

Create the output files for the command.

If the feature OutputFile is enabled, this method must be implemented by subclasses to create the output files. It will only be called if no errors occurred during processing.

DEFINITION
virtual int  create_output ( );
RETURNSDESCRIPTION
int

A non-zero value indicates an error occurred during output creation and will be used as the exit code.

method maximum_argumentsvirtual

Get the maximum number of arguments allowed for the command.

This method can be overridden by subclasses.

DEFINITION
virtual size_t  maximum_arguments ( );
RETURNSDESCRIPTION
size_t

The maximum number of arguments allowed for the command. The default is the maximum value of size_t, representing unlimited.

method minimum_argumentsvirtual

Get the minimum number of arguments required for the command.

This method can be overridden by subclasses.

DEFINITION
virtual size_t  minimum_arguments ( );
RETURNSDESCRIPTION
size_t

The minimum number of arguments required for the command. The default is 0.

method processvirtual

Process the command line arguments and options.

This method must be implemented by subclasses to perform the actual processing of the command.

DEFINITION
virtual int  process ( ) = 0;
RETURNSDESCRIPTION
int

A non-zero value indicates an error occurred during processing and will be used as the exit code.

method run

Run the command line program with the given arguments.

DEFINITION
int  run ( int  argc,
char *const  argv );
PARAMETERDESCRIPTION
argc

The number of arguments.

argv

The arguments.

RETURNSDESCRIPTION
int

The exit code of the program.

member arguments

The parsed command line arguments and options.

DEFINITION
ParsedCommandline  arguments;

member commandline

The command line parser for the command.

DEFINITION
Commandline  commandline;

member dependency_file

The name of the dependency file.

DEFINITION
std::optional< std::filesystem::path >  dependency_file;

member features

The features enabled for the command.

DEFINITION
FlagSet< Feature >  features;

member output_file

The name of the output file.

DEFINITION
std::optional< std::filesystem::path >  output_file;

member program_name

The name of the program.

DEFINITION
std::string  program_name;