Skip to content

Commit

Permalink
Add and fix cpplint whitespace/comments (CLIUtils#434)
Browse files Browse the repository at this point in the history
* Add whitespace/comments check

* Adapt spacing in clang-format

* Fix cpplint whitespace/comments issues

* Grammar

* Do not use clang-format for comment spacing

* Fix with clang-format pre-commit hook
  • Loading branch information
cbachhuber authored Mar 6, 2020
1 parent ba68040 commit d8a5bdc
Show file tree
Hide file tree
Showing 30 changed files with 170 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SortIncludes: true
# SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
# SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1
SpacesBeforeTrailingComments: 2
# SpacesInAngles: false
# SpacesInContainerLiterals: true
# SpacesInCStyleCastParentheses: false
Expand Down
5 changes: 1 addition & 4 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
set noparent
linelength=120 # As in .clang-format

# Non-used filters
# Unused filters
filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers
filter=-readability/nolint # Conflicts with clang-tidy
filter=-runtime/references # Requires fundamental change of API, don't see need for this
filter=-whitespace/blank_line # Unnecessarily strict with blank lines that otherwise help with readability
filter=-whitespace/indent # Requires strange 3-space indent of private/protected/public markers
filter=-whitespace/parens,-whitespace/braces # Conflict with clang-format

# Filters to be included in future
filter=-whitespace/comments

2 changes: 1 addition & 1 deletion examples/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char **argv) {
int count{0};
CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important");

double value{0.0}; // = 3.14;
double value{0.0}; // = 3.14;
app.add_option("-d,--double", value, "Some Value")->group("Other");

try {
Expand Down
2 changes: 1 addition & 1 deletion examples/nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char **argv) {
app.add_flag("--version", "Get version");

CLI::App *cameraApp = app.add_subcommand("camera", "Configure the app camera");
cameraApp->require_subcommand(0, 1); // 0 (default) or 1 camera
cameraApp->require_subcommand(0, 1); // 0 (default) or 1 camera

std::string mvcamera_config_file = "mvcamera_config.json";
CLI::App *mvcameraApp = cameraApp->add_subcommand("mvcamera", "MatrixVision Camera Configuration");
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main(int argc, char **argv) {
int v{0};
CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times");

double value{0.0}; // = 3.14;
double value{0.0}; // = 3.14;
app.add_option("-d,--double", value, "Some Value");

CLI11_PARSE(app, argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion examples/subcom_partitioned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char **argv) {
CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required();

CLI::App_p otherOpt = std::make_shared<CLI::App>("Other");
double value{0.0}; // = 3.14;
double value{0.0}; // = 3.14;
otherOpt->add_option("-d,--double", value, "Some Value");

// add the subapps to the main one
Expand Down
2 changes: 1 addition & 1 deletion examples/subcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main(int argc, char **argv) {
app.add_flag("--random", "Some random flag");
CLI::App *start = app.add_subcommand("start", "A great subcommand");
CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?");
app.require_subcommand(); // 1 or more
app.require_subcommand(); // 1 or more

std::string file;
start->add_option("-f,--file", file, "File name");
Expand Down
66 changes: 33 additions & 33 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ namespace CLI {
namespace detail {
enum class Classifier { NONE, POSITIONAL_MARK, SHORT, LONG, WINDOWS, SUBCOMMAND, SUBCOMMAND_TERMINATOR };
struct AppFriend;
} // namespace detail
} // namespace detail

namespace FailureMessage {
std::string simple(const App *app, const Error &e);
std::string help(const App *app, const Error &e);
} // namespace FailureMessage
} // namespace FailureMessage

/// enumeration of modes of how to deal with extras in config files

Expand Down Expand Up @@ -464,7 +464,7 @@ class App {
auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this;
auto &match = _compare_subcommand_names(*this, *p);
if(!match.empty()) {
ignore_case_ = false; // we are throwing so need to be exception invariant
ignore_case_ = false; // we are throwing so need to be exception invariant
throw OptionAlreadyAdded("ignore case would cause subcommand name conflicts: " + match);
}
}
Expand Down Expand Up @@ -586,19 +586,19 @@ class App {
}
}
// this line should not be reached the above loop should trigger the throw
throw(OptionAlreadyAdded("added option matched existing option name")); // LCOV_EXCL_LINE
throw(OptionAlreadyAdded("added option matched existing option name")); // LCOV_EXCL_LINE
}

/// Add option for assigning to a variable
template <typename AssignTo,
typename ConvertTo = AssignTo,
enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
Option *add_option(std::string option_name,
AssignTo &variable, ///< The variable to set
AssignTo &variable, ///< The variable to set
std::string option_description = "",
bool defaulted = false) {

auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
};

Expand All @@ -619,7 +619,7 @@ class App {
/// Add option for a callback of a specific type
template <typename T>
Option *add_option_function(std::string option_name,
const std::function<void(const T &)> &func, ///< the callback to execute
const std::function<void(const T &)> &func, ///< the callback to execute
std::string option_description = "") {

auto fun = [func](const CLI::results_t &res) {
Expand Down Expand Up @@ -731,7 +731,7 @@ class App {
template <typename T,
enable_if_t<std::is_integral<T>::value && !is_bool<T>::value, detail::enabler> = detail::dummy>
Option *add_flag(std::string flag_name,
T &flag_count, ///< A variable holding the count
T &flag_count, ///< A variable holding the count
std::string flag_description = "") {
flag_count = 0;
CLI::callback_t fun = [&flag_count](const CLI::results_t &res) {
Expand All @@ -754,7 +754,7 @@ class App {
!std::is_constructible<std::function<void(int)>, T>::value,
detail::enabler> = detail::dummy>
Option *add_flag(std::string flag_name,
T &flag_result, ///< A variable holding true if passed
T &flag_result, ///< A variable holding true if passed
std::string flag_description = "") {

CLI::callback_t fun = [&flag_result](const CLI::results_t &res) {
Expand All @@ -768,7 +768,7 @@ class App {
typename T,
enable_if_t<!std::is_assignable<std::function<void(std::int64_t)>, T>::value, detail::enabler> = detail::dummy>
Option *add_flag(std::string flag_name,
std::vector<T> &flag_results, ///< A vector of values with the flag results
std::vector<T> &flag_results, ///< A vector of values with the flag results
std::string flag_description = "") {
CLI::callback_t fun = [&flag_results](const CLI::results_t &res) {
bool retval = true;
Expand All @@ -785,7 +785,7 @@ class App {

/// Add option for callback that is triggered with a true flag and takes no arguments
Option *add_flag_callback(std::string flag_name,
std::function<void(void)> function, ///< A function to call, void(void)
std::function<void(void)> function, ///< A function to call, void(void)
std::string flag_description = "") {

CLI::callback_t fun = [function](const CLI::results_t &res) {
Expand All @@ -801,7 +801,7 @@ class App {

/// Add option for callback with an integer value
Option *add_flag_function(std::string flag_name,
std::function<void(std::int64_t)> function, ///< A function to call, void(int)
std::function<void(std::int64_t)> function, ///< A function to call, void(int)
std::string flag_description = "") {

CLI::callback_t fun = [function](const CLI::results_t &res) {
Expand All @@ -817,7 +817,7 @@ class App {
#ifdef CLI11_CPP14
/// Add option for callback (C++14 or better only)
Option *add_flag(std::string flag_name,
std::function<void(std::int64_t)> function, ///< A function to call, void(std::int64_t)
std::function<void(std::int64_t)> function, ///< A function to call, void(std::int64_t)
std::string flag_description = "") {
return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
}
Expand All @@ -826,8 +826,8 @@ class App {
/// Add set of options (No default, temp reference, such as an inline set) DEPRECATED
template <typename T>
Option *add_set(std::string option_name,
T &member, ///< The selected member of the set
std::set<T> options, ///< The set of possibilities
T &member, ///< The selected member of the set
std::set<T> options, ///< The set of possibilities
std::string option_description = "") {

Option *opt = add_option(option_name, member, std::move(option_description));
Expand All @@ -838,8 +838,8 @@ class App {
/// Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED
template <typename T>
Option *add_mutable_set(std::string option_name,
T &member, ///< The selected member of the set
const std::set<T> &options, ///< The set of possibilities
T &member, ///< The selected member of the set
const std::set<T> &options, ///< The set of possibilities
std::string option_description = "") {

Option *opt = add_option(option_name, member, std::move(option_description));
Expand All @@ -850,8 +850,8 @@ class App {
/// Add set of options (with default, static set, such as an inline set) DEPRECATED
template <typename T>
Option *add_set(std::string option_name,
T &member, ///< The selected member of the set
std::set<T> options, ///< The set of possibilities
T &member, ///< The selected member of the set
std::set<T> options, ///< The set of possibilities
std::string option_description,
bool defaulted) {

Expand All @@ -863,8 +863,8 @@ class App {
/// Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED
template <typename T>
Option *add_mutable_set(std::string option_name,
T &member, ///< The selected member of the set
const std::set<T> &options, ///< The set of possibilities
T &member, ///< The selected member of the set
const std::set<T> &options, ///< The set of possibilities
std::string option_description,
bool defaulted) {

Expand Down Expand Up @@ -932,7 +932,7 @@ class App {
// Remove existing config if present
if(config_ptr_ != nullptr) {
remove_option(config_ptr_);
config_ptr_ = nullptr; // need to remove the config_ptr completely
config_ptr_ = nullptr; // need to remove the config_ptr completely
}

// Only add config if option passed
Expand Down Expand Up @@ -1107,7 +1107,7 @@ class App {
for(auto &sub : subcommands_) {
cnt += sub->count_all();
}
if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called
if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called
cnt += parsed_;
}
return cnt;
Expand Down Expand Up @@ -1881,7 +1881,7 @@ class App {
app->name_.clear();
}
if(app->name_.empty()) {
app->fallthrough_ = false; // make sure fallthrough_ is false to prevent infinite loop
app->fallthrough_ = false; // make sure fallthrough_ is false to prevent infinite loop
app->prefix_command_ = false;
}
// make sure the parent is set to be this object in preparation for parse
Expand Down Expand Up @@ -2657,14 +2657,14 @@ class App {
int max_num = op->get_items_expected_max();

// Make sure we always eat the minimum for unlimited vectors
int collected = 0; // total number of arguments collected
int result_count = 0; // local variable for number of results in a single arg string
int collected = 0; // total number of arguments collected
int result_count = 0; // local variable for number of results in a single arg string
// deal with purely flag like things
if(max_num == 0) {
auto res = op->get_flag_value(arg_name, value);
op->add_result(res);
parse_order_.push_back(op.get());
} else if(!value.empty()) { // --this=value
} else if(!value.empty()) { // --this=value
op->add_result(value, result_count);
parse_order_.push_back(op.get());
collected += result_count;
Expand All @@ -2685,11 +2685,11 @@ class App {
collected += result_count;
}

if(min_num > collected) { // if we have run out of arguments and the minimum was not met
if(min_num > collected) { // if we have run out of arguments and the minimum was not met
throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name());
}

if(max_num > collected || op->get_allow_extra_args()) { // we allow optional arguments
if(max_num > collected || op->get_allow_extra_args()) { // we allow optional arguments
auto remreqpos = _count_remaining_positionals(true);
// we have met the minimum now optionally check up to the maximum
while((collected < max_num || op->get_allow_extra_args()) && !args.empty() &&
Expand Down Expand Up @@ -2866,7 +2866,7 @@ class App {
throw OptionNotFound("could not locate the given Option");
}
}
}; // namespace CLI
}; // namespace CLI

/// Extension of App to better manage groups of options
class Option_group : public App {
Expand Down Expand Up @@ -3050,7 +3050,7 @@ inline std::string help(const App *app, const Error &e) {
return header;
}

} // namespace FailureMessage
} // namespace FailureMessage

namespace detail {
/// This class is simply to allow tests access to App's protected functions
Expand All @@ -3072,6 +3072,6 @@ struct AppFriend {
/// Wrap the fallthrough parent function to make sure that is working correctly
static App *get_fallthrough_parent(App *app) { return app->_get_fallthrough_parent(); }
};
} // namespace detail
} // namespace detail

} // namespace CLI
} // namespace CLI
4 changes: 2 additions & 2 deletions include/CLI/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ inline void checkParentSegments(std::vector<ConfigItem> &output, const std::stri
output.back().parents = std::move(parents);
output.back().name = "++";
}
} // namespace detail
} // namespace detail

inline std::vector<ConfigItem> ConfigBase::from_config(std::istream &input) const {
std::string line;
Expand Down Expand Up @@ -343,4 +343,4 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
return out.str();
}

} // namespace CLI
} // namespace CLI
2 changes: 1 addition & 1 deletion include/CLI/ConfigFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ class ConfigTOML : public ConfigINI {
valueDelimiter = '=';
}
};
} // namespace CLI
} // namespace CLI
2 changes: 1 addition & 1 deletion include/CLI/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,4 @@ class OptionNotFound : public Error {

/// @}

} // namespace CLI
} // namespace CLI
14 changes: 7 additions & 7 deletions include/CLI/Formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ inline std::string Formatter::make_groups(const App *app, AppFormatMode mode) co
// Options
for(const std::string &group : groups) {
std::vector<const Option *> opts = app->get_options([app, mode, &group](const Option *opt) {
return opt->get_group() == group // Must be in the right group
&& opt->nonpositional() // Must not be a positional
&& (mode != AppFormatMode::Sub // If mode is Sub, then
|| (app->get_help_ptr() != opt // Ignore help pointer
&& app->get_help_all_ptr() != opt)); // Ignore help all pointer
return opt->get_group() == group // Must be in the right group
&& opt->nonpositional() // Must not be a positional
&& (mode != AppFormatMode::Sub // If mode is Sub, then
|| (app->get_help_ptr() != opt // Ignore help pointer
&& app->get_help_all_ptr() != opt)); // Ignore help all pointer
});
if(!group.empty() && !opts.empty()) {
out << make_group(group, false, opts);
Expand Down Expand Up @@ -220,7 +220,7 @@ inline std::string Formatter::make_expanded(const App *sub) const {

// Drop blank spaces
std::string tmp = detail::find_and_replace(out.str(), "\n\n", "\n");
tmp = tmp.substr(0, tmp.size() - 1); // Remove the final '\n'
tmp = tmp.substr(0, tmp.size() - 1); // Remove the final '\n'

// Indent all but the first line (the name)
return detail::find_and_replace(tmp, "\n", "\n ") + "\n";
Expand Down Expand Up @@ -278,4 +278,4 @@ inline std::string Formatter::make_option_usage(const Option *opt) const {
return opt->get_required() ? out.str() : "[" + out.str() + "]";
}

} // namespace CLI
} // namespace CLI
Loading

0 comments on commit d8a5bdc

Please sign in to comment.