Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beautify with clang-format #75

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
332 changes: 150 additions & 182 deletions data/single_include/lyra/lyra.hpp

Large diffs are not rendered by default.

43 changes: 21 additions & 22 deletions examples/combined_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
using namespace lyra;
bool show_help = false;
Expand All @@ -24,27 +24,26 @@ int main(int argc, const char** argv)
} config;
auto parser
= help(show_help).description(
"This is a combined sample CLI parser. It takes varied options"
"and arguments.")
| opt(config.seed, "time|value")
["--rng-seed"]["-r"]("Set a specific seed for random numbers.")
.required()
| opt(config.name, "name")
["-n"]["--name"]("The name to use.")
| opt(config.flag)
["-f"]["--flag"]("A flag to set.")
| opt([&](double value) { config.value = value; }, "number")
["-d"]["--double"]("Just some number.")
| arg(config.tests, "test name|tags|pattern")("Which test or tests to use.").required()
| opt(config.choice, "1-10")
["-c"]["--choice"]("A choice from 1 to 10.")
.choices([](int value) -> bool { return 1 <= value && value <= 10; });
parser.add_argument(
opt(config.color, "red|green|blue")
.name("-k")
.name("--color")
.help("A primary color.")
.choices("red", "green", "blue"));
"This is a combined sample CLI parser. It takes varied options"
"and arguments.")
| opt(config.seed, "time|value")["--rng-seed"]["-r"](
"Set a specific seed for random numbers.")
.required()
| opt(config.name, "name")["-n"]["--name"]("The name to use.")
| opt(config.flag)["-f"]["--flag"]("A flag to set.")
| opt([&](double value) { config.value = value; },
"number")["-d"]["--double"]("Just some number.")
| arg(config.tests, "test name|tags|pattern")(
"Which test or tests to use.")
.required()
| opt(config.choice, "1-10")["-c"]["--choice"]("A choice from 1 to 10.")
.choices(
[](int value) -> bool { return 1 <= value && value <= 10; });
parser.add_argument(opt(config.color, "red|green|blue")
.name("-k")
.name("--color")
.help("A primary color.")
.choices("red", "green", "blue"));

auto result = parser.parse({ argc, argv });

Expand Down
11 changes: 4 additions & 7 deletions examples/count_flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt)
*/


/* tag::doc[]

= Counting Flags
Expand All @@ -28,12 +27,10 @@ end::doc[] */
int main(int argc, const char ** argv)
{
int verbose = 0; // <1>
return lyra::main()
(lyra::opt(
[&](bool){ verbose += 1; }) // <2>
["-v"].cardinality(0,5)) // <3>
(argc, argv, [&](lyra::main &)
{
return lyra::main()(lyra::opt([&](bool) { verbose += 1; }) // <2>
["-v"]
.cardinality(0, 5)) // <3>
(argc, argv, [&](lyra::main &) {
std::cout << verbose << "\n"; // <4>
return 0;
});
Expand Down
5 changes: 2 additions & 3 deletions examples/doc_example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
// Where we read in the argument value:
int width = 0;

// The parser with the one option argument:
auto cli = lyra::cli()
| lyra::opt(width, "width")
["-w"]["--width"]("How wide should it be?");
| lyra::opt(width, "width")["-w"]["--width"]("How wide should it be?");

// ...
// end::part1[]
Expand Down
11 changes: 5 additions & 6 deletions examples/doc_example1_alt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
// Where we read in the argument value:
int width = 0;

// The parser with the one option argument:
auto cli = lyra::cli();
cli.add_argument(
lyra::opt(width, "width")
.name("-w")
.name("--width")
.help("How wide should it be?"));
cli.add_argument(lyra::opt(width, "width")
.name("-w")
.name("--width")
.help("How wide should it be?"));

// Parse the program arguments:
auto result = cli.parse({ argc, argv });
Expand Down
15 changes: 7 additions & 8 deletions examples/doc_example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
// Where we read in the argument values:
int width = 0;
Expand All @@ -20,12 +20,10 @@ int main(int argc, const char** argv)
// The parser with the multiple option arguments. They are composed
// together by the "|" operator.
auto cli
= lyra::opt(width, "width")
["-w"]["--width"]("How wide should it be?")
| lyra::opt(name, "name")
["-n"]["--name"]("By what name should I be known")
| lyra::opt(doIt)
["-d"]["--doit"]("Do the thing");
= lyra::opt(width, "width")["-w"]["--width"]("How wide should it be?")
| lyra::opt(name, "name")["-n"]["--name"](
"By what name should I be known")
| lyra::opt(doIt)["-d"]["--doit"]("Do the thing");

// ...
// end::part1[]
Expand All @@ -42,7 +40,8 @@ int main(int argc, const char** argv)
return 1;
}

std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
std::cout << "width = " << width << ", name = " << name
<< ", doIt = " << doIt << "\n";
return 0;
}
// end::part2[]
17 changes: 11 additions & 6 deletions examples/doc_example2_alt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
// Where we read in the argument values:
int width = 0;
Expand All @@ -21,11 +21,15 @@ int main(int argc, const char** argv)
// together by the "|" operator.
auto cli = lyra::cli();
cli.add_argument(lyra::opt(width, "width")
.name("-w").name("--width").help("How wide should it be?"));
.name("-w")
.name("--width")
.help("How wide should it be?"));
cli.add_argument(lyra::opt(name, "name")
.name("-n").name("--name").help("By what name should I be known"));
cli.add_argument(lyra::opt(doIt)
.name("-d").name("--doit").help("Do the thing"));
.name("-n")
.name("--name")
.help("By what name should I be known"));
cli.add_argument(
lyra::opt(doIt).name("-d").name("--doit").help("Do the thing"));

