|
iash
v0.5
Library to provide a bash-like shell in an application
|
Used to retain command arguments and the proper input and output streams for a command call. More...
#include <UserCommand.h>
Public Member Functions | |
| UserCommand (const std::string &inputCommand, std::istream &in, std::ostream &out) | |
| Constructs a new UserCommand object with the given command, input, and output. More... | |
| UserCommand (const Token &inputCommand, std::istream &in, std::ostream &out) | |
| Constructs a new UserCommand object with the given command, input, and output. More... | |
| const std::vector< std::string > & | getWholeCommand () const |
| Returns the entire command (including the command name), parsed into arguments as a vector. More... | |
| std::vector< std::string > | getArguments () const |
Returns all arguments passed by the user that are not options/switches (arguments identified with a - or -- at the beginning). More... | |
| std::vector< std::string > | getOptions () const |
Returns all of the options/flags that the user specified (arguments with a leading - or --). More... | |
| bool | hasOption (char opt) const |
| Returns whether the given single-letter option was specified by the user. More... | |
| bool | hasOption (const std::string &opt) const |
| Returns whether the given whole-word option was specified by the user. More... | |
| std::string | getContextualArgument (char opt) const |
| Finds the argument following the specified single-letter option or flag. More... | |
| std::string | getContextualArgument (std::string opt) const |
| Finds the argument following the specified multi-character option or flag. More... | |
| std::istream & | getStdin () const |
| Gets a reference to the input stream to be used as stdin for this command invocation. More... | |
| std::ostream & | getStdout () const |
| Gets a reference to the output stream to be used as stdout for this command invocation. More... | |
Used to retain command arguments and the proper input and output streams for a command call.
Note that, with the exception of UserCommand::getWholeCommand, all of the functions that retrieve options or arguments from the user's command input iterate over the internal vector used to store it, and thus may slow down your program if they are called too often.
| UserCommand::UserCommand | ( | const std::string & | inputCommand, |
| std::istream & | in, | ||
| std::ostream & | out | ||
| ) |
Constructs a new UserCommand object with the given command, input, and output.
This also invokes the command parser, parsing the user's command into its components. (This does not parse out the command's options).
| inputCommand | the command the user input |
| in | the stream to use as stdin for the command |
| out | the stream to use as out for the command |
| UserCommand::UserCommand | ( | const Token & | inputCommand, |
| std::istream & | in, | ||
| std::ostream & | out | ||
| ) |
Constructs a new UserCommand object with the given command, input, and output.
This also invokes the command parser, parsing the user's command into its components. (This does not parse out the command's options).
| inputCommand | the command the user input as a Token |
| in | the stream to use as stdin for the command |
| out | the stream to use as stdout for the command |
| vector< string > UserCommand::getArguments | ( | ) | const |
Returns all arguments passed by the user that are not options/switches (arguments identified with a - or -- at the beginning).
| string UserCommand::getContextualArgument | ( | char | opt | ) | const |
Finds the argument following the specified single-letter option or flag.
If the specified option does not have an argument that follows it, or the option is embedded in a chained single-letter argument and is not at the end (for example, c in -abcde), then this will return an empty string.
Note that this does not guarantee that the returned argument is actually specifying a parameter for the given option. In order to insure this, Command::validate should be overridden to check that the command structure is valid.
| opt | the single-letter option to find a contextual argument for |
| std::string UserCommand::getContextualArgument | ( | std::string | opt | ) | const |
Finds the argument following the specified multi-character option or flag.
If the specified option dooes not have an argument that follows it, then this will return an empty string.
Note that this does not guarantee that the returned argument is actually specifying a parameter for the given option. In order to insure this, Command::validate should be overridden to check that the command structure is valid.
| opt | a multi-character option to find a contextual argument for |
| vector< string > UserCommand::getOptions | ( | ) | const |
Returns all of the options/flags that the user specified (arguments with a leading - or --).
Note that iash option syntax allows users to chain single-letter options together (like -abcde), and will report all of the characters present after a single minus as individual options (so, in this example, a, b, c, d, e will all be reported as options). If you want iash to report whole words as options, have users enter them with a double-minus prefix (so --abcde will be reported as abcde).
| istream & UserCommand::getStdin | ( | ) | const |
Gets a reference to the input stream to be used as stdin for this command invocation.
| ostream & UserCommand::getStdout | ( | ) | const |
Gets a reference to the output stream to be used as stdout for this command invocation.
| const vector< string > & UserCommand::getWholeCommand | ( | ) | const |
Returns the entire command (including the command name), parsed into arguments as a vector.
| bool UserCommand::hasOption | ( | char | opt | ) | const |
Returns whether the given single-letter option was specified by the user.
Note that iash option syntax allows users to chain single-letter options together (like -abcde), and will report all of the characters present after a single minus as individual options (so, in this example, a, b, c, d, e will all be reported as options). If you want iash to report whole words as options, have users enter them with a double-minus prefix (so --abcde will be reported as abcde).
@param opt the single-letter option to check for @return whether the option was passed by the user
| bool UserCommand::hasOption | ( | const std::string & | opt | ) | const |
Returns whether the given whole-word option was specified by the user.
Note that iash option syntax allows users to chain single-letter options together (like -abcde), and will report all of the characters present after a single minus as individual options (so, in this example, a, b, c, d, e will all be reported as options). If you want iash to report whole words as options, have users enter them with a double-minus prefix (so --abcde will be reported as abcde).
@param opt the whole-word option to check for @return whether the option was passed by the user