From 38306dfc047c5dabcd4995ce82f1c15099c830de Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 11 Jul 2023 21:17:55 +0200 Subject: [PATCH] pySim-shell: Add a mode where a pySim-shell cmd can be passed by shell This adds a new operation mode for pySim-shell, where a single command can be passed to pySim-shell, which then is executed before pySim-shell terminates. Example: ./pySim-shell.py -p0 export --json Change-Id: I0ed379b23a4b1126006fd8f9e7ba2ba07fb01ada Closes: OS#6088 --- pySim-shell.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pySim-shell.py b/pySim-shell.py index 213f057d..3b56bfd1 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -982,6 +982,11 @@ adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', de adm_group.add_argument('-A', '--pin-adm-hex', metavar='PIN_ADM1_HEX', dest='pin_adm_hex', default=None, help='ADM PIN used for provisioning, as hex string (16 characters long)') +option_parser.add_argument("command", nargs='?', + help="A pySim-shell command that would optionally be executed at startup") +option_parser.add_argument('command_args', nargs=argparse.REMAINDER, + help="Optional Arguments for command") + if __name__ == '__main__': @@ -1045,4 +1050,7 @@ if __name__ == '__main__': except Exception as e: print(e) - app.cmdloop() + if opts.command: + app.onecmd_plus_hooks('{} {}'.format(opts.command, ' '.join(opts.command_args))) + else: + app.cmdloop()