mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Adding tidy cleanups (modernize)
This commit is contained in:
parent
d697cb6d85
commit
101c926dac
@ -12,6 +12,7 @@
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -33,7 +34,7 @@ struct AppFriend;
|
||||
class App;
|
||||
|
||||
|
||||
typedef std::unique_ptr<App> App_p;
|
||||
using App_p = std::unique_ptr<App>;
|
||||
|
||||
/// Creates a command line program, with very few defaults.
|
||||
/** To use, create a new `Program()` instance with `argc`, `argv`, and a help description. The templated
|
||||
@ -122,7 +123,7 @@ protected:
|
||||
|
||||
/// Special private constructor for subcommand
|
||||
App(std::string description_, bool help, detail::enabler)
|
||||
: description_(description_) {
|
||||
: description_(std::move(description_)) {
|
||||
|
||||
if(help)
|
||||
help_ptr_ = add_flag("-h,--help", "Print this help message and exit");
|
||||
@ -514,7 +515,7 @@ public:
|
||||
name_ = argv[0];
|
||||
std::vector<std::string> args;
|
||||
for(int i=argc-1; i>0; i--)
|
||||
args.push_back(argv[i]);
|
||||
args.emplace_back(argv[i]);
|
||||
return parse(args);
|
||||
|
||||
}
|
||||
@ -949,7 +950,7 @@ protected:
|
||||
try {
|
||||
size_t ui = std::stoul(val);
|
||||
for (size_t i=0; i<ui; i++)
|
||||
op->results_.push_back("");
|
||||
op->results_.emplace_back("");
|
||||
} catch (const std::invalid_argument &) {
|
||||
throw ConversionError(current.fullname + ": Should be true/false or a number");
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ inline std::string inijoin(std::vector<std::string> args) {
|
||||
auto it = std::find_if(arg.begin(), arg.end(), [](char ch){ return std::isspace<char>(ch , std::locale());});
|
||||
if(it == arg.end())
|
||||
s << arg;
|
||||
else if(arg.find("\"") == std::string::npos)
|
||||
s << "\"" << arg << "\"";
|
||||
else if(arg.find(R"(")") == std::string::npos)
|
||||
s << R"(")" << arg << R"(")";
|
||||
else
|
||||
s << "\'" << arg << "\'";
|
||||
s << R"(')" << arg << R"(')";
|
||||
}
|
||||
|
||||
return s.str();
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
@ -17,13 +18,13 @@
|
||||
|
||||
namespace CLI {
|
||||
|
||||
typedef std::vector<std::string> results_t;
|
||||
typedef std::function<bool(results_t)> callback_t;
|
||||
using results_t = std::vector<std::string>;
|
||||
using callback_t = std::function<bool (results_t)>;
|
||||
|
||||
class Option;
|
||||
class App;
|
||||
|
||||
typedef std::unique_ptr<Option> Option_p;
|
||||
using Option_p = std::unique_ptr<Option>;
|
||||
|
||||
|
||||
class Option {
|
||||
@ -113,7 +114,7 @@ protected:
|
||||
|
||||
/// Making an option by hand is not defined, it must be made by the App class
|
||||
Option(std::string name, std::string description = "", std::function<bool(results_t)> callback=[](results_t){return true;}, bool default_=true, App* parent = nullptr) :
|
||||
description_(description), default_(default_), parent_(parent), callback_(callback) {
|
||||
description_(std::move(description)), default_(default_), parent_(parent), callback_(std::move(callback)) {
|
||||
std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(name));
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ inline std::tuple<std::vector<std::string>,std::vector<std::string>, std::string
|
||||
continue;
|
||||
else if(name.length() > 1 && name[0] == '-' && name[1] != '-') {
|
||||
if(name.length()==2 && valid_first_char(name[1]))
|
||||
short_names.push_back(std::string(1,name[1]));
|
||||
short_names.emplace_back(1,name[1]);
|
||||
else
|
||||
throw BadNameString("Invalid one char name: "+name);
|
||||
} else if(name.length() > 2 && name.substr(0,2) == "--") {
|
||||
|
@ -20,7 +20,7 @@ inline std::vector<std::string> split(const std::string &s, char delim) {
|
||||
std::vector<std::string> elems;
|
||||
// Check to see if emtpy string, give consistent result
|
||||
if(s=="")
|
||||
elems.push_back("");
|
||||
elems.emplace_back("");
|
||||
else {
|
||||
std::stringstream ss;
|
||||
ss.str(s);
|
||||
|
@ -7,19 +7,20 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace CLI {
|
||||
|
||||
class Timer {
|
||||
protected:
|
||||
/// This is a typedef to make clocks easier to use
|
||||
typedef std::chrono::steady_clock clock;
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
/// This typedef is for points in time
|
||||
typedef std::chrono::time_point<clock> time_point;
|
||||
using time_point = std::chrono::time_point<clock>;
|
||||
|
||||
/// This is the type of a printing function, you can make your own
|
||||
typedef std::function<std::string(std::string, std::string)> time_print_t;
|
||||
using time_print_t = std::function<std::string (std::string, std::string)>;
|
||||
|
||||
/// This is the title of the timer
|
||||
std::string title_;
|
||||
@ -50,7 +51,7 @@ public:
|
||||
public:
|
||||
/// Standard constructor, can set title and print function
|
||||
Timer(std::string title="Timer", time_print_t time_print = Simple)
|
||||
: title_(title), time_print_(time_print), start_(clock::now()) {}
|
||||
: title_(std::move(title)), time_print_(std::move(time_print)), start_(clock::now()) {}
|
||||
|
||||
/// Time a function by running it multiple times. Target time is the len to target.
|
||||
std::string time_it(std::function<void()> f, double target_time=1) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "app_helper.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
TEST_F(TApp, OneFlagShort) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "app_helper.hpp"
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
TEST_F(TApp, AddingExistingShort) {
|
||||
app.add_flag("-c,--count");
|
||||
|
@ -283,7 +283,7 @@ TEST(Exit, ErrorWithoutHelp) {
|
||||
TEST(Exit, ExitCodes) {
|
||||
CLI::App app;
|
||||
|
||||
int i = static_cast<int>(CLI::ExitCodes::Extras);
|
||||
auto i = static_cast<int>(CLI::ExitCodes::Extras);
|
||||
EXPECT_EQ(0, app.exit(CLI::Success()));
|
||||
EXPECT_EQ(0, app.exit(CLI::CallForHelp()));
|
||||
EXPECT_EQ(i, app.exit(CLI::ExtrasError("Thing")));
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
TEST(Split, SimpleByToken) {
|
||||
@ -278,33 +278,33 @@ TEST(Join, Backward) {
|
||||
|
||||
TEST(SplitUp, Simple) {
|
||||
std::vector<std::string> oput = {"one", "two three"};
|
||||
std::string orig {"one \"two three\""};
|
||||
std::string orig {R"(one "two three")"};
|
||||
std::vector<std::string> result = CLI::detail::split_up(orig);
|
||||
EXPECT_EQ(oput, result);
|
||||
}
|
||||
|
||||
TEST(SplitUp, Layered) {
|
||||
std::vector<std::string> output = {"one \'two three\'"};
|
||||
std::string orig {"\"one \'two three\'\""};
|
||||
std::vector<std::string> output = {R"(one 'two three')"};
|
||||
std::string orig {R"("one 'two three'")"};
|
||||
std::vector<std::string> result = CLI::detail::split_up(orig);
|
||||
EXPECT_EQ(output, result);
|
||||
}
|
||||
|
||||
TEST(SplitUp, Spaces) {
|
||||
std::vector<std::string> oput = {"one", " two three"};
|
||||
std::string orig {" one \" two three\" "};
|
||||
std::string orig {R"( one " two three" )"};
|
||||
std::vector<std::string> result = CLI::detail::split_up(orig);
|
||||
EXPECT_EQ(oput, result);
|
||||
}
|
||||
|
||||
TEST(SplitUp, BadStrings) {
|
||||
std::vector<std::string> oput = {"one", " two three"};
|
||||
std::string orig {" one \" two three "};
|
||||
std::string orig {R"( one " two three )"};
|
||||
std::vector<std::string> result = CLI::detail::split_up(orig);
|
||||
EXPECT_EQ(oput, result);
|
||||
|
||||
oput = {"one", " two three"};
|
||||
orig = " one \' two three ";
|
||||
orig = R"( one ' two three )";
|
||||
result = CLI::detail::split_up(orig);
|
||||
EXPECT_EQ(oput, result);
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ TEST(StringBased, FirstWithComments) {
|
||||
TEST(StringBased, Quotes) {
|
||||
std::stringstream ofile;
|
||||
|
||||
ofile << "one = \"three\"" << std::endl;
|
||||
ofile << "two = \'four\'" << std::endl;
|
||||
ofile << "five = \"six and seven\"" << std::endl;
|
||||
ofile << R"(one = "three")" << std::endl;
|
||||
ofile << R"(two = 'four')" << std::endl;
|
||||
ofile << R"(five = "six and seven")" << std::endl;
|
||||
|
||||
ofile.seekg(0, std::ios::beg);
|
||||
|
||||
@ -575,7 +575,7 @@ TEST_F(TApp, IniQuotedOutput) {
|
||||
std::string val2;
|
||||
app.add_option("--val2", val2);
|
||||
|
||||
args = {"--val1", "I am a string", "--val2", "I am a \"confusing\" string"};
|
||||
args = {"--val1", "I am a string", "--val2", R"(I am a "confusing" string)"};
|
||||
|
||||
run();
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
|
||||
typedef std::complex<double> cx;
|
||||
using cx = std::complex<double>;
|
||||
|
||||
CLI::Option* add_option(CLI::App& app,
|
||||
std::string name, cx& variable,
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
typedef std::vector<std::string> input_t;
|
||||
using input_t = std::vector<std::string>;
|
||||
|
||||
TEST(Basic, Empty) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user