-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.cpp
25 lines (24 loc) · 822 Bytes
/
count.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "argparse.hpp"
#include <iostream>
int main(int argc, char * argv[])
{
auto parser = argparse::ArgumentParser();
parser.add_argument("square").help("display a square of a given number").type<int>();
parser.add_argument("-v", "--verbosity").help("increase output verbosity").action(argparse::count);
auto parsed = parser.parse_args(argc, argv);
auto value = parsed.get_value<int>("square");
auto answer = value * value;
auto verbosity = parsed.get("verbosity");
if (verbosity && verbosity.get<int>() == 2)
{
std::cout << "the square of " << value << " equals " << answer << '\n';
}
else if (verbosity && verbosity.get<int>() == 1)
{
std::cout << value << "^2 == " << answer << '\n';
}
else
{
std::cout << answer << '\n';
}
}