Sharg 1.1.1
The argument parser for bio-c++ tools.
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages Concepts
Loading...
Searching...
No Matches
format_man.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/sharg-parser/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------------
7
13#pragma once
14
16
17namespace sharg::detail
18{
19
33class format_man : public format_help_base<format_man>
34{
36 using base_type = format_help_base<format_man>;
37
39 friend base_type;
40
41public:
45 format_man() = default;
46 format_man(format_man const & pf) = default;
47 format_man & operator=(format_man const & pf) = default;
48 format_man(format_man &&) = default;
49 format_man & operator=(format_man &&) = default;
50 ~format_man() = default;
51
53 format_man(std::vector<std::string> const & names,
54 update_notifications const version_updates,
55 bool const advanced = false) :
56 base_type{names, version_updates, advanced} {};
58
59private:
61 void print_header()
62 {
64
65 // Print .TH line.
66 std::cout << ".TH ";
67 std::transform(meta.app_name.begin(),
68 meta.app_name.end(),
69 out,
70 [](unsigned char c)
71 {
72 return std::toupper(c);
73 });
74 std::cout << " " << std::to_string(meta.man_page_section) << " \"" << meta.date << "\" \"";
75 std::transform(meta.app_name.begin(),
76 meta.app_name.end(),
77 out,
78 [](unsigned char c)
79 {
80 return std::tolower(c);
81 });
82 std::cout << " " << meta.version << "\" \"" << meta.man_page_title << "\"\n";
83
84 // Print NAME section.
85 std::cout << ".SH NAME\n" << meta.app_name << " \- " << meta.short_description << std::endl;
86 }
87
91 void print_section(std::string const & title)
92 {
94 std::cout << ".SH ";
95 std::transform(title.begin(),
96 title.end(),
97 out,
98 [](unsigned char c)
99 {
100 return std::toupper(c);
101 });
102 std::cout << "\n";
103 is_first_in_section = true;
104 }
105
109 void print_subsection(std::string const & title)
110 {
111 std::cout << ".SS " << title << "\n";
112 is_first_in_section = true;
113 }
114
121 void print_line(std::string const & text, bool const line_is_paragraph)
122 {
123 if (!is_first_in_section && line_is_paragraph)
124 std::cout << ".sp\n";
125 else if (!is_first_in_section && !line_is_paragraph)
126 std::cout << ".br\n";
127
128 std::cout << text << "\n";
129 is_first_in_section = false;
130 }
131
141 void print_list_item(std::string const & term, std::string const & desc)
142 {
143 std::cout << ".TP\n" << term << "\n" << desc << "\n";
144 is_first_in_section = false;
145 }
146
148 void print_footer()
149 {
150 // no footer
151 }
152
157 std::string in_bold(std::string const & str)
158 {
159 return "\fB" + str + "\fR";
160 }
161
163 bool is_first_in_section{true};
164};
165
166} // 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:29
T to_string(T... args)
T transform(T... args)