Skip to content

Commit 04c6784

Browse files
committed
schema_salad/main.py: --version now correctly prints version
1 parent 61c2203 commit 04c6784

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

schema_salad/main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def main(argsl=None): # type: (List[str]) -> int
6262
"--print-index", action="store_true", help="Print node index")
6363
exgroup.add_argument("--print-metadata",
6464
action="store_true", help="Print document metadata")
65-
exgroup.add_argument("--version", action="store_true",
66-
help="Print version")
6765

6866
exgroup = parser.add_mutually_exclusive_group()
6967
exgroup.add_argument("--strict", action="store_true", help="Strict validation (unrecognized or out of place fields are error)",
@@ -79,11 +77,18 @@ def main(argsl=None): # type: (List[str]) -> int
7977
exgroup.add_argument("--debug", action="store_true",
8078
help="Print even more logging")
8179

82-
parser.add_argument("schema", type=str)
80+
parser.add_argument("schema", type=str, nargs="?", default=None)
8381
parser.add_argument("document", type=str, nargs="?", default=None)
82+
parser.add_argument("--version", "-v", action="store_true",
83+
help="Print version", default=None)
84+
8485

8586
args = parser.parse_args(argsl)
8687

88+
if args.version is None and args.schema is None:
89+
print('%s: error: too few arguments' % sys.argv[0])
90+
exit(0)
91+
8792
if args.quiet:
8893
_logger.setLevel(logging.WARN)
8994
if args.debug:
@@ -92,10 +97,10 @@ def main(argsl=None): # type: (List[str]) -> int
9297
pkg = pkg_resources.require("schema_salad")
9398
if pkg:
9499
if args.version:
95-
print("%s %s" % (sys.argv[0], pkg[0].version))
100+
print("%s Current version: %s" % (sys.argv[0], pkg[0].version))
96101
return 0
97102
else:
98-
_logger.info("%s %s", sys.argv[0], pkg[0].version)
103+
_logger.info("%s Current version: %s", sys.argv[0], pkg[0].version)
99104

100105
# Get the metaschema to validate the schema
101106
metaschema_names, metaschema_doc, metaschema_loader = schema.get_metaschema()

0 commit comments

Comments
 (0)