Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

add a --version flag to the parlai command #3163 #3164

Merged
merged 5 commits into from
Oct 7, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions parlai/core/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,10 +204,18 @@ def superscript_main(args=None):
parser = _SupercommandParser(
False, False, formatter_class=_SuperscriptHelpFormatter
)
helpall_help_str = 'List all commands, including advanced ones.'
parser.add_argument(
'--helpall',
action='helpall',
help='show all commands, including advanced ones.',
DNGros marked this conversation as resolved.
Show resolved Hide resolved
help=helpall_help_str,
)
versioninfo_help_str = 'Prints version info and exit.'
parser.add_argument(
'--version',
action='version',
version=get_version_string(),
help=versioninfo_help_str,
)
parser.set_defaults(super_command=None)
subparsers = parser.add_subparsers(
Expand All @@ -222,7 +231,7 @@ def superscript_main(args=None):
hparser = subparsers.add_parser(
'helpall',
help=argparse.SUPPRESS,
description="List all commands, including advanced ones.",
description=helpall_help_str,
)
hparser.set_defaults(super_command='helpall')

Expand Down Expand Up @@ -265,7 +274,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__}"