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
00055 std::string getCommonHeaderFileName() const;
00056
00067 static std::string formatDescription(
00068 const std::string& description, size_t indent, size_t maxLineLength, bool html);
00069
00070 static size_t getHelpLineLength();
00071
00072 protected:
00073 Command(const std::string& name,
00074 const std::string& shortDescription,
00075 const std::string& formatVersionSupported,
00076 const std::string& longDescription);
00077
00080 virtual ~Command()
00081 {
00082 }
00083
00086 std::istream& openStdin (const std::string& path);
00087
00090 std::ostream& openStdout(const std::string& path);
00091
00094 void requireParam(const po::variables_map& vm, const std::string& param);
00095
00098 virtual int run(po::variables_map& vm) = 0;
00099
00100 private:
00101 std::string escapeArgument(const std::string& arg) const;
00102 static std::string formatLine(
00103 const std::string& line, size_t indent, size_t maxLineLength, bool html);
00104
00105 std::string name_;
00106 std::string formatVersionSupported_;
00107 std::string shortDescription_;
00108 std::string longDescription_;
00109 std::string commonHeaderFileName_;
00110 bool beta_;
00111 boost::shared_ptr<std::istream> myIn_;
00112 boost::shared_ptr<std::ostream> myOut_;
00113
00114 int argc_;
00115 char** argv_;
00116
00117 protected:
00118 po::options_description options_;
00119 po::options_description hiddenOptions_;
00120 po::positional_options_description positionalOptions_;
00121 };
00122
00123 } }
00124
00125 #endif // CGA_TOOLS_COMMAND_COMMAND_HPP_