Coverage for lobster/version.py: 79%
25 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-26 14:55 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-26 14:55 +0000
1#!/usr/bin/env python3
2#
3# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report
4# Copyright (C) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public
17# License along with this program. If not, see
18# <https://www.gnu.org/licenses/>.
19import sys
20from argparse import ArgumentParser
22VERSION_TUPLE = (0, 13, 1)
23VERSION_SUFFIX = "dev"
25LOBSTER_VERSION = ("%u.%u.%u" % VERSION_TUPLE) + (
26 "-%s" % VERSION_SUFFIX if VERSION_SUFFIX else ""
27)
29FULL_NAME = "LOBSTER %s" % LOBSTER_VERSION
32def get_version(obj):
33 """
34 This decorator function is used on function wherever we are parsing
35 the command line arguments which then adds a version argument to the function.
36 If a version flag is passed to the command line arguments then the LOBSTER version
37 is printed.
38 Parameters
39 ----------
40 obj - obj can be an ArgumentParser object or a Function object.
42 Returns - Nothing
43 -------
45 """
46 if isinstance(obj, ArgumentParser):
47 obj.add_argument("-v, --version", action="store_true",
48 default=None,
49 help="Get version for the tool")
51 def version(func):
52 def execution():
53 if (len(sys.argv) > 1 and 53 ↛ 55line 53 didn't jump to line 55 because the condition on line 53 was never true
54 (sys.argv[1] == "--version" or sys.argv[1] == "-v")):
55 print(FULL_NAME)
56 return sys.exit(0)
57 else:
58 return func()
59 return execution
60 return version
61 else:
62 def version(func):
63 if not isinstance(obj, ArgumentParser): 63 ↛ 71line 63 didn't jump to line 71 because the condition on line 63 was always true
64 func.ap.add_argument("-v, --version", action="store_true",
65 default=None,
66 help="Get version for the tool")
67 if (len(sys.argv) > 1 and 67 ↛ 69line 67 didn't jump to line 69 because the condition on line 67 was never true
68 (sys.argv[1] == "--version" or sys.argv[1] == "-v")):
69 print(FULL_NAME)
70 return sys.exit(0)
71 return obj(func)
72 return version