# # # patch "cmd.cc" # from [f5123df5fcf8bddbc2d1c7328020e63afaf0c97f] # to [b0c21243f7f344006c05aebb2b4f5c9f9ee6ccfd] # # patch "lua_hooks.cc" # from [c8023d8f41b5ac29e7f1a6831c3349875ea0038e] # to [a71ded3aabcde9e0ef7281b7c56f2ff1fa6baaec] # # patch "lua_hooks.hh" # from [25624ede9904749728389df1f3a4fc1599ebae56] # to [66b79c7d1dcefed2d3530e71474346b72417fee9] # # patch "std_hooks.lua" # from [32781b7b525432e0e230aaa2ece7e24e6a8ef7ec] # to [05e8c1f23e11bbc7860baa201787c0ca603fcd52] # ============================================================ --- cmd.cc f5123df5fcf8bddbc2d1c7328020e63afaf0c97f +++ cmd.cc b0c21243f7f344006c05aebb2b4f5c9f9ee6ccfd @@ -23,16 +23,19 @@ #ifndef _WIN32 #include +#include #endif #include +#include using std::string; +using std::stringstream; using std::vector; using std::set; using std::ostream; using std::make_pair; -using std::cout +using std::cout; using boost::lexical_cast; // @@ -677,7 +680,9 @@ get_options_string(options::options_type vector descriptions; unsigned int maxnamelen; - optset.instantiate(&opts).get_usage_strings(names, descriptions, maxnamelen); + optset.instantiate(&opts).get_usage_strings( + names, descriptions, maxnamelen, opts.show_hidden_commands + ); string out; vector::const_iterator name; @@ -847,61 +852,80 @@ get_command_groups(options & opts) return out; } -CMD_HIDDEN(manpage, "manpage", "", CMD_REF(informative), "", - N_("Dumps monotone's command tree in a (g)roff compatible format"), +CMD_NO_WORKSPACE(manpage, "manpage", "", CMD_REF(informative), "", + N_("Displays monotone's command help as manual page"), "", options::opts::show_hidden_commands) { - cout << man_title("monotone"); - cout << man_section(_("Name")); + stringstream ss; + ss << man_title("monotone"); + ss << man_section(_("Name")); - cout << _("monotone - a distributed version control system") << "\n"; - cout << man_section(_("Synopsis")); - cout << man_bold(prog_name) << " " - << man_italic(_("[options...] command [arguments...]")) - << "\n"; + ss << _("monotone - a distributed version control system") << "\n"; + ss << man_section(_("Synopsis")); + ss << man_bold(prog_name) << " " + << man_italic(_("[options...] command [arguments...]")) + << "\n"; - cout << man_section(_("Description")); - cout << _("monotone is a highly reliable, very customizable distributed " - "version control system that provides lightweight branches, " - "history-sensitive merging and a flexible trust setup. " - "monotone has an easy-to-learn command set and comes with a rich " - "interface for scripting purposes and thorough documentation.") - << "\n\n"; - cout << (F("For more information on monotone, visit %s.") - % man_bold("http://www.monotone.ca")).str() - << "\n\n"; - cout << (F("The complete documentation, including a tutorial for a quick start " - "with the system, can be found online on %s.") - % man_bold("http://www.monotone.ca/docs")).str() << "\n"; + ss << man_section(_("Description")); + ss << _("monotone is a highly reliable, very customizable distributed " + "version control system that provides lightweight branches, " + "history-sensitive merging and a flexible trust setup. " + "monotone has an easy-to-learn command set and comes with a rich " + "interface for scripting purposes and thorough documentation.") + << "\n\n"; + ss << (F("For more information on monotone, visit %s.") + % man_bold("http://www.monotone.ca")).str() + << "\n\n"; + ss << (F("The complete documentation, including a tutorial for a quick start " + "with the system, can be found online on %s.") + % man_bold("http://www.monotone.ca/docs")).str() << "\n"; - cout << man_section(_("Global Options")); - cout << get_options_string(options::opts::globals(), app.opts, 25) << "\n"; + ss << man_section(_("Global Options")); + ss << get_options_string(options::opts::globals(), app.opts, 25) << "\n"; - cout << man_section(_("Commands")); - cout << get_command_groups(app.opts); + ss << man_section(_("Commands")); + ss << get_command_groups(app.opts); - cout << man_section(_("See Also")); - cout << (F("info %s and the documentation on %s") - % prog_name % man_bold("http://monotone.ca/docs")).str() << "\n"; + ss << man_section(_("See Also")); + ss << (F("info %s and the documentation on %s") + % prog_name % man_bold("http://monotone.ca/docs")).str() << "\n"; - cout << man_section("Bugs"); - cout << (F("Please report bugs to %s.") - % man_bold("http://savannah.nongnu.org/bugs/?group=monotone")).str()<< "\n"; + ss << man_section("Bugs"); + ss << (F("Please report bugs to %s.") + % man_bold("http://savannah.nongnu.org/bugs/?group=monotone")).str()<< "\n"; - cout << man_section("Authors"); - cout << _("monotone was written originally by Graydon Hoare " - " in 2004 and has since then received " - "numerous contributions from many individuals. " - "A complete list of authors can be found in AUTHORS.") - << "\n\n"; - cout << _("Nowadays, monotone is maintained by a collective of enthusiastic " - "programmers, known as the monotone developement team.") << "\n"; + ss << man_section("Authors"); + ss << _("monotone was written originally by Graydon Hoare " + " in 2004 and has since then received " + "numerous contributions from many individuals. " + "A complete list of authors can be found in AUTHORS.") + << "\n\n"; + ss << _("Nowadays, monotone is maintained by a collective of enthusiastic " + "programmers, known as the monotone developement team.") << "\n"; - cout << man_section("Copyright"); - cout << (F("monotone and this man page is Copyright (c) 2004 - %s by " - "the monotone development team.") - % date_t::now().as_formatted_localtime("%Y")).str() << "\n"; + ss << man_section("Copyright"); + ss << (F("monotone and this man page is Copyright (c) 2004 - %s by " + "the monotone development team.") + % date_t::now().as_formatted_localtime("%Y")).str() << "\n"; + + if (!isatty(STDOUT_FILENO)) + { + cout << ss.str(); + return; + } + + string cmd; + E(app.lua.hook_get_man_page_formatter_command(cmd) && !cmd.empty(), + origin::user, F("no man page formatter command configured")); + + FILE * fp = popen(cmd.c_str(), "w"); + E(fp != NULL, origin::system, + F("could not execute man page formatter command '%s': %s") + % cmd % strerror(errno)); + + I(fprintf(fp, ss.str().c_str()) != -1); + pclose(fp); } // There isn't really a better place for this function. ============================================================ --- lua_hooks.cc c8023d8f41b5ac29e7f1a6831c3349875ea0038e +++ lua_hooks.cc a71ded3aabcde9e0ef7281b7c56f2ff1fa6baaec @@ -743,6 +743,19 @@ bool } bool +lua_hooks::hook_get_man_page_formatter_command(string & command) +{ + bool exec_ok + = Lua(st) + .func("get_man_page_formatter_command") + .call(0, 1) + .extract_str(command) + .ok(); + + return exec_ok; +} + +bool lua_hooks::hook_use_inodeprints() { bool use = false, exec_ok = false; ============================================================ --- lua_hooks.hh 25624ede9904749728389df1f3a4fc1599ebae56 +++ lua_hooks.hh 66b79c7d1dcefed2d3530e71474346b72417fee9 @@ -160,11 +160,13 @@ public: bool & validated, string & reason); - // meta hooks + // misc hooks bool hook_hook_wrapper(string const & func_name, vector const & args, string & out); + bool hook_get_man_page_formatter_command(string & command); + // notification hooks bool hook_note_commit(revision_id const & new_id, revision_data const & rdat, ============================================================ --- std_hooks.lua 32781b7b525432e0e230aaa2ece7e24e6a8ef7ec +++ std_hooks.lua 05e8c1f23e11bbc7860baa201787c0ca603fcd52 @@ -1462,3 +1462,8 @@ end return false end + +function get_man_page_formatter_command() + return "nroff -man -Tutf8 | less -R" +end +