55#include < sourcemeta/core/json.h>
66#include < sourcemeta/core/jsonpointer.h>
77#include < sourcemeta/core/options.h>
8+ #include < sourcemeta/core/schemaconfig.h>
89#include < sourcemeta/core/yaml.h>
910
1011#include " configuration.h"
@@ -30,13 +31,14 @@ struct InputJSON {
3031 }
3132};
3233
33- inline auto parse_extensions (const sourcemeta::core::Options &options)
34+ inline auto parse_extensions (
35+ const sourcemeta::core::Options &options,
36+ const std::optional<sourcemeta::core::SchemaConfig> &configuration)
3437 -> std::set<std::string> {
3538 std::set<std::string> result;
3639
3740 if (options.contains (" extension" )) {
3841 for (const auto &extension : options.at (" extension" )) {
39- LOG_VERBOSE (options) << " Using extension: " << extension << " \n " ;
4042 if (extension.starts_with (' .' )) {
4143 result.emplace (extension);
4244 } else {
@@ -47,6 +49,22 @@ inline auto parse_extensions(const sourcemeta::core::Options &options)
4749 }
4850 }
4951
52+ if (configuration.has_value ()) {
53+ for (const auto &extension : configuration.value ().extension ) {
54+ if (extension.starts_with (' .' )) {
55+ result.emplace (extension);
56+ } else {
57+ std::ostringstream normalised_extension;
58+ normalised_extension << ' .' << extension;
59+ result.emplace (normalised_extension.str ());
60+ }
61+ }
62+ }
63+
64+ for (const auto &extension : result) {
65+ LOG_VERBOSE (options) << " Using extension: " << extension << " \n " ;
66+ }
67+
5068 if (result.empty ()) {
5169 result.insert ({" .json" });
5270 result.insert ({" .yaml" });
@@ -131,18 +149,19 @@ inline auto for_each_json(const std::vector<std::string_view> &arguments,
131149 const sourcemeta::core::Options &options)
132150 -> std::vector<InputJSON> {
133151 const auto blacklist{parse_ignore (options)};
134- const auto extensions{parse_extensions (options)};
135152 std::vector<InputJSON> result;
136153
137154 if (arguments.empty ()) {
138155 const auto current_path{std::filesystem::current_path ()};
139156 const auto configuration_path{find_configuration (current_path)};
140157 const auto &configuration{read_configuration (options, configuration_path)};
158+ const auto extensions{parse_extensions (options, configuration)};
141159 handle_json_entry (configuration.has_value ()
142160 ? configuration.value ().absolute_path
143161 : current_path,
144162 blacklist, extensions, result);
145163 } else {
164+ const auto extensions{parse_extensions (options, std::nullopt )};
146165 for (const auto &entry : arguments) {
147166 handle_json_entry (entry, blacklist, extensions, result);
148167 }
0 commit comments