Improve argument parser

This commit is contained in:
KnugiHK
2023-02-13 16:31:35 +08:00
parent 10875060c9
commit 2d23052758

View File

@@ -42,13 +42,13 @@ def main():
"--wa", "--wa",
dest="wa", dest="wa",
default=None, default=None,
help="Path to contact database") help="Path to contact database (default: wa.db/ContactsV2.sqlite)")
parser.add_argument( parser.add_argument(
"-m", "-m",
"--media", "--media",
dest="media", dest="media",
default=None, default=None,
help="Path to WhatsApp media folder") help="Path to WhatsApp media folder (default: WhatsApp)")
parser.add_argument( parser.add_argument(
"-b", "-b",
"--backup", "--backup",
@@ -61,20 +61,22 @@ def main():
"--output", "--output",
dest="output", dest="output",
default="result", default="result",
help="Output to specific directory") help="Output to specific directory (default: result)")
parser.add_argument( parser.add_argument(
'-j', '-j',
'--json', '--json',
dest='json', dest='json',
default=False, nargs='?',
action='store_true', default=None,
help="Save the result to a single JSON file") type=str, const="result.json",
help="Save the result to a single JSON file (default if present: result.json)")
parser.add_argument( parser.add_argument(
'-d', '-d',
'--db', '--db',
dest='db', dest='db',
default=None, default=None,
help="Path to database file") help="Path to database file (default: msgstore.db/"
"7c7fba66680ef796b916b067077cc246adacf01d)")
parser.add_argument( parser.add_argument(
'-k', '-k',
'--key', '--key',
@@ -124,7 +126,7 @@ def main():
"--output-size", "--output-size",
dest="size", dest="size",
default=None, default=None,
help="Maximum size of a single output file in bytes (not yet implemented)" help="Maximum size of a single output file in bytes, 0 for auto (not yet implemented)"
) )
args = parser.parse_args() args = parser.parse_args()
@@ -244,7 +246,7 @@ def main():
"Perhaps the directory is opened?") "Perhaps the directory is opened?")
if args.json: if args.json:
with open("result.json", "w") as f: with open(args.json, "w") as f:
data = json.dumps(data) data = json.dumps(data)
print(f"\nWriting JSON file...({int(len(data)/1024/1024)}MB)") print(f"\nWriting JSON file...({int(len(data)/1024/1024)}MB)")
f.write(data) f.write(data)