python: Elide default for store_{true,false} argparse arguments.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-09-02 11:45:48 -07:00 committed by Alex Vandiver
parent d9431a5e66
commit b4597a8ca8
46 changed files with 45 additions and 85 deletions

View File

@ -29,15 +29,13 @@ class Command(BaseCommand):
default=timezone_now().isoformat())
parser.add_argument('--utc',
action='store_true',
help="Interpret --time in UTC.",
default=False)
help="Interpret --time in UTC.")
parser.add_argument('--stat', '-s',
type=str,
help="CountStat to process. If omitted, all stats are processed.")
parser.add_argument('--verbose',
action='store_true',
help="Print timing information to stdout.",
default=False)
help="Print timing information to stdout.")
def handle(self, *args: Any, **options: Any) -> None:
try:

View File

@ -67,10 +67,10 @@ parser.add_argument('-d', '--dst-host', dest="host", type=str, default='https://
parser.add_argument('-u', '--dst-url', dest="url", type=str, default='/email_mirror_message',
help="Destination relative url for uploading email from email mirror.")
parser.add_argument('-n', '--not-verify-ssl', dest="verify_ssl", action='store_false', default=True,
parser.add_argument('-n', '--not-verify-ssl', dest="verify_ssl", action='store_false',
help="Disable ssl certificate verifying for self-signed certificates")
parser.add_argument('-t', '--test', action='store_true', default=False,
parser.add_argument('-t', '--test', action='store_true',
help="Test mode.")
options = parser.parse_args()

View File

@ -17,7 +17,7 @@ logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('--fill-cache', action='store_true', default=False,
parser.add_argument('--fill-cache', action='store_true',
help='Fill the memcached caches')
args = parser.parse_args()

View File

@ -21,11 +21,11 @@ DJANGO_PO_REGEX = re.compile('msgid "(.*?)"')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--show-ignored',
action='store_true', default=False,
action='store_true',
help='Show strings that passed the check because they '
'contained ignored phrases.')
parser.add_argument('--no-generate',
action='store_true', default=False,
action='store_true',
help="Don't run makemessages command.")
args = parser.parse_args()

View File

@ -26,7 +26,7 @@ def find_handlebars(translatable_strings: List[str]) -> List[str]:
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--no-generate',
action='store_true', default=False,
action='store_true',
help="Don't run makemessages command.")
args = parser.parse_args()

View File

@ -44,7 +44,7 @@ def get_next_page_url(link_header: str) -> Optional[str]:
def check_issue_labels() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--force', action="store_true", default=False)
parser.add_argument('--force', action="store_true")
args = parser.parse_args()
if not args.force:

View File

@ -12,7 +12,7 @@ from tools.lib.test_script import assert_provisioning_status_ok
def run() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--force', default=False,
parser.add_argument('--force',
action="store_true",
help='Run tests despite possible problems.')
options = parser.parse_args()

View File

@ -156,13 +156,13 @@ def check_handlebar_templates(templates: Iterable[str], fix: bool) -> None:
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--modified',
action='store_true', default=False,
action='store_true',
help='only check modified files')
parser.add_argument('--all-dups',
action="store_true", default=False,
action="store_true",
help='Run lint tool to detect duplicate ids on ignored files as well')
parser.add_argument('--fix',
action='store_true', default=False,
action='store_true',
help='Automatically fix indentation problems.')
parser.add_argument('targets', nargs=argparse.REMAINDER)
args = parser.parse_args()

View File

@ -21,7 +21,7 @@ import requests
parser = ArgumentParser(description='Give a mentor ssh access to this machine.')
parser.add_argument('username', help='Github username of the mentor.')
parser.add_argument('--remove', help='Remove his/her key from the machine.',
action='store_true', default=False)
action='store_true')
# Wrap keys with line comments for easier key removal.
append_key = """\

View File

@ -30,7 +30,7 @@ import digitalocean
parser = argparse.ArgumentParser(description='Create a Zulip devopment VM DigitalOcean droplet.')
parser.add_argument("username", help="Github username for whom you want to create a Zulip dev droplet")
parser.add_argument('--tags', nargs='+', default=[])
parser.add_argument('-f', '--recreate', action="store_true", default=False)
parser.add_argument('-f', '--recreate', action="store_true")
def get_config() -> configparser.ConfigParser:
config = configparser.ConfigParser()

View File

@ -193,7 +193,7 @@ def generate_screenshot_from_config(integration_name: str, screenshot_config: Sc
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--all', default=False, action='store_true')
group.add_argument('--all', action='store_true')
group.add_argument('--integration', type=str, help='Name of the integration')
parser.add_argument('--fixture', type=str, help='Name of the fixture file to use')
parser.add_argument('--image-name', type=str, help='Name for the screenshot image')

View File

@ -421,16 +421,13 @@ if __name__ == "__main__":
description = ("Provision script to install Zulip")
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--force', action='store_true', dest='is_force',
default=False,
help="Ignore all provisioning optimizations.")
parser.add_argument('--build-release-tarball-only', action='store_true',
dest='is_build_release_tarball_only',
default=False,
help="Provision needed to build release tarball.")
parser.add_argument('--skip-dev-db-build', action='store_true',
default=False,
help="Don't run migrations on dev database.")
options = parser.parse_args()

View File

@ -328,16 +328,13 @@ def main(options: argparse.Namespace) -> int:
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--force', action='store_true', dest='is_force',
default=False,
help="Ignore all provisioning optimizations.")
parser.add_argument('--build-release-tarball-only', action='store_true',
dest='is_build_release_tarball_only',
default=False,
help="Provision for test suite with production settings.")
parser.add_argument('--skip-dev-db-build', action='store_true',
default=False,
help="Don't run migrations on dev database.")
options = parser.parse_args()

View File

@ -16,7 +16,7 @@ from linter_lib.custom_check import non_py_rules, python_rules
def run() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--force', default=False,
parser.add_argument('--force',
action="store_true",
help='Run tests despite possible problems.')
parser.add_argument('--full',

View File

@ -52,16 +52,16 @@ parser.add_argument('--interface',
default=None, help='Set the IP or hostname for the proxy to listen on')
parser.add_argument('--no-clear-memcached',
action='store_false', dest='clear_memcached',
default=True, help='Do not clear memcached')
help='Do not clear memcached')
parser.add_argument('--streamlined',
action="store_true",
default=False, help='Avoid thumbor, etc.')
help='Avoid thumbor, etc.')
parser.add_argument('--force',
action="store_true",
default=False, help='Run command despite possible problems.')
help='Run command despite possible problems.')
parser.add_argument('--enable-tornado-logging',
action="store_true",
default=False, help='Enable access logs from tornado proxy server.')
help='Enable access logs from tornado proxy server.')
options = parser.parse_args()
assert_provisioning_status_ok(options.force)

View File

@ -23,7 +23,7 @@ usage = """test-api [options]"""
parser = argparse.ArgumentParser(usage)
parser.add_argument('--force',
action="store_true",
default=False, help='Run tests despite possible provisioning problems.')
help='Run tests despite possible provisioning problems.')
options = parser.parse_args()
assert_provisioning_status_ok(options.force)

View File

@ -209,18 +209,16 @@ def main() -> None:
parser = argparse.ArgumentParser(description=usage,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--nonfatal-errors', action="store_false", default=True,
parser.add_argument('--nonfatal-errors', action="store_false",
dest="fatal_errors", help="Continue past test failures to run all tests")
parser.add_argument('--coverage',
action="store_true",
default=False,
help='Compute test coverage.')
parser.add_argument('--verbose-coverage',
action="store_true",
default=False, help='Enable verbose print of coverage report.')
help='Enable verbose print of coverage report.')
parser.add_argument('--no-cov-cleanup',
action='store_true',
default=False,
help="Do not clean generated coverage files.")
parser.add_argument('--parallel', dest='processes',
@ -231,39 +229,33 @@ def main() -> None:
'tests in. Default is the number of logical CPUs')
parser.add_argument('--profile',
action="store_true",
default=False, help='Profile test runtime.')
help='Profile test runtime.')
parser.add_argument('--force',
action="store_true",
default=False, help='Run tests despite possible problems.')
help='Run tests despite possible problems.')
parser.add_argument('--no-shallow',
action="store_true",
default=False,
help="Don't allow shallow testing of templates (deprecated)")
parser.add_argument('--verbose',
action="store_true",
default=False,
help="Show detailed output")
parser.add_argument('--reverse',
action="store_true",
default=False,
help="Run tests in reverse order.")
parser.add_argument('--rerun',
action="store_true",
default=False,
help=("Run the tests which failed the last time "
"test-backend was run. Implies --nonfatal-errors."))
parser.add_argument('--include-webhooks',
action="store_true",
default=False,
help=("Include webhook tests. By default, they are skipped for performance."))
parser.add_argument('--generate-stripe-fixtures',
action="store_true",
default=False,
help=("Generate Stripe test fixtures by making requests to Stripe test network"))
parser.add_argument('args', nargs='*')
parser.add_argument('--ban-console-output',
action="store_true",
default=False, help='Require stdout and stderr to be clean of unexpected output.')
help='Require stdout and stderr to be clean of unexpected output.')
options = parser.parse_args()
if options.ban_console_output:

View File

@ -14,10 +14,10 @@ from lib import sanity_check
sanity_check.check_venv(__file__)
parser = argparse.ArgumentParser()
parser.add_argument('--force', default=False,
parser.add_argument('--force',
action="store_true",
help='Run tests despite possible problems.')
parser.add_argument('--skip-external-links', default=False,
parser.add_argument('--skip-external-links',
dest="skip_external_link_check",
action="store_true",
help='Skip checking of external links.')

View File

@ -166,10 +166,10 @@ EXEMPT_FILES = {
parser = argparse.ArgumentParser(USAGE)
parser.add_argument('--coverage',
action="store_true",
default=False, help='Get coverage report')
help='Get coverage report')
parser.add_argument('--force',
action="store_true",
default=False, help='Run tests despite possible problems.')
help='Run tests despite possible problems.')
parser.add_argument('args', nargs=argparse.REMAINDER)
options = parser.parse_args()
individual_files = options.args

View File

@ -29,10 +29,10 @@ parser = argparse.ArgumentParser(usage)
parser.add_argument('--interactive',
action="store_true",
default=False, help='Run tests interactively')
help='Run tests interactively')
parser.add_argument('--force',
action="store_true",
default=False, help='Run tests despite possible problems.')
help='Run tests despite possible problems.')
parser.add_argument('tests', nargs=argparse.REMAINDER,
help='Specific tests to run; by default, runs all tests')

View File

@ -13,7 +13,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--coverage',
action="store_true",
default=False, help='compute test coverage')
help='compute test coverage')
args = parser.parse_args()
def dir_join(dir1: str, dir2: str) -> str:

View File

@ -112,13 +112,13 @@ def build_for_most_tests() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--test',
action='store_true', default=False,
action='store_true',
help='generate a stub webpack-stats.json file (for backend testing)')
parser.add_argument('--quiet',
action='store_true', default=False,
action='store_true',
help='Minimizes webpack output while running')
parser.add_argument('--watch',
action='store_true', default=False,
action='store_true',
help='watch for changes to source files (for development)')
parser.add_argument('--host',
action='store',
@ -127,10 +127,10 @@ parser.add_argument('--port',
action='store',
default='9994', help='set the port for the webpack server to run on')
parser.add_argument('--minify',
action='store_true', default=False,
action='store_true',
help='Minify and optimize the assets (for development)')
parser.add_argument('--disable-host-check',
action='store_true', default=None,
action='store_true',
help='Disable host check for webpack-dev-server')
args = parser.parse_args()

View File

@ -65,7 +65,6 @@ You can use the command list_realms to find ID of the realms in this server."""
parser.add_argument(
'-a', '--all-users',
action="store_true",
default=False,
help=all_users_help)
def get_realm(self, options: Dict[str, Any]) -> Optional[Realm]:

