Sharg 1.1.2-rc.1
The argument parser for bio-c++ tools.
Loading...
Searching...
No Matches
format_man.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
13
14namespace sharg::detail
15{
16
30class format_man : public format_help_base<format_man>
31{
33 using base_type = format_help_base<format_man>;
34
36 friend base_type;
37
38public:
42 format_man() = default;
43 format_man(format_man const & pf) = default;
44 format_man & operator=(format_man const & pf) = default;
45 format_man(format_man &&) = default;
46 format_man & operator=(format_man &&) = default;
47 ~format_man() = default;
48
50 format_man(std::vector<std::string> const & names,
51 update_notifications const version_updates,
52 bool const advanced = false) :
53 base_type{names, version_updates, advanced} {};
55
56private:
58 void print_header()
59 {
61
62 // Print .TH line.
63 std::cout << ".TH ";
64 std::transform(meta.app_name.begin(),
65 meta.app_name.end(),
66 out,
67 [](unsigned char c)
68 {
69 return std::toupper(c);
70 });
71 std::cout << " " << std::to_string(meta.man_page_section) << " \"" << meta.date << "\" \"";
72 std::transform(meta.app_name.begin(),
73 meta.app_name.end(),
74 out,
75 [](unsigned char c)
76 {
77 return std::tolower(c);
78 });
79 std::cout << " " << meta.version << "\" \"" << meta.man_page_title << "\"\n";
80
81 // Print NAME section.
82 std::cout << ".SH NAME\n" << meta.app_name << " \\- " << meta.short_description << std::endl;
83 }
84
88 void print_section(std::string const & title)
89 {
91 std::cout << ".SH ";
92 std::transform(title.begin(),
93 title.end(),
94 out,
95 [](unsigned char c)
96 {
97 return std::toupper(c);
98 });
99 std::cout << "\n";
100 is_first_in_section = true;
101 }
102
106 void print_subsection(std::string const & title)
107 {
108 std::cout << ".SS " << title << "\n";
109 is_first_in_section = true;
110 }
111
118 void print_line(std::string const & text, bool const line_is_paragraph)
119 {
120 if (!is_first_in_section && line_is_paragraph)
121 std::cout << ".sp\n";
122 else if (!is_first_in_section && !line_is_paragraph)
123 std::cout << ".br\n";
124
125 std::cout << text << "\n";
126 is_first_in_section = false;
127 }
128
138 void print_list_item(std::string const & term, std::string const & desc)
139 {
140 std::cout << ".TP\n" << term << "\n" << desc << "\n";
141 is_first_in_section = false;
142 }
143
145 void print_footer()
146 {
147 // no footer
148 }
149
154 std::string in_bold(std::string const & str)
155 {
156 return "\\fB" + str + "\\fR";
157 }
158
160 bool is_first_in_section{true};
161};
162
163} // namespace sharg::detail
T begin(T... args)
T end(T... args)
T endl(T... args)
Provides the format_base struct containing all helper functions that are needed in all formats.
update_notifications
Indicates whether application allows automatic update notifications by the sharg::parser.
Definition auxiliary.hpp:26
T to_string(T... args)
T transform(T... args)
Hide me