// Parse the program arguments:
auto result = cli.parse({ argc, argv });
Expand All @@ -37,7 +41,8 @@ int main(int argc, const char** argv)
return 1;
}

std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
std::cout << "width = " << width << ", name = " << name
<< ", doIt = " << doIt << "\n";
return 0;
}
// end::doc[]
18 changes: 8 additions & 10 deletions examples/doc_example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <lyra/lyra.hpp>

// tag::part1[]
int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
// Where we read in the argument values:
int width = 0;
Expand All @@ -19,14 +19,11 @@ int main(int argc, const char** argv)
bool show_help = false; // <1>

// The parser with the multiple option arguments and help option.
auto cli
= lyra::help(show_help) // <2>
| lyra::opt(width, "width")
["-w"]["--width"]("How wide should it be?")
| lyra::opt(name, "name")
["-n"]["--name"]("By what name should I be known")
| lyra::opt(doIt)
["-d"]["--doit"]("Do the thing");
auto cli = lyra::help(show_help) // <2>
| lyra::opt(width, "width")["-w"]["--width"]("How wide should it be?")
| lyra::opt(name, "name")["-n"]["--name"](
"By what name should I be known")
| lyra::opt(doIt)["-d"]["--doit"]("Do the thing");

// ...
// end::part1[]
Expand All @@ -51,7 +48,8 @@ int main(int argc, const char** argv)
return 0;
}

