aboutsummaryrefslogtreecommitdiff
path: root/tools/binman/cmdline.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-11-23 11:03:42 -0700
committerSimon Glass <sjg@chromium.org>2021-12-02 09:16:30 -0700
commitc475decf59a6460bbd706199d8157f2fd2c4f4fc (patch)
tree144b0e99f9493e18c23a081397b624812af6e6db /tools/binman/cmdline.py
parent650e5de7d407a3a9d2a9cc693eb8b1290a768d65 (diff)
downloadu-boot-c475decf59a6460bbd706199d8157f2fd2c4f4fc.zip
u-boot-c475decf59a6460bbd706199d8157f2fd2c4f4fc.tar.gz
u-boot-c475decf59a6460bbd706199d8157f2fd2c4f4fc.tar.bz2
binman: Add a way to obtain the version
Add a -V option which shows the version number of binman. For now this just uses a local 'version' file. Once the tool is packaged in some way we can figure out an approach that suits. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/cmdline.py')
-rw-r--r--tools/binman/cmdline.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index 14ec95c..2229316 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -5,7 +5,9 @@
"""Command-line parser for binman"""
+import argparse
from argparse import ArgumentParser
+import state
def make_extract_parser(subparsers):
"""make_extract_parser: Make a subparser for the 'extract' command
@@ -26,6 +28,32 @@ def make_extract_parser(subparsers):
extract_parser.add_argument('-U', '--uncompressed', action='store_true',
help='Output raw uncompressed data for compressed entries')
+
+#pylint: disable=R0903
+class BinmanVersion(argparse.Action):
+ """Handles the -V option to binman
+
+ This reads the version information from a file called 'version' in the same
+ directory as this file.
+
+ If not present it assumes this is running from the U-Boot tree and collects
+ the version from the Makefile.
+
+ The format of the version information is three VAR = VALUE lines, for
+ example:
+
+ VERSION = 2022
+ PATCHLEVEL = 01
+ EXTRAVERSION = -rc2
+ """
+ def __init__(self, nargs=0, **kwargs):
+ super().__init__(nargs=nargs, **kwargs)
+
+ def __call__(self, parser, namespace, values, option_string=None):
+ parser._print_message(f'Binman {state.GetVersion()}\n')
+ parser.exit()
+
+
def ParseArgs(argv):
"""Parse the binman command-line arguments
@@ -59,6 +87,7 @@ controlled by a description in the board device tree.'''
parser.add_argument('-v', '--verbosity', default=1,
type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
'3=info, 4=detail, 5=debug')
+ parser.add_argument('-V', '--version', nargs=0, action=BinmanVersion)
subparsers = parser.add_subparsers(dest='cmd')
subparsers.required = True