iash  v0.5
Library to provide a bash-like shell in an application
UserCommand.h
1 /*
2  * UserCommand.h
3  *
4  * Created on: Oct 7, 2016
5  * Author: paul
6  */
7 
8 #ifndef SRC_USERCOMMAND_H_
9 #define SRC_USERCOMMAND_H_
10 
11 #include <iostream>
12 #include <string>
13 #include <vector>
14 
15 #include "tools/Token.h"
16 
28 class UserCommand {
29 public:
39  UserCommand (const std::string &inputCommand, std::istream &in,
40  std::ostream &out);
41 
51  UserCommand (const Token &inputCommand, std::istream &in, std::ostream &out);
52  virtual ~UserCommand();
53 
54  //COMMAND INFORMATION RETRIEVAL ********************************************
55 
62  const std::vector<std::string>& getWholeCommand () const;
63 
70  std::vector<std::string> getArguments () const;
71 
85  std::vector<std::string> getOptions () const;
86 
101  bool hasOption (char opt) const;
102 
117  bool hasOption (const std::string &opt) const;
118 
135  std::string getContextualArgument (char opt) const;
136 
151  std::string getContextualArgument (std::string opt) const;
152 
159  std::istream& getStdin () const;
160 
167  std::ostream& getStdout () const;
168 private:
169  std::istream &m_stdin;
170  std::ostream &m_stdout;
171  std::vector<std::string> m_commandParts;
172  std::string m_raw;
173 };
174 
175 #endif /* SRC_USERCOMMAND_H_ */
bool hasOption(char opt) const
Returns whether the given single-letter option was specified by the user.
Definition: UserCommand.cpp:79
std::istream & getStdin() const
Gets a reference to the input stream to be used as stdin for this command invocation.
Definition: UserCommand.cpp:145
std::vector< std::string > getOptions() const
Returns all of the options/flags that the user specified (arguments with a leading - or --)...
Definition: UserCommand.cpp:57
const std::vector< std::string > & getWholeCommand() const
Returns the entire command (including the command name), parsed into arguments as a vector...
Definition: UserCommand.cpp:39
UserCommand(const std::string &inputCommand, std::istream &in, std::ostream &out)
Constructs a new UserCommand object with the given command, input, and output.
std::ostream & getStdout() const
Gets a reference to the output stream to be used as stdout for this command invocation.
Definition: UserCommand.cpp:150
Used to retain command arguments and the proper input and output streams for a command call...
Definition: UserCommand.h:28
Represents a single unit of a command language.
Definition: Token.h:23
std::string getContextualArgument(char opt) const
Finds the argument following the specified single-letter option or flag.
Definition: UserCommand.cpp:109
std::vector< std::string > getArguments() const
Returns all arguments passed by the user that are not options/switches (arguments identified with a -...
Definition: UserCommand.cpp:44