diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-18 12:50:12 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-01-18 12:52:25 +0200 |
commit | 5a01a260c368d3045f0870cc09620a772027e911 (patch) | |
tree | 504d6d3d1504d0c8e180d1f36eed17b2a3fff07a /cli/generator.cxx | |
parent | 650ea3bd3bac1fa50f9c8566d5def774c5eb2fee (diff) |
Initial support for plain text documentation (--generate-txt)
Support for option documentation generation is still a TODO.
Diffstat (limited to 'cli/generator.cxx')
-rw-r--r-- | cli/generator.cxx | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/cli/generator.cxx b/cli/generator.cxx index b086089..486c793 100644 --- a/cli/generator.cxx +++ b/cli/generator.cxx @@ -23,6 +23,7 @@ #include "man.hxx" #include "html.hxx" +#include "txt.hxx" #include "context.hxx" #include "generator.hxx" @@ -122,8 +123,9 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) bool gen_cxx (ops.generate_cxx ()); bool gen_man (ops.generate_man ()); bool gen_html (ops.generate_html ()); + bool gen_txt (ops.generate_txt ()); - if (!gen_cxx && !gen_man && !gen_html) + if (!gen_cxx && !gen_man && !gen_html && !gen_txt) gen_cxx = true; if (ops.stdout_ ()) @@ -134,9 +136,11 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) throw failed (); } - if (gen_man && gen_html) + if ((gen_man && gen_html) || + (gen_man && gen_txt) || + (gen_html && gen_txt)) { - cerr << "error: --stdout cannot be used with man and html output" + cerr << "error: --stdout cannot only be used with one output format" << endl; throw failed (); } @@ -463,6 +467,43 @@ generate (options const& ops, semantics::cli_unit& unit, path const& p) append (os, ops.html_epilogue (), ops.html_epilogue_file (), unit); } + // txt output + // + if (gen_txt) + { + ofstream txt; + + if (!ops.stdout_ ()) + { + path txt_path (pfx + base + sfx + ops.txt_suffix ()); + + if (!ops.output_dir ().empty ()) + txt_path = path (ops.output_dir ()) / txt_path; + + txt.open (txt_path.string ().c_str ()); + + if (!txt.is_open ()) + { + cerr << "error: unable to open '" << txt_path << "' in write mode" + << endl; + throw failed (); + } + + auto_rm.add (txt_path); + } + + // The explicit cast helps VC++ 8.0 overcome its issues. + // + ostream& os (ops.stdout_ () ? cout : static_cast<ostream&> (txt)); + + append (os, ops.txt_prologue (), ops.txt_prologue_file (), unit); + + context ctx (os, unit, ops); + generate_txt (ctx); + + append (os, ops.txt_epilogue (), ops.txt_epilogue_file (), unit); + } + auto_rm.cancel (); } catch (const generation_failed&) |