Skip to content

Commit 60f0b94

Browse files
committed
Improve cli by using argparse
1 parent 411b3b1 commit 60f0b94

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

jsonsubschema/cli.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
@author: Andrew Habib
44
'''
55

6-
import sys
6+
import argparse
77

88
from jsonsubschema._utils import load_json_file
99
from jsonsubschema.api import isSubschema
1010

1111

1212
def main():
13+
''' CLI entry point for jsonsubschema '''
14+
15+
parser = argparse.ArgumentParser(description='CLI for ssonsubschema tool which checks whether a LHS JSON schema is a subschema (<:) of another RHS JSON schema.')
16+
parser.add_argument('LHS', metavar='lhs', type=str, help='Path to the JSON file which has the LHS JSON schema')
17+
parser.add_argument('RHS', metavar='rhs', type=str, help='Path to the JSON file which has the RHS JSON schema')
1318

14-
assert len(
15-
sys.argv) == 3, "jsonsubschema cli takes exactly two arguments lhs_schema and rhs_schema"
19+
args = parser.parse_args()
20+
s1_file_path = args.LHS
21+
s2_file_path = args.RHS
1622

17-
s1_file = sys.argv[1]
18-
s2_file = sys.argv[2]
19-
20-
s1 = load_json_file(s1_file, "LHS file:")
21-
s2 = load_json_file(s2_file, "RHS file:")
23+
s1 = load_json_file(s1_file_path, "LHS file:")
24+
s2 = load_json_file(s2_file_path, "RHS file:")
2225

2326
print("LHS <: RHS", isSubschema(s1, s2))
24-
print("RHS <: LHS", isSubschema(s2, s1))
25-
2627

2728
if __name__ == "__main__":
2829

0 commit comments

Comments
 (0)