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{
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;
47 ~format_man() = default;
48
51 update_notifications const version_updates,
52 bool const advanced = false) :
53 base_type{names, version_updates, advanced} {};
55
56private:
59 {
61
62 // Print .TH line.
63 std::cout << ".TH ";
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 << "\" \"";
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
146 {
147 // no footer
148 }
149
155 {
156 return "\\fB" + str + "\\fR";
157 }
158
161};
162
163} // namespace sharg::detail
T begin(T... args)
The format that contains all helper functions needed in all formats for printing the interface descri...
Definition format_base.hpp:248
parser_meta_data meta
Stores all meta information about the application.
Definition format_base.hpp:508
The format that prints the help page information formatted for a man page to std::cout.
Definition format_man.hpp:31
format_man(format_man const &pf)=default
Defaulted.
format_man & operator=(format_man const &pf)=default
Defaulted.
format_man(std::vector< std::string > const &names, update_notifications const version_updates, bool const advanced=false)
Defaulted.
Definition format_man.hpp:50
void print_footer()
Prints a help page footer in man page format.
Definition format_man.hpp:145
format_man & operator=(format_man &&)=default
Defaulted.
void print_section(std::string const &title)
Prints a section title in man page format to std::cout.
Definition format_man.hpp:88
void print_header()
Prints a help page header in man page format to std::cout.
Definition format_man.hpp:58
std::string in_bold(std::string const &str)
Format string as in_bold.
Definition format_man.hpp:154
void print_line(std::string const &text, bool const line_is_paragraph)
Prints a help page section in man page format to std::cout.
Definition format_man.hpp:118
bool is_first_in_section
Needed for correct indentation and line breaks.
Definition format_man.hpp:160
~format_man()=default
Defaulted.
friend base_type
Befriend the base class to give access to the private member functions.
Definition format_man.hpp:36
void print_list_item(std::string const &term, std::string const &desc)
Prints a help page list_item in man page format to std::cout.
Definition format_man.hpp:138
format_man()=default
Defaulted.
format_man(format_man &&)=default
Defaulted.
void print_subsection(std::string const &title)
Prints a subsection title in man page format to std::cout.
Definition format_man.hpp:106
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
std::string short_description
A short description of the application (e.g. "A tool for mapping reads to the genome").
Definition auxiliary.hpp:57
std::string app_name
The application name that will be displayed on the help page.
Definition auxiliary.hpp:51
std::string version
The version information MAJOR.MINOR.PATH (e.g. 3.1.3)
Definition auxiliary.hpp:54
std::string man_page_title
The title of your man page when exported by specifying "--export-help man" on the common line.
Definition auxiliary.hpp:87
std::string date
The date that the application was last updated. Keep this updated, ! since it will tell your users th...
Definition auxiliary.hpp:68
unsigned man_page_section
The man page section info (type man man on the command line for more information).
Definition auxiliary.hpp:90
T to_string(T... args)
T transform(T... args)
Hide me