1
1
#include < sourcemeta/core/json.h>
2
2
#include < sourcemeta/core/jsonschema.h>
3
3
4
- #include < cstdlib> // EXIT_SUCCESS
4
+ #include < cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
5
5
#include < iostream> // std::cout
6
6
7
7
#include " command.h"
@@ -11,37 +11,30 @@ auto sourcemeta::jsonschema::cli::bundle(
11
11
const std::span<const std::string> &arguments) -> int {
12
12
const auto options{
13
13
parse_options (arguments, {" h" , " http" , " w" , " without-id" })};
14
- const auto dialect{default_dialect (options)};
15
-
16
14
if (options.at (" " ).size () < 1 ) {
17
- std::cerr
18
- << " error: This command expects a path to a schema. For example:\n\n "
19
- << " jsonschema bundle path/to/schema.json\n " ;
15
+ log_error () << " This command expects a path to a schema. For example:\n\n "
16
+ << " jsonschema bundle path/to/schema.json\n " ;
20
17
return EXIT_FAILURE;
21
18
}
22
19
23
- const auto custom_resolver{resolver (
24
- options, options.contains (" h" ) || options.contains (" http" ), dialect)};
25
- auto schema{sourcemeta::jsonschema::cli::read_file (options.at (" " ).front ())};
26
-
20
+ const auto default_dialect{infer_default_dialect (options)};
21
+ const auto resolver{infer_resolver (options, default_dialect)};
22
+ auto schema{read_yaml_or_json (options.at (" " ).front ())};
27
23
sourcemeta::core::bundle (schema, sourcemeta::core::schema_official_walker,
28
- custom_resolver, dialect );
24
+ resolver, default_dialect );
29
25
30
26
if (options.contains (" w" ) || options.contains (" without-id" )) {
31
- std::cerr << " warning: You are opting in to remove schema identifiers in "
32
- " the bundled schema.\n " ;
33
- std::cerr << " The only legit use case of this advanced feature we know of "
34
- " it to workaround\n " ;
35
- std::cerr << " non-compliant JSON Schema implementations such as Visual "
36
- " Studio Code.\n " ;
37
- std::cerr << " In other case, this is not needed and may harm other use "
38
- " cases. For example,\n " ;
39
- std::cerr << " you will be unable to reference the resulting schema from "
40
- " other schemas\n " ;
41
- std::cerr << " using the --resolve/-r option.\n " ;
27
+ log_warning ()
28
+ << " You are opting in to remove schema identifiers in "
29
+ " the bundled schema.\n The only legit use case of this "
30
+ " advanced feature we know of it to workaround\n non-compliant "
31
+ " JSON Schema implementations such as Visual Studio Code.\n In "
32
+ " other case, this is not needed and may harm other use cases. "
33
+ " For example,\n you will be unable to reference the resulting "
34
+ " schema from other schemas\n using the --resolve/-r option.\n " ;
42
35
sourcemeta::core::unidentify (schema,
43
36
sourcemeta::core::schema_official_walker,
44
- custom_resolver, dialect );
37
+ resolver, default_dialect );
45
38
}
46
39
47
40
sourcemeta::core::prettify (schema, std::cout,
0 commit comments