aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-26 06:21:55 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-26 06:21:55 +0000
commitc26a020654b3bd13a8719b85420a86244a43dab6 (patch)
tree6d602f24a1a9ad7d0bdba69521212a33abdb42e7
parentd68ac062d7db4c56ad144008aeb5a1ac668e7930 (diff)
downloadpaludis-c26a020654b3bd13a8719b85420a86244a43dab6.tar.gz
paludis-c26a020654b3bd13a8719b85420a86244a43dab6.tar.xz
Allow notes in client docs
-rw-r--r--paludis/args/args_handler.cc19
-rw-r--r--paludis/args/args_handler.hh15
-rw-r--r--paludis/args/man.cc47
-rw-r--r--paludis/args/man.hh12
4 files changed, 93 insertions, 0 deletions
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index b3241ce..9ee56aa 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -46,6 +46,7 @@ namespace paludis
std::list<std::string> usage_lines;
std::list<std::pair<std::string, std::string> > environment_lines;
std::list<std::pair<std::string, std::string> > example_lines;
+ std::list<std::string> notes;
std::map<std::string, ArgsOption *> longopts;
std::map<char, ArgsOption *> shortopts;
@@ -80,6 +81,12 @@ ArgsHandler::add_example(const std::string & e, const std::string & desc)
}
void
+ArgsHandler::add_note(const std::string & e)
+{
+ _imp->notes.push_back(e);
+}
+
+void
ArgsHandler::add(ArgsGroup * const g)
{
/// \bug Should check for name uniqueness.
@@ -259,6 +266,18 @@ ArgsHandler::end_examples() const
return EnvironmentLineConstIterator(_imp->example_lines.end());
}
+ArgsHandler::NotesIterator
+ArgsHandler::begin_notes() const
+{
+ return NotesIterator(_imp->notes.begin());
+}
+
+ArgsHandler::NotesIterator
+ArgsHandler::end_notes() const
+{
+ return NotesIterator(_imp->notes.end());
+}
+
ArgsHandler::ArgsGroupsConstIterator
ArgsHandler::begin_args_groups() const
{
diff --git a/paludis/args/args_handler.hh b/paludis/args/args_handler.hh
index 168be76..058ee2a 100644
--- a/paludis/args/args_handler.hh
+++ b/paludis/args/args_handler.hh
@@ -73,6 +73,11 @@ namespace paludis
void add_example(const std::string & e, const std::string & desc);
/**
+ * Add a new note.
+ */
+ void add_note(const std::string &);
+
+ /**
* Add an new ArgsGroup (called by the ArgsGroup constructor).
*/
void add(ArgsGroup * const);
@@ -206,6 +211,16 @@ namespace paludis
ArgsGroupsConstIterator end_args_groups() const;
///\}
+
+ ///\name Iterate over our notes
+ ///\{
+
+ typedef libwrapiter::ForwardIterator<ArgsHandler, const std::string > NotesIterator;
+
+ NotesIterator begin_notes() const;
+ NotesIterator end_notes() const;
+
+ ///\}
};
/**
diff --git a/paludis/args/man.cc b/paludis/args/man.cc
index 68f7f74..c71ccb3 100644
--- a/paludis/args/man.cc
+++ b/paludis/args/man.cc
@@ -19,8 +19,10 @@
#include "man.hh"
#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/tr1_functional.hh>
#include <ostream>
#include <sstream>
+#include <algorithm>
using namespace paludis;
using namespace paludis::args;
@@ -96,6 +98,8 @@ namespace
void
paludis::args::generate_doc(DocWriter & dw, const ArgsHandler * const h)
{
+ using namespace tr1::placeholders;
+
dw.heading(h->app_name(), h->man_section(), h->app_synopsis());
for (ArgsHandler::UsageLineConstIterator u(h->begin_usage_lines()),
@@ -138,6 +142,13 @@ paludis::args::generate_doc(DocWriter & dw, const ArgsHandler * const h)
dw.end_environment();
}
+ if (h->begin_notes() != h->end_notes())
+ {
+ dw.start_notes();
+ std::for_each(h->begin_notes(), h->end_notes(), tr1::bind(&DocWriter::note, &dw, _1));
+ dw.end_notes();
+ }
+
if (h->begin_examples() != h->end_examples())
{
dw.start_examples();
@@ -267,6 +278,25 @@ HtmlWriter::end_environment()
}
void
+HtmlWriter::start_notes()
+{
+ _os << "<h2>Notes</h2>" << endl;
+ _os << "<ul>" << endl;
+}
+
+void
+HtmlWriter::end_notes()
+{
+ _os << "</ul>" << endl;
+}
+
+void
+HtmlWriter::note(const std::string & s)
+{
+ _os << "<li>" << s << "</li>" << endl;
+}
+
+void
HtmlWriter::start_examples()
{
_os << "<h2>Examples</h2>" << endl;
@@ -448,6 +478,23 @@ ManWriter::end_examples()
}
void
+ManWriter::start_notes()
+{
+ _os << ".SH NOTES" << endl;
+}
+
+void
+ManWriter::note(const std::string & s)
+{
+ _os << s << endl << endl;
+}
+
+void
+ManWriter::end_notes()
+{
+}
+
+void
ManWriter::section(const std::string & title)
{
_os << ".SH " << title << endl;
diff --git a/paludis/args/man.hh b/paludis/args/man.hh
index b741bc7..7ee0101 100644
--- a/paludis/args/man.hh
+++ b/paludis/args/man.hh
@@ -79,6 +79,10 @@ namespace paludis
virtual void example(const std::string &, const std::string &) = 0;
virtual void end_examples() = 0;
+ virtual void start_notes() = 0;
+ virtual void note(const std::string &) = 0;
+ virtual void end_notes() = 0;
+
virtual void section(const std::string & title) = 0;
virtual void subsection(const std::string & title) = 0;
virtual void paragraph(const std::string & text) = 0;
@@ -131,6 +135,10 @@ namespace paludis
void example(const std::string &, const std::string &);
void end_examples();
+ void start_notes();
+ void note(const std::string &);
+ void end_notes();
+
void section(const std::string & title);
void subsection(const std::string & title);
void paragraph(const std::string & text);
@@ -181,6 +189,10 @@ namespace paludis
void example(const std::string &, const std::string &);
void end_examples();
+ void start_notes();
+ void note(const std::string &);
+ void end_notes();
+
void section(const std::string & title);
void subsection(const std::string & title);
void paragraph(const std::string & text);