View File

@ -17,7 +17,6 @@ class Command(BaseCommand):
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument('-t', '--trim',
default=False,
action='store_true',
help="Actually trim excess")

View File

@ -23,7 +23,6 @@ class Command(compilemessages.Command):
parser.add_argument(
'--strict', '-s',
action='store_true',
default=False,
help='Stop execution in case of errors.')
def handle(self, *args: Any, **options: Any) -> None:

View File

@ -24,7 +24,6 @@ Omit both <email> and <full name> for interactive user creation.
parser.add_argument('--this-user-has-accepted-the-tos',
dest='tos',
action="store_true",
default=False,
help='Acknowledgement that the user has already accepted the ToS.')
parser.add_argument('--password',
type=str,

View File

@ -13,7 +13,6 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('-f', '--for-real',
action='store_true',
default=False,
help="Actually deactivate the user. Default is a dry run.")
parser.add_argument('email', metavar='<email>', type=str,
help='email of user to deactivate')

View File

@ -21,7 +21,6 @@ class Command(BaseCommand):
parser.add_argument('-f', '--for-real',
action='store_true',
default=False,
help="Actually remove the files from the storage.")
def handle(self, *args: Any, **options: Any) -> None:

View File

@ -21,7 +21,6 @@ class Command(ZulipBaseCommand):
help='email address to spelunk')
parser.add_argument('--all',
action='store_true',
default=False,
help='fix all users in specified realm')
self.add_realm_args(parser)

