CLI: add stdin support for instance validation #614
CLI: add stdin support for instance validation #614Vaibhav701161 wants to merge 7 commits intosourcemeta:mainfrom
Conversation
ddb8312 to
9a040d7
Compare
|
Hi @jviotti , I’ve opened this PR and would appreciate a review when you have time. Thanks! |
|
Hey @Vaibhav701161 , sorry for the delay. It has been a hectic week. I'll try to get into it today |
|
I like the idea but I think there are some things to iron out:
I think for consistency, we can require the The other problem here will be line numbers. We should make sure all relevant commands handle standard input while still reporting line/column information and potentially some "special" file path like |
4d5ff3f to
112b374
Compare
|
Hey @jviotti , thanks a lot for the feedback. I’ve pushed an updated iteration that tries to address the concerns you mentioned:
|
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
f70d55d to
b9bb23e
Compare
|
Hi @jviotti , just a quick follow-up on this. |
| inline auto read_from_stdin() -> ParsedJSON { | ||
| std::string buffer; | ||
| { | ||
| std::ostringstream ss; |
There was a problem hiding this comment.
You shouldn't need this. sourcemeta::core::parse_json should already be able to read from any standard C++ input stream without needing to buffer it
|
|
||
| struct InputJSON { | ||
| std::filesystem::path first; | ||
| std::filesystem::path resolution_base; |
There was a problem hiding this comment.
If this is just a display name, maybe make a std::string? Otherwise <stdin> is not really a path
There was a problem hiding this comment.
I think this still needs to be addressed?
There was a problem hiding this comment.
Please split this test into multiple tests. If you see the other tests in the project, we have specific conventions and we always test a single thing per file. Plus you also want to add test for every other applicable command.
Finally, you didn't register this test in test/CMakeLists.txt, so it won't run at all
| copy, sourcemeta::core::schema_walker, custom_resolver, | ||
| get_lint_callback(errors_array, entry, output_json), dialect, | ||
| sourcemeta::jsonschema::default_id(entry.first), | ||
| sourcemeta::core::URI::from_path(entry.resolution_base) |
There was a problem hiding this comment.
I think we still definitely want to use sourcemeta::jsonschema::default_id here, to concentrate that logic in a single place. Maybe make such function take entry directly, so that inside we can decide to use entry.resolution_base or whatever?
| custom_resolver, | ||
| get_lint_callback(errors_array, entry, output_json), dialect, | ||
| sourcemeta::jsonschema::default_id(entry.first), | ||
| sourcemeta::core::URI::from_path(entry.resolution_base) |
| // TODO: Print a verbose message for what is getting parsed | ||
| auto parsed{read_file(canonical)}; | ||
| result.push_back({std::move(canonical), std::move(parsed.document), | ||
| auto canonical_copy{canonical}; |
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't think this deletion was intended?
| } | ||
| } | ||
| if (stdin_count > 1) { | ||
| throw std::runtime_error{"Standard input (-) can only be specified once"}; |
There was a problem hiding this comment.
| throw std::runtime_error{"Standard input (-) can only be specified once"}; | |
| throw std::runtime_error{"The standard input position argument `-` can only be specified once"}; |
| std::size_t stdin_count{0}; | ||
| for (const auto &arg : arguments) { | ||
| if (arg == "-") { | ||
| stdin_count++; |
There was a problem hiding this comment.
I don't think counting all occurrences makes sense if you only want up to two. Maybe check that if you already got at least 2, then its an error and you can break?
| set +o errexit | ||
| cat "$TMP/schema.json" > "$TMP/schema_stdin.json" | ||
|
|
||
| OUTPUT=$("$1" validate - "$TMP/schema.json" < "$TMP/schema_stdin.json" 2>&1) |
There was a problem hiding this comment.
Please see the other shell scripts for the conventions on how we test stuff. Some obvious ones:
- We never capture into a variable. We pipe into a file and then
diffit - We never enable
set +o errexit - We never test more than one thing at once
Also your test is not registered in test/CMakeLists.txt so it won't run at all. But overall, split it so that there are multiple tests testing each one thing
Adds stdin support for instance input to enable real-time editor diagnostics.
Fixes(#537)
src/input.h(JSON-first, YAML fallback).validateaccepts instances from stdin only; schemas must be file paths.$refagainst the current working directory.test/validate/pass_stdin.sh.sourcemeta/studio#61; addressessourcemeta/jsonschema#537.Refs: sourcemeta/studio#61, #537
*

Build and test: