3 from parse_message_file
import parse_file
, display_services
, to_json
, from_json
, load_from_json_file
, save_to_json_file
6 parser
= argparse
.ArgumentParser(description
="Parse and display message file content.")
7 parser
.add_argument("filename", help="Path to the file to be parsed")
8 parser
.add_argument("--validate-only", "-v", action
="store_true", help="Only validate the file without displaying")
9 parser
.add_argument("--verbose", "-V", action
="store_true", help="Enable verbose mode")
10 parser
.add_argument("--debug", "-d", action
="store_true", help="Enable debug mode")
11 parser
.add_argument("--to-json", "-j", help="Convert the parsed data to JSON and save to a file")
12 parser
.add_argument("--from-json", "-J", help="Load the services data structure from a JSON file")
13 parser
.add_argument("--json-string", "-s", type=str, help="JSON string to parse if --from-json is specified")
15 args
= parser
.parse_args()
20 services
= from_json(args
.json_string
)
22 services
= load_from_json_file(args
.from_json
)
23 display_services(services
)
25 if args
.validate_only
:
26 is_valid
, error_message
, error_line
= parse_file(args
.filename
, validate_only
=True, verbose
=args
.verbose
)
28 print(f
"The file '{args.filename}' is valid.")
30 print(f
"Validation Error: {error_message}")
31 print(f
"Line: {error_line.strip()}")
33 services
= parse_file(args
.filename
, verbose
=args
.verbose
)
35 import pdb
; pdb
.set_trace()
37 save_to_json_file(services
, args
.to_json
)
38 print(f
"Saved JSON to {args.to_json}")
40 display_services(services
)
41 except Exception as e
:
42 print(f
"An error occurred: {e}", file=sys
.stderr
)
45 if __name__
== "__main__":