|
iash
v0.5
Library to provide a bash-like shell in an application
|
The main shell class for iash. More...
#include <iash.h>
Public Member Functions | |
| iash (const std::string &appName="iash") | |
| Creates an iash shell object with the given application name (for use in the prompt). More... | |
| Environment * | getEnv () |
| Gets the current Environment object for this shell instance. More... | |
| const Directory * | getCwd () const |
| Gets the current working directory for this shell. More... | |
| void | addCommand (Command *cmd) |
| Adds a Command instance to this shell's CommandDispatcher registry. More... | |
| template<typename ExtCommand , typename... Args> | |
| void | addCommand (Args &&... args) |
| Adds a Command instance of the given type to this shell's CommandDispatcher registry. More... | |
| int | runInteractive () |
| Runs the shell in interactive mode. More... | |
| int | runScript (const char *fname) |
| Executes the commands in the specified script and quits. More... | |
| int | exec (std::string &cmd) |
| Executes the specified command and quits. More... | |
| int | exec (UserCommand *cmd) |
| Executes the specified, already parsed command and quits. More... | |
Friends | |
| class | ExitCommand |
The main shell class for iash.
This class provides an interface to register commands with the shell, and then execute those commands in a number of ways. It also provides an interface for commands to inspect (and, to an extent, modify) the current state of the shell.
While this class has always existed, its interface was completely rewritten in v0.5. Versions that are greater than or equal to v0.5 are not backwards- compatible with prior versions.
| iash::iash | ( | const std::string & | appName = "iash" | ) |
Creates an iash shell object with the given application name (for use in the prompt).
| appName | the name of the application, to be shown in prompts and to check for in scripts |
| void iash::addCommand | ( | Command * | cmd | ) |
Adds a Command instance to this shell's CommandDispatcher registry.
This function is to be used by directly injecting dynamically allocated Command object pointers into the iash class (iash will handle the dynamic memory internally), for example:
This should not be called more than once per each unique command; the CommandDispatcher will refuse to add the repeated command.
It is not recommended that commands are registered in this way. Please use the templated iash::addCommand() instead.
| cmd | a pointer to a dynamically allocated Command object |
|
inline |
Adds a Command instance of the given type to this shell's CommandDispatcher registry.
This function will internally allocate an object of the given Command type dynamically.
This should not be called more than once per each unique command; the CommandDispatcher will refuse to add the repeated command.
| args | the arguments to pass to the Command subclass' constructor |
| int iash::exec | ( | std::string & | cmd | ) |
Executes the specified command and quits.
This does not support I/O redirection; this will do all input and output from/to stdin/stdout. To run a command with I/O redirection, use exec(UserCommand*).
| cmd | a string containing the command to execute |
|
inline |
Executes the specified, already parsed command and quits.
Command I/O is done to/from the specified streams in the UserCommand object.
| cmd | a UserCommand to execute |
| const Directory * iash::getCwd | ( | ) | const |
Gets the current working directory for this shell.
Note that this is NOT the same as the program's current working directory; this is never changed by iash. Internally, iash stores a reference to another directory that is specified by the current user to work in.
| Environment * iash::getEnv | ( | ) |
Gets the current Environment object for this shell instance.
| int iash::runInteractive | ( | ) |
Runs the shell in interactive mode.
This will print out a command prompt to stdout and read the user's commands in via stdin.
When running iash in interactive mode, this should be called directly in the return statement for main, i.e.:
| int iash::runScript | ( | const char * | fname | ) |
Executes the commands in the specified script and quits.
Command I/O will be done from/to stdin/stdout unless otherwise specified by the script.
iash scripts are identified by having this line at the top of the file:
where appname is the configured name of the application. If the @appname specifier is missing, by default iash will refuse to run the script.
| fname | the filename (absolute or relative to the application's current working directory) of the script to run. |