myshell 2.0.0
Loading...
Searching...
No Matches
msh_builtin.cpp File Reference

Built-in commands and related utilities. More...

Functions

bool is_builtin (const std::string &cmd)
 Check if a command is a built-in command.
 
bool handle_help (int argc, char **argv, const builtin_doc &doc)
 Check if help flag is present in arguments and print help message if it is.
 

Variables

const std::map< std::string, builtinbuiltin_commands
 Internal map of built-in commands.
 
std::map< std::string, std::string > aliases
 Internal map of aliases.
 

Detailed Description

Built-in commands and related utilities.

Function Documentation

◆ handle_help()

bool handle_help ( int argc,
char ** argv,
const builtin_doc & doc )

Check if help flag is present in arguments and print help message if it is.

If unknown flags are present, throws an exception intended to be caught by the internal command handler.

Parameters
argcNumber of arguments.
argvArray of arguments.
docDocumentation of the command.
Returns
True if help flag is present, false otherwise.
Exceptions
boost::program_options::errorif arguments are invalid.

◆ is_builtin()

bool is_builtin ( const std::string & cmd)

Check if a command is a built-in command.

Parameters
cmdCommand to check.
Returns
True if command is built-in, false otherwise.

Variable Documentation

◆ aliases

std::map<std::string, std::string> aliases

Internal map of aliases.

Maps alias names to their corresponding commands.

◆ builtin_commands

const std::map<std::string, builtin> builtin_commands
Initial value:
= {
{"merrno", {&merrno, 0}},
{"mpwd", {&mpwd, 0}},
{"mcd", {&mcd, 0}},
{"mexit", {&mexit, 0}},
{"mecho", {&mecho, 0}},
{"mexport", {&mexport, DECLARATION_COMMAND}},
{"msource", {&msource, 0}},
{".", {&msource, 0}},
{"malias", {&malias, DECLARATION_COMMAND}},
{"munalias", {&munalias, 0}},
{"mjobs", {&mjobs, 0}},
}

Internal map of built-in commands.

Maps command names to their corresponding built-in commands.