Skip to content

Commit

Permalink
engine: Remove --distinct option from check command
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Jul 5, 2024
1 parent d5f3314 commit fa7d258
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 44 deletions.
1 change: 0 additions & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ int main(int argc, char** argv) {
engine::CheckOptions check_options;
std::vector<std::string> check_files;
auto check = app.add_subcommand("check", "Validate stack file configurations.");
check->add_flag("-d,--distinct", check_options.distinct, "Validate each file distinctly");
check->add_flag("-s,--summarize", check_options.summarize, "Summarize results");
check->add_flag("-j,--json", check_options.output_json, "Output results as JSON data");
check->add_option("-J,--json-indent", check_options.json_indent, "JSON indentation level");
Expand Down
44 changes: 1 addition & 43 deletions engine/src/main_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct CheckOptions {
std::string delimiter = ",";

// Flags:
bool distinct = false;
bool summarize = false;
bool output_json = false;
int json_indent = 2;
Expand Down Expand Up @@ -129,49 +128,8 @@ inline int check_merged(const CheckOptions& opt, const std::vector<std::string>&
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}

inline int check_distinct(const CheckOptions& opt, const std::vector<std::string>& filepaths) {
int exit_code = EXIT_SUCCESS;
auto check_each = [&](std::function<void(const std::string&, bool*)> func) {
for (const auto& x : filepaths) {
bool ok = true;
func(x, &ok);
if (!ok) {
exit_code = EXIT_FAILURE;
}
}
};

if (opt.output_json) {
// Output for each file a summary
cloe::Json output;
check_each([&](const auto& f, bool* ok) {
output[f] = check_json(opt, std::vector<std::string>{f}, ok);
});
opt.output << output.dump(opt.json_indent) << std::endl;
} else if (opt.summarize) {
check_each([&](const auto& f, bool* ok) {
opt.output << f << ": " << check_summary(opt, std::vector<std::string>{f}, ok) << std::endl;
});
} else {
check_each([&](const auto& f, bool* ok) {
try {
check_stack(opt.stack_options, std::vector<std::string>{f}, ok);
} catch (cloe::ConcludedError&) {
} catch (std::exception& e) {
opt.output << f << ": " << e.what() << std::endl;
}
});
}

return exit_code;
}

inline int check(const CheckOptions& opt, const std::vector<std::string>& filepaths) {
if (opt.distinct) {
return check_distinct(opt, filepaths);
} else {
return check_merged(opt, filepaths);
}
return check_merged(opt, filepaths);
}

} // namespace engine

0 comments on commit fa7d258

Please sign in to comment.