wibble
0.1.28
|
00001 #ifndef WIBBLE_COMMANDLINE_DOC_H 00002 #define WIBBLE_COMMANDLINE_DOC_H 00003 00004 #include <wibble/commandline/parser.h> 00005 #include <string> 00006 #include <vector> 00007 #include <ostream> 00008 00009 namespace wibble { 00010 namespace commandline { 00011 00012 class HelpWriter; 00013 00014 class DocMaker 00015 { 00016 protected: 00017 std::string m_app; 00018 std::string m_ver; 00019 00020 public: 00021 DocMaker(const std::string& app, const std::string& ver) 00022 : m_app(app), m_ver(ver) {} 00023 }; 00024 00025 class Help : public DocMaker 00026 { 00027 protected: 00028 void outputOptions(std::ostream& out, HelpWriter& writer, const Engine& cp); 00029 00030 public: 00031 Help(const std::string& app, const std::string& ver) 00032 : DocMaker(app, ver) {} 00033 00034 void outputVersion(std::ostream& out); 00035 void outputHelp(std::ostream& out, const Engine& cp); 00036 }; 00037 00038 class Manpage : public DocMaker 00039 { 00040 public: 00041 enum where { BEFORE, BEGINNING, END }; 00042 00043 private: 00044 struct Hook 00045 { 00046 std::string section; 00047 where placement; 00048 std::string text; 00049 00050 Hook(const std::string& section, where placement, const std::string& text) 00051 : section(section), placement(placement), text(text) {} 00052 }; 00053 00054 int m_section; 00055 std::string m_author; 00056 00057 std::vector<Hook> hooks; 00058 std::string lastSection; 00059 00060 void outputParagraph(std::ostream& out, const std::string& str); 00061 void outputOption(std::ostream& out, const Option* o); 00062 void outputOptions(std::ostream& out, const Engine& p); 00063 void runHooks(std::ostream& out, const std::string& section, where where); 00064 void startSection(std::ostream& out, const std::string& name); 00065 void endSection(std::ostream& out); 00066 00067 00068 public: 00069 Manpage(const std::string& app, const std::string& ver, int section, const std::string& author) 00070 : DocMaker(app, ver), m_section(section), m_author(author) {} 00071 00072 void addHook(const std::string& section, where placement, const std::string& text) 00073 { 00074 hooks.push_back(Hook(section, placement, text)); 00075 } 00076 void readHooks(const std::string& file); 00077 00078 void output(std::ostream& out, const Engine& cp); 00079 }; 00080 00081 } 00082 } 00083 00084 // vim:set ts=4 sw=4: 00085 #endif