[elbe-devel] [PATCH 1/2] elbepack: commands: add deprecated argument helper for argparse

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Jul 22 09:45:39 CEST 2024


All usage of optparse is being replaced with argparse.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/__init__.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/elbepack/commands/__init__.py b/elbepack/commands/__init__.py
index f11aff3f8525..b14bac8935a2 100644
--- a/elbepack/commands/__init__.py
+++ b/elbepack/commands/__init__.py
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 # SPDX-FileCopyrightText: 2024 Linutronix GmbH
 
+import argparse
 import optparse
 import sys
 
@@ -14,3 +15,14 @@ def add_deprecated_optparse_option(oparser, *args, **kwargs):
     oparser.add_option(*args, **kwargs,
                        action='callback', callback=_deprecated_option_cb,
                        help=optparse.SUPPRESS_HELP)
+
+
+class _DeprecatedArgumentAction(argparse.Action):
+    def __call__(self, parser, namespace, values, option_string):
+        print(f'Deprecated option "{option_string}" was used. This option is a NOOP.',
+              file=sys.stderr)
+
+
+def add_deprecated_argparse_argument(parser, *args, **kwargs):
+    parser.add_argument(*args, **kwargs, action=_DeprecatedArgumentAction,
+                        help=argparse.SUPPRESS)

-- 
2.45.2



More information about the elbe-devel mailing list