Instead of --import paying attention to --format, leave --format
just for the export-format and give --import itself an optional
arguent that is the import format.  This of course defaults to 'jrnl'.
This allows argparse to do the choice-checking.
This commit is contained in:
Paul Jimenez 2022-08-23 15:13:37 -04:00
parent 72d1a044d9
commit ff3dc08af3
2 changed files with 7 additions and 7 deletions

View file

@ -121,18 +121,19 @@ def parse_args(args=[]):
) )
standalone.add_argument( standalone.add_argument(
"--import", "--import",
action="store_const",
metavar="TYPE", metavar="TYPE",
const=postconfig_import, dest="import_format",
dest="postconfig_cmd", nargs="?",
choices=IMPORT_FORMATS,
default="jrnl",
help=f""" help=f"""
Import entries from another journal. Import entries from another journal.
TYPE is the format to import [{util.oxford_list(IMPORT_FORMATS)}] (default: jrnl)
Optional parameters: Optional parameters:
--file FILENAME (default: uses stdin) --file FILENAME (default: uses stdin)
--format [{util.oxford_list(IMPORT_FORMATS)}] (default: jrnl)
""", """,
) )
standalone.add_argument( standalone.add_argument(

View file

@ -69,8 +69,7 @@ def postconfig_import(args, config, **kwargs):
# Requires opening the journal # Requires opening the journal
journal = open_journal(args.journal_name, config) journal = open_journal(args.journal_name, config)
format = args.export if args.export else "jrnl" get_importer(args.import_format).import_(journal, args.filename)
get_importer(format).import_(journal, args.filename)
def postconfig_encrypt(args, config, original_config, **kwargs): def postconfig_encrypt(args, config, original_config, **kwargs):