diff mbox series

[yocto-patches,meta-zephyr,master,4/9] generate-version.py: Add verion and help options

Message ID 20260307044353.1936182-5-sandeep.gundlupet-raju@amd.com
State New
Headers show
Series Update to v4.3.0 | expand

Commit Message

Gundlupet Raju, Sandeep March 7, 2026, 4:43 a.m. UTC
Replace basic sys.argv argument parsing with argparse module to provide:
- Change the Zephyr version argument from a positional argument to an
  explicit -v/--version option, making the intent clearer at the command
  line.
- Proper -h/--help option with usage information.
- Better error messages for invalid version format.
- Usage examples in help text.
- Improved user experience.
- Update README.md with usage.

The script now displays helpful information when called with --help:
  $ generate-version.py --help
  usage: generate-version.py [-h] -v VERSION

  Generate Zephyr kernel source include file for a specific version

  options:
    -h, --help            show this help message and exit
    -v VERSION, --version VERSION
                        Zephyr version in the form x.y.z (e.g., 3.7.0, 4.3.0)

  Example:
    generate-version.py -v 3.7.0
    generate-version.py --version 4.3.0

AI-Generated: GitHub Copilot (Claude Sonnet 4.6)

Signed-off-by: Sandeep Gundlupet Raju <sandeep.gundlupet-raju@amd.com>
---
 README.md                                    |  2 +-
 meta-zephyr-core/scripts/generate-version.py | 25 ++++++++++++++++----
 2 files changed, 22 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/README.md b/README.md
index 0aa55e1..4a7d75a 100644
--- a/README.md
+++ b/README.md
@@ -216,7 +216,7 @@  Yocto configuration for a Zephyr version from the West configuration in the
 Zephyr repository. It requires the west and jinja2 Python packages to be
 installed on the host. Run it as follows:
 ```
-    $ ./meta-zephyr-core/scripts/generate-version.py x.x.x
+    $ ./meta-zephyr-core/scripts/generate-version.py -v x.x.x
 ```
 
 where x.x.x is the Zephyr version.
diff --git a/meta-zephyr-core/scripts/generate-version.py b/meta-zephyr-core/scripts/generate-version.py
index d795a70..c8f79d4 100755
--- a/meta-zephyr-core/scripts/generate-version.py
+++ b/meta-zephyr-core/scripts/generate-version.py
@@ -1,5 +1,6 @@ 
 #!/usr/bin/env python3
 
+import argparse
 import pathlib
 import re
 import subprocess
@@ -11,10 +12,26 @@  import urllib.request
 import jinja2
 import west.manifest
 
-# This script takes one argument - the Zephyr version in the form x.y.z
-version = sys.argv[1]
-if not re.match(r'\d+.\d+.\d+', version):
-    raise ValueError("Please provide a valid Zephyr version")
+# Set up argument parser
+parser = argparse.ArgumentParser(
+    description='Generate Zephyr kernel source include file for a specific version',
+    formatter_class=argparse.RawDescriptionHelpFormatter,
+    epilog='''
+Example:
+  %(prog)s -v 3.7.0
+  %(prog)s --version 4.3.0
+    ''')
+parser.add_argument('-v', '--version',
+                    required=True,
+                    metavar='VERSION',
+                    help='Zephyr version in the form x.y.z (e.g., 3.7.0, 4.3.0)')
+
+args = parser.parse_args()
+version = args.version
+
+# Validate version format
+if not re.match(r'\d+\.\d+\.\d+', version):
+    parser.error(f"Invalid version format: '{version}'. Please provide a valid Zephyr version (e.g., 3.7.0)")
 
 # Obtain the West manifest and decode using west as a library
 manifest_url = f'https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v{version}/west.yml'