Skip to content

Commit

Permalink
CLI: Use stdout and stderr to print Messages with xmlschema-validate …
Browse files Browse the repository at this point in the history
…command (#393)

* feat(cli-validate): Use stdout and stderr instead of print statement

This change helps users to distinguish between error messages and
others, e.g. in CI pipelines.

Signed-off-by: Sven Sager <s.sager@kunbus.com>

* feat(cli-validate): Use argument -v to print errors on stderr

The argument -v (verbosity) is not yet used in the validate function.
The specification of -v is now used in xmlschema-validate to obtain a
detailed error report on the stderr. This helps users to find the error
in their XML files at the mentioned place.

Signed-off-by: Sven Sager <s.sager@kunbus.com>

---------

Signed-off-by: Sven Sager <s.sager@kunbus.com>
  • Loading branch information
naruxde committed Mar 12, 2024
1 parent e0ff225 commit cb9a110
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions xmlschema/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ def validate():
locations=args.locations, lazy=args.lazy, defuse=args.defuse))
except (xmlschema.XMLSchemaException, URLError) as err:
tot_errors += 1
print(str(err))
sys.stderr.write(f"{err}\n")
continue
else:
if not errors:
print("{} is valid".format(filepath))
sys.stdout.write(f"{filepath} is valid\n")
else:
tot_errors += len(errors)
print("{} is not valid".format(filepath))
sys.stderr.write(f"{filepath} is not valid\n")
if args.verbosity > 0:
for error in errors:
sys.stderr.write(f"{error}\n")

sys.exit(tot_errors)

0 comments on commit cb9a110

Please sign in to comment.