diff --git a/parlai/core/script.py b/parlai/core/script.py index e94aaa3839a..4924800998d 100644 --- a/parlai/core/script.py +++ b/parlai/core/script.py @@ -17,6 +17,7 @@ import io import argparse from typing import List, Optional, Dict, Any +import parlai from parlai.core.opt import Opt from parlai.core.params import ParlaiParser, CustomHelpFormatter from abc import abstractmethod @@ -206,7 +207,13 @@ def superscript_main(args=None): parser.add_argument( '--helpall', action='helpall', - help='show all commands, including advanced ones.', + help='List all commands, including advanced ones.', + ) + parser.add_argument( + '--version', + action='version', + version=get_version_string(), + help='Prints version info and exit.', ) parser.set_defaults(super_command=None) subparsers = parser.add_subparsers( @@ -216,13 +223,13 @@ def superscript_main(args=None): 'help', aliases=['h'], help=argparse.SUPPRESS, - description="List the main commands", + description='List the main commands.', ) hparser.set_defaults(super_command='help') hparser = subparsers.add_parser( 'helpall', help=argparse.SUPPRESS, - description="List all commands, including advanced ones.", + description='List all commands, including advanced ones.', ) hparser.set_defaults(super_command='helpall') @@ -265,7 +272,13 @@ def superscript_main(args=None): cmd = opt.pop('super_command') if cmd == 'helpall': parser.print_helpall() + elif cmd == 'versioninfo': + exit(0) elif cmd == 'help' or cmd is None: parser.print_help() elif cmd is not None: return SCRIPT_REGISTRY[cmd].klass._run_from_parser_and_opt(opt, parser) + + +def get_version_string() -> str: + return f"ParlAI version {parlai.__version__}"