13
13
#pragma once
14
14
15
15
#include < sharg/detail/format_base.hpp>
16
+ #include < sharg/test/tmp_filename.hpp>
16
17
17
18
namespace sharg ::detail
18
19
{
@@ -38,6 +39,9 @@ class format_man : public format_help_base<format_man>
38
39
// !\brief Befriend the base class to give access to the private member functions.
39
40
friend base_type;
40
41
42
+ // !\brief Whether to call man and open the man page.
43
+ bool open_man_page{false };
44
+
41
45
public:
42
46
/* !\name Constructors, destructor and assignment
43
47
* \{
@@ -52,10 +56,35 @@ class format_man : public format_help_base<format_man>
52
56
// !\copydoc sharg::detail::format_help_base::format_help_base
53
57
format_man (std::vector<std::string> const & names,
54
58
update_notifications const version_updates,
55
- bool const advanced = false ) :
56
- base_type{names, version_updates, advanced} {};
59
+ bool const advanced = false ,
60
+ bool const open_man_page = false ) :
61
+ base_type{names, version_updates, advanced},
62
+ open_man_page{open_man_page} {};
57
63
// !\}
58
64
65
+ void parse (parser_meta_data & parser_meta)
66
+ {
67
+ if (!open_man_page)
68
+ return base_type::parse (parser_meta);
69
+
70
+ sharg::test::tmp_filename tmp_file{parser_meta.app_name .c_str ()};
71
+
72
+ {
73
+ std::ofstream out{tmp_file.get_path ()};
74
+ std::streambuf * coutbuf = std::cout.rdbuf ();
75
+ std::cout.rdbuf (out.rdbuf ());
76
+
77
+ base_type::parse (parser_meta);
78
+
79
+ std::cout.rdbuf (coutbuf);
80
+ }
81
+
82
+ std::string command{" /usr/bin/man -l " };
83
+ command += tmp_file.get_path ().c_str ();
84
+ if (std::system (command.c_str ()) != 0 )
85
+ throw sharg::parser_error{" Unexpected failure." }; // LCOV_EXCL_LINE
86
+ }
87
+
59
88
private:
60
89
// !\brief Prints a help page header in man page format to std::cout.
61
90
void print_header ()
0 commit comments