[elbe-devel] [PATCH 3/9] elbepack: main: allow specification of custom argv

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Jul 25 11:47:13 CEST 2024


To execute elbe subcommands from other parts of elbe it is useful to
explicitly specify an argv to use.

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

diff --git a/elbepack/main.py b/elbepack/main.py
index 7719dd9470f5..431e1c4b3a24 100644
--- a/elbepack/main.py
+++ b/elbepack/main.py
@@ -22,28 +22,28 @@ def usage():
         print('        * %s' % i)
 
 
-def main():
+def main(argv=sys.argv):
     # with python -melbepack the optparse usage message would show __main__.py
-    if sys.argv[0].endswith('__main__.py'):
-        sys.argv[0] = 'elbe'
+    if argv[0].endswith('__main__.py'):
+        argv[0] = 'elbe'
 
-    if len(sys.argv) < 2:
+    if len(argv) < 2:
         usage()
         sys.exit(20)
 
-    if sys.argv[1] == '--version':
+    if argv[1] == '--version':
         print('elbe v%s' % (elbe_version))
         sys.exit(0)
 
     cmd_list = get_cmdlist()
 
-    if sys.argv[1] not in cmd_list:
+    if argv[1] not in cmd_list:
         print('Unknown subcommand !\n')
         usage()
         sys.exit(20)
 
-    modname = 'elbepack.commands.' + sys.argv[1]
+    modname = 'elbepack.commands.' + argv[1]
 
     cmdmod = importlib.import_module(modname)
 
-    cmdmod.run_command(sys.argv[2:])
+    cmdmod.run_command(argv[2:])

-- 
2.45.2



More information about the elbe-devel mailing list