-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
identify
command to print schema ids
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4 | ||
noa https://github.com/sourcemeta/noa 7e26abce7a4e31e86a16ef2851702a56773ca527 | ||
jsontoolkit https://github.com/sourcemeta/jsontoolkit 8e4d59fb0d75351175337bdcff7fe6caf4fe7096 | ||
jsontoolkit https://github.com/sourcemeta/jsontoolkit a3765c8038ba4271e55318a677f6366bdaa7b805 | ||
hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <sourcemeta/jsontoolkit/json.h> | ||
#include <sourcemeta/jsontoolkit/jsonschema.h> | ||
|
||
#include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE | ||
#include <iostream> // std::cout | ||
|
||
#include "command.h" | ||
#include "utils.h" | ||
|
||
auto intelligence::jsonschema::cli::identify( | ||
const std::span<const std::string> &arguments) -> int { | ||
const auto options{parse_options(arguments, {})}; | ||
if (options.at("").size() < 1) { | ||
std::cerr | ||
<< "error: This command expects a path to a schema. For example:\n\n" | ||
<< " jsonschema identify path/to/schema.json\n"; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
const sourcemeta::jsontoolkit::JSON schema{ | ||
sourcemeta::jsontoolkit::from_file(options.at("").front())}; | ||
|
||
// Just to print a nice warning | ||
try { | ||
const auto base_dialect{ | ||
sourcemeta::jsontoolkit::base_dialect( | ||
schema, sourcemeta::jsontoolkit::official_resolver) | ||
.get()}; | ||
if (!base_dialect.has_value()) { | ||
std::cerr << "warning: Cannot determine the base dialect of the schema, " | ||
"but will attempt to guess\n"; | ||
} | ||
} catch (const sourcemeta::jsontoolkit::SchemaResolutionError &) { | ||
std::cerr << "warning: Cannot determine the base dialect of the schema, " | ||
"but will attempt to guess\n"; | ||
} | ||
|
||
const auto identifier{ | ||
sourcemeta::jsontoolkit::id( | ||
schema, sourcemeta::jsontoolkit::official_resolver, | ||
sourcemeta::jsontoolkit::IdentificationStrategy::Loose) | ||
.get()}; | ||
|
||
if (!identifier.has_value()) { | ||
log_verbose(options) << "error: Could not determine schema identifier\n"; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::cout << identifier.value() << "\n"; | ||
return EXIT_SUCCESS; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.