mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
new nominatim --version CLI argument
This commit is contained in:
@@ -18,6 +18,7 @@ from nominatim.config import Configuration
|
|||||||
from nominatim.tools.exec_utils import run_legacy_script, run_php_server
|
from nominatim.tools.exec_utils import run_legacy_script, run_php_server
|
||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
from nominatim import clicmd
|
from nominatim import clicmd
|
||||||
|
from nominatim import version
|
||||||
from nominatim.clicmd.args import NominatimArgs
|
from nominatim.clicmd.args import NominatimArgs
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
@@ -36,6 +37,11 @@ class CommandlineParser:
|
|||||||
self.subs = self.parser.add_subparsers(title='available commands',
|
self.subs = self.parser.add_subparsers(title='available commands',
|
||||||
dest='subcommand')
|
dest='subcommand')
|
||||||
|
|
||||||
|
# Global arguments that only work if no sub-command given
|
||||||
|
self.parser.add_argument('--version', action='version',
|
||||||
|
version=CommandlineParser.nominatim_version_text(),
|
||||||
|
help='Print Nominatim version and exit')
|
||||||
|
|
||||||
# Arguments added to every sub-command
|
# Arguments added to every sub-command
|
||||||
self.default_args = argparse.ArgumentParser(add_help=False)
|
self.default_args = argparse.ArgumentParser(add_help=False)
|
||||||
group = self.default_args.add_argument_group('Default arguments')
|
group = self.default_args.add_argument_group('Default arguments')
|
||||||
@@ -51,6 +57,11 @@ class CommandlineParser:
|
|||||||
group.add_argument('-j', '--threads', metavar='NUM', type=int,
|
group.add_argument('-j', '--threads', metavar='NUM', type=int,
|
||||||
help='Number of parallel threads to use')
|
help='Number of parallel threads to use')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def nominatim_version_text():
|
||||||
|
""" Program name and version number as string
|
||||||
|
"""
|
||||||
|
return "Nominatim version %s.%s.%s.%s\n" % version.NOMINATIM_VERSION
|
||||||
|
|
||||||
def add_subcommand(self, name, cmd):
|
def add_subcommand(self, name, cmd):
|
||||||
""" Add a subcommand to the parser. The subcommand must be a class
|
""" Add a subcommand to the parser. The subcommand must be a class
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ def test_cli_help(cli_call, capsys):
|
|||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
assert captured.out.startswith('usage:')
|
assert captured.out.startswith('usage:')
|
||||||
|
|
||||||
|
def test_cli_version(cli_call, capsys):
|
||||||
|
""" Running nominatim tool --version prints a version string.
|
||||||
|
"""
|
||||||
|
assert cli_call('--version') == 1
|
||||||
|
|
||||||
|
captured = capsys.readouterr()
|
||||||
|
assert captured.out.startswith('Nominatim version')
|
||||||
|
|
||||||
@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')])
|
@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')])
|
||||||
def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid):
|
def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid):
|
||||||
|
|||||||
Reference in New Issue
Block a user