X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/878835e4bd4d9ff480fe067928787a4c8e9c2535..04644102f2721d6fa6fbb86af8fb7ad8267add56:/nominatim/cli.py diff --git a/nominatim/cli.py b/nominatim/cli.py index 7fae205b..f911023b 100644 --- a/nominatim/cli.py +++ b/nominatim/cli.py @@ -1,3 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ Command-line interface to the Nominatim functions for import, update, database administration and querying. @@ -12,6 +18,7 @@ from nominatim.config import Configuration from nominatim.tools.exec_utils import run_legacy_script, run_php_server from nominatim.errors import UsageError from nominatim import clicmd +from nominatim import version from nominatim.clicmd.args import NominatimArgs LOG = logging.getLogger() @@ -30,6 +37,10 @@ class CommandlineParser: self.subs = self.parser.add_subparsers(title='available commands', dest='subcommand') + # Global arguments that only work if no sub-command given + self.parser.add_argument('--version', action='store_true', + help='Print Nominatim version and exit') + # Arguments added to every sub-command self.default_args = argparse.ArgumentParser(add_help=False) group = self.default_args.add_argument_group('Default arguments') @@ -45,6 +56,14 @@ class CommandlineParser: group.add_argument('-j', '--threads', metavar='NUM', type=int, help='Number of parallel threads to use') + @staticmethod + def nominatim_version_text(): + """ Program name and version number as string + """ + text = f'Nominatim version {version.version_str()}' + if version.GIT_COMMIT_HASH is not None: + text += f' ({version.GIT_COMMIT_HASH})' + return text def add_subcommand(self, name, cmd): """ Add a subcommand to the parser. The subcommand must be a class @@ -64,7 +83,14 @@ class CommandlineParser: appropriate subcommand. """ args = NominatimArgs() - self.parser.parse_args(args=kwargs.get('cli_args'), namespace=args) + try: + self.parser.parse_args(args=kwargs.get('cli_args'), namespace=args) + except SystemExit: + return 1 + + if args.version: + print(CommandlineParser.nominatim_version_text()) + return 0 if args.subcommand is None: self.parser.print_help() @@ -176,7 +202,7 @@ class AdminServe: This command starts the built-in PHP webserver to serve the website from the current project directory. This webserver is only suitable - for testing and develop. Do not use it in production setups! + for testing and development. Do not use it in production setups! By the default, the webserver can be accessed at: http://127.0.0.1:8088 """