std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n";
std::cout << "width = " << width << ", name = " << name
<< ", doIt = " << doIt << "\n";
return 0;
}
// end::part2[]
5 changes: 2 additions & 3 deletions examples/doc_example4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
int repeat = 0;
std::string message;
// Ex: <exe> --repeat=10 "Hello world."
auto cli
= lyra::opt(repeat, "-repeat")["--repeat"]
auto cli = lyra::opt(repeat, "-repeat")["--repeat"]
| lyra::arg(message, "message");
if (cli.parse({ argc, argv }))
{
Expand Down
5 changes: 2 additions & 3 deletions examples/doc_example5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
std::string choice;
// Ex: <exe> --choice=red
auto cli = lyra::cli()
| lyra::opt(choice, "-c")["--choice"]
.choices("red", "green", "blue");
| lyra::opt(choice, "-c")["--choice"].choices("red", "green", "blue");
auto result = cli.parse({ argc, argv });
if (result)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/doc_example6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Distributed under the Boost Software License, Version 1.0.
#include <iostream>
#include <lyra/lyra.hpp>

int main(int argc, const char** argv)
int main(int argc, const char ** argv)
{
int choice = 5;
// Ex: <exe> --choice=3
auto cli = lyra::cli()
| lyra::opt(choice, "-c")["--choice"]
.choices([](int value) { return 1 <= value && value <= 10; });
| lyra::opt(choice, "-c")["--choice"].choices(
[](int value) { return 1 <= value && value <= 10; });
auto result = cli.parse({ argc, argv });
if (result)
{
Expand Down
8 changes: 3 additions & 5 deletions examples/doc_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ int main(int argc, const char ** argv)
.add_argument(lyra::opt(aspect, "aspect") // <1>
.name("--aspect")
.help("Full-screen aspect ratio window."))
.add_argument(lyra::group([&](const lyra::group &) {
show_full_screen = false;
}) // <2>
.add_argument(lyra::group(
[&](const lyra::group &) { show_full_screen = false; }) // <2>
.add_argument(lyra::opt(width, "width") // <3>
.required()
.name("--width")
Expand All @@ -78,8 +77,7 @@ int main(int argc, const char ** argv)
// Check that the arguments where valid.
if (!result)
{
std::cerr << "Error in command line: " << result.message()
<< std::endl;
std::cerr << "Error in command line: " << result.message() << std::endl;
return 1;
}

Expand Down
13 changes: 5 additions & 8 deletions examples/doc_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt)
*/


/* tag::doc[]

= More Main
Expand All @@ -30,13 +29,11 @@ end::doc[] */

int main(int argc, const char ** argv)
{
return lyra::main()
(lyra::opt(lyra::val(0), "x")["-x"]) // <1>
(lyra::opt(lyra::val(0), "y")["-y"])
(lyra::arg(lyra::val(5), "z")) // <2>
(argc, argv, [](lyra::main & m)
{
std::cout << (int(m["-x"]) + int(m["-y"]))*int(m["z"]) << "\n";
return lyra::main()(lyra::opt(lyra::val(0), "x")["-x"]) // <1>
(lyra::opt(lyra::val(0), "y")["-y"])(
lyra::arg(lyra::val(5), "z")) // <2>
(argc, argv, [](lyra::main & m) {
std::cout << (int(m["-x"]) + int(m["-y"])) * int(m["z"]) << "\n";
return 0;
});
}
Expand Down
3 changes: 2 additions & 1 deletion examples/doc_simple_alt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ int main(int argc, const char ** argv)
return lyra::main() // <1>
("-x", 0)("-y", 0)("z", 5) // <2>
(argc, argv, [](lyra::main & m) { // <3>
std::cout << (int(m["-x"]) + int(m["-y"])) * int(m["z"]) << "\n"; // <4>
std::cout << (int(m["-x"]) + int(m["-y"])) * int(m["z"])
<< "\n"; // <4>
return 0; // <5>
});
}
Expand Down
3 changes: 1 addition & 2 deletions include/lyra/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class arg : public bound_parser<arg>
for (size_t i = 0; i < c.minimum; ++i)
(((text += (i > 0 ? " " : "")) += "<") += m_hint) += ">";
if (c.is_unbounded())
(((text += (c.is_required() ? " " : "")) += "[<")
+= m_hint)
(((text += (c.is_required() ? " " : "")) += "[<") += m_hint)
+= ">...]";
}
else if (c.is_unbounded())
Expand Down
1 change: 0 additions & 1 deletion include/lyra/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ inline command & command::brief_help(bool brief)
return *this;
}


} // namespace lyra

#endif
6 changes: 4 additions & 2 deletions include/lyra/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class parser
print_help_text_summary(p, style);
print_help_text_details(p, style);
}
virtual void print_help_text_summary(printer & p, const option_style & style) const
virtual void print_help_text_summary(
printer & p, const option_style & style) const
{
std::string usage_test = get_usage_text(style);
if (!usage_test.empty())
Expand All @@ -193,7 +194,8 @@ class parser
std::string description_test = get_description_text(style);
if (!description_test.empty()) p.paragraph(get_description_text(style));
}
virtual void print_help_text_details(printer & p, const option_style & style) const
virtual void print_help_text_details(
printer & p, const option_style & style) const
{
p.heading("OPTIONS, ARGUMENTS:");
for (auto const & cols : get_help_text(style))
Expand Down
Loading