Skip to content

Commit bcd39ab

Browse files
RomainTTRomain Taprest
authored and
Romain Taprest
committed
[CLI] Fix STDIN management.
1 parent a901635 commit bcd39ab

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

jsonschema/cli.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ def _namedAnyWithDefault(name):
118118
type=str,
119119
help=(
120120
"A path to a JSON instance (i.e. filename.json) "
121-
"to validate (may be specified multiple times)"
121+
"to validate (may be specified multiple times). "
122+
"If this option is not used, an instance can be given through stdin. "
123+
"If none is given, only the schema is checked."
122124
),
123125
)
124126
parser.add_argument(
@@ -248,17 +250,21 @@ def run(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin):
248250
return False
249251

250252
errored = False
251-
for instance_path in arguments["instances"]:
252-
try:
253-
validate_instance(
254-
instance_path,
255-
load_instance_file(instance_path, output_writer),
256-
validator,
257-
output_writer,
258-
)
259-
except (json.JSONDecodeError, FileNotFoundError, ValidationError):
260-
errored = True
261-
if stdin is sys.stdin and not sys.stdin.isatty():
253+
if arguments["instances"]:
254+
for instance_path in arguments["instances"]:
255+
try:
256+
validate_instance(
257+
instance_path,
258+
load_instance_file(instance_path, output_writer),
259+
validator,
260+
output_writer,
261+
)
262+
except (json.JSONDecodeError, FileNotFoundError, ValidationError):
263+
errored = True
264+
elif (
265+
stdin is sys.stdin and not sys.stdin.isatty()
266+
or stdin is not sys.stdin and stdin is not None
267+
):
262268
try:
263269
validate_instance(
264270
"stdin",

0 commit comments

Comments
 (0)