View File

@ -15,7 +15,6 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--force',
action="store_true",
default=False,
help='Override that the domain is restricted to external users.')
parser.add_argument('emails', metavar='<email>', type=str, nargs='*',
help='email of users to generate an activation link for')

View File

@ -19,12 +19,10 @@ import a database dump from one or more JSON files."""
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument('--destroy-rebuild-database',
default=False,
action="store_true",
help='Destroys and rebuilds the databases prior to import.')
parser.add_argument('--import-into-nonempty',
default=False,
action="store_true",
help='Import into an existing nonempty database.')

View File

@ -18,12 +18,10 @@ ONLY perform this on customer request from an authorized person.
parser.add_argument('-f', '--for-real',
dest='ack',
action="store_true",
default=False,
help='Acknowledgement that this is done according to policy.')
parser.add_argument('--revoke',
dest='grant',
action="store_false",
default=True,
help='Remove an administrator\'s rights.')
parser.add_argument('--permission',
action="store",

View File

@ -17,7 +17,6 @@ Usage examples:
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument("--all",
action="store_true",
default=False,
help="Print all the configuration settings of the realms.")
def handle(self, *args: Any, **options: Any) -> None:

View File

@ -15,7 +15,6 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--deactivated-only',
action='store_true',
default=False,
help="Only logout all users who are deactivated")
self.add_realm_args(parser, help="Only logout all users in a particular realm")

View File

@ -19,7 +19,7 @@ class Command(BaseCommand):
help="queue to process")
parser.add_argument('--worker_num', metavar='<worker number>', type=int, nargs='?', default=0,
help="worker label")
parser.add_argument('--all', action="store_true", default=False,
parser.add_argument('--all', action="store_true",
help="run all queues")
parser.add_argument('--multi_threaded', nargs='+',
metavar='<list of queue name>',

View File

@ -13,7 +13,7 @@ class Command(BaseCommand):
parser.add_argument(dest="queue_name", type=str, nargs='?',
help="queue to purge", default=None)
parser.add_argument('--all', action="store_true",
default=False, help="purge all queues")
help="purge all queues")
help = "Discards all messages from the given queue"

View File

@ -24,7 +24,6 @@ class Command(ZulipBaseCommand):
parser.add_argument('-b', '--all-bots',
dest='bots',
action='store_true',
default=False,
help="Whether or not to also block all bots for this user.")
parser.add_argument('operation', metavar='<operation>', type=str, choices=['block', 'unblock'],
help="operation to perform (block or unblock)")

View File

@ -20,7 +20,6 @@ class Command(ZulipBaseCommand):
help='What operation to do (add, show, remove).')
parser.add_argument('--allow-subdomains',
action="store_true",
default=False,
help='Whether subdomains are allowed or not.')
parser.add_argument('domain', metavar='<domain>', type=str, nargs='?',
help="domain to add or remove")

View File

@ -21,11 +21,9 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--agree_to_terms_of_service',
action='store_true',
default=False,
help="Agree to the Zulipchat Terms of Service: https://zulip.com/terms/.")
parser.add_argument('--rotate-key',
action='store_true',
default=False,
help="Automatically rotate your server's zulip_org_key")
def handle(self, **options: Any) -> None:

View File

@ -46,11 +46,11 @@ class Command(BaseCommand):
'(use multiple ports to start multiple servers)')
parser.add_argument('--nokeepalive', action='store_true',
dest='no_keep_alive', default=False,
dest='no_keep_alive',
help="Tells Tornado to NOT keep alive http connections.")
parser.add_argument('--noxheaders', action='store_false',
dest='xheaders', default=True,
dest='xheaders',
help="Tells Tornado to NOT override remote IP with X-Real-IP.")
def handle(self, addrport: str, **options: bool) -> None:

View File

@ -16,7 +16,7 @@ class Command(ZulipBaseCommand):
document used to generate the email, or on the command line."""
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--entire-server', action="store_true", default=False,
parser.add_argument('--entire-server', action="store_true",
help="Send to every user on the server.")
parser.add_argument('--markdown-template-path', '--path',
required=True,

View File

@ -13,7 +13,7 @@ class Command(ZulipBaseCommand):
help = """Send email to specified email address."""
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('--entire-server', action="store_true", default=False,
parser.add_argument('--entire-server', action="store_true",
help="Send to every user on the server. ")
self.add_user_list_args(parser,
help="Email addresses of user(s) to send password reset emails to.",

View File

@ -17,7 +17,6 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: CommandParser) -> None:
parser.add_argument('-l', '--for-real',
action='store_true',
default=False,
help="Actually change message flags. Default is a dry run.")
parser.add_argument('-f', '--flag',

View File

@ -39,11 +39,9 @@ class Command(ZulipBaseCommand):
self.add_realm_args(parser)
parser.add_argument('-d', '--deactivate',
action='store_true',
default=False,
help='Used to deactivate user/users.')
parser.add_argument('-a', '--activate',
action='store_true',
default=False,
help='Used to activate user/users.')
parser.add_argument('--inactive-for',
type=int,

View File

@ -54,7 +54,6 @@ class Command(ZulipBaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument('-f', '--force',
action="store_true",
default=False,
help='Disable the protection against deactivating all users.')
self.add_realm_args(parser)

View File

@ -223,12 +223,10 @@ class Command(BaseCommand):
parser.add_argument('--nodelete',
action="store_false",
default=True,
dest='delete',
help='Whether to delete all the existing messages.')
parser.add_argument('--test-suite',
default=False,
action="store_true",
help='Configures populate_db to create a deterministic '
'data set for the backend tests.')