CLI: Validate JSON keymap input (#16261)

* Fix schema validator

It should use the passed schema.

* Add required attributes to keymap schema

* Rework subcommands to validate the JSON keymaps

The 'compile', 'flash' and 'json2c' subcommands were reworked to add
JSON keymap validation so error is reported for non-JSON and
non-compliant-JSON inputs.

* Fix required fields in keymap schema

* Add tests

* Fix compiling keymaps directly from keymap directory

* Schema should not require version for now.
This commit is contained in:
Erovia 2022-02-28 20:02:39 +00:00 committed by GitHub
parent 779c7debcf
commit fbfd5312b9
Failed to generate hash of commit
6 changed files with 47 additions and 18 deletions

View file

@ -70,9 +70,13 @@ def normpath(path):
class FileType(argparse.FileType):
def __init__(self, encoding='UTF-8'):
# Use UTF8 by default for stdin
return super().__init__(encoding=encoding)
def __call__(self, string):
"""normalize and check exists
otherwise magic strings like '-' for stdin resolve to bad paths
"""
norm = normpath(string)
return super().__call__(norm if norm.exists() else string)
return norm if norm.exists() else super().__call__(string)