Skip to content

Commit

Permalink
style: pre-commit.ci fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jun 23, 2023
1 parent 3d0e29e commit a454aa3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
21 changes: 8 additions & 13 deletions include/CLI/impl/App_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,24 +1015,19 @@ CLI11_INLINE void App::_process_config_file() {
bool config_required = config_ptr_->get_required();
auto file_given = config_ptr_->count() > 0;
auto config_files = config_ptr_->as<std::vector<std::string>>();
if (config_files.empty() || config_files.front().empty()) {
if (!config_ptr_->envname_.empty())
{
if(config_files.empty() || config_files.front().empty()) {
if(!config_ptr_->envname_.empty()) {
std::string ename_string = detail::get_environment_value(config_ptr_->envname_);
if (!ename_string.empty())
{
if (config_files.empty())
{
if(!ename_string.empty()) {
if(config_files.empty()) {
config_files.push_back(ename_string);
}
else
{
config_files[0]=ename_string;
} else {
config_files[0] = ename_string;
}
}
}
}
if(config_files.empty() || config_files.front().empty()) {
if(config_files.empty() || config_files.front().empty()) {
if(config_required) {
throw FileError("config file is required but none was given");
}
Expand Down Expand Up @@ -1062,7 +1057,7 @@ CLI11_INLINE void App::_process_config_file() {
CLI11_INLINE void App::_process_env() {
for(const Option_p &opt : options_) {
if(opt->count() == 0 && !opt->envname_.empty()) {
std::string ename_string=detail::get_environment_value(opt->envname_);
std::string ename_string = detail::get_environment_value(opt->envname_);
if(!ename_string.empty()) {
opt->add_result(ename_string);
}
Expand Down
4 changes: 1 addition & 3 deletions include/CLI/impl/StringTools_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ CLI11_INLINE std::string &add_quotes_if_needed(std::string &str) {
return str;
}


std::string get_environment_value(const std::string& env_name)
{
std::string get_environment_value(const std::string &env_name) {
char *buffer = nullptr;
std::string ename_string;

Expand Down
5 changes: 2 additions & 3 deletions tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ TEST_CASE_METHOD(TApp, "IniEnvironmentalFileName", "[config]") {

TempFile tmpini{"TestIniTmp.ini"};


app.set_config("--config", "")->envname("CONFIG")->required();

{
Expand All @@ -692,7 +691,7 @@ TEST_CASE_METHOD(TApp, "IniEnvironmentalFileName", "[config]") {
app.add_option("--two", two);
app.add_option("--three", three);

put_env("CONFIG",tmpini);
put_env("CONFIG", tmpini);

CHECK_NOTHROW(run());

Expand All @@ -701,7 +700,7 @@ TEST_CASE_METHOD(TApp, "IniEnvironmentalFileName", "[config]") {

unset_env("CONFIG");

CHECK_THROWS_AS(run(),CLI::FileError);
CHECK_THROWS_AS(run(), CLI::FileError);
}

TEST_CASE_METHOD(TApp, "MultiConfig", "[config]") {
Expand Down
13 changes: 6 additions & 7 deletions tests/HelpersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include "app_helper.hpp"
#include "CLI/StringTools.hpp"
#include "app_helper.hpp"

#include <cmath>

Expand Down Expand Up @@ -1356,14 +1356,13 @@ TEST_CASE("FixNewLines: EdgesCheck", "[helpers]") {
CHECK(output == result);
}


TEST_CASE("String: environment", "[helpers]") {
put_env("TEST1","TESTS");
auto value=CLI::detail::get_environment_value("TEST1");
CHECK(value=="TESTS");
put_env("TEST1", "TESTS");

auto value = CLI::detail::get_environment_value("TEST1");
CHECK(value == "TESTS");
unset_env("TEST1");

value=CLI::detail::get_environment_value("TEST2");
value = CLI::detail::get_environment_value("TEST2");
CHECK(value.empty());
}

0 comments on commit a454aa3

Please sign in to comment.