00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGA_TOOLS_COMMAND_COMMAND_HPP_
00016 #define CGA_TOOLS_COMMAND_COMMAND_HPP_ 1
00017
00020
00021 #include "cgatools/core.hpp"
00022 #include <iosfwd>
00023 #include <string>
00024 #include <boost/program_options.hpp>
00025
00026 namespace cgatools { namespace command {
00027
00028 namespace po = boost::program_options;
00029
00031 class Command
00032 {
00033 public:
00036 int operator()(int argc, char** argv);
00037
00039 void help(std::ostream& out, bool html);
00040
00042 const std::string& getName() const
00043 {
00044 return name_;
00045 }
00046
00048 const std::string& getShortDescription() const
00049 {
00050 return shortDescription_;
00051 }
00052
00053 std::string getCommandLine() const;
00054
00065 static std::string formatDescription(
00066 const std::string& description, size_t indent, size_t maxLineLength, bool html);
00067
00068 static size_t getHelpLineLength();
00069
00070 protected:
00071 Command(const std::string& name,
00072 const std::string& shortDescription,
00073 const std::string& formatVersionSupported,
00074 const std::string& longDescription);
00075
00078 virtual ~Command()
00079 {
00080 }
00081
00084 std::istream& openStdin (const std::string& path);
00085
00088 std::ostream& openStdout(const std::string& path);
00089
00092 void requireParam(const po::variables_map& vm, const std::string& param);
00093
00096 virtual int run(po::variables_map& vm) = 0;
00097
00098 private:
00099 std::string escapeArgument(const std::string& arg) const;
00100 static std::string formatLine(
00101 const std::string& line, size_t indent, size_t maxLineLength, bool html);
00102
00103 std::string name_;
00104 std::string formatVersionSupported_;
00105 std::string shortDescription_;
00106 std::string longDescription_;
00107 bool beta_;
00108 boost::shared_ptr<std::istream> myIn_;
00109 boost::shared_ptr<std::ostream> myOut_;
00110
00111 int argc_;
00112 char** argv_;
00113
00114 protected:
00115 po::options_description options_;
00116 po::options_description hiddenOptions_;
00117 po::positional_options_description positionalOptions_;
00118
00119 std::string pipelineVersion_;
00120 };
00121
00122 } }
00123
00124 #endif // CGA_TOOLS_COMMAND_COMMAND_HPP_