laforge has uploaded this change for review.

View Change

pySim-shell: Use arparser for verify_adm to support --help

Let's add a proper argparser instance for the 'verify_adm' command,
avoiding situations where the user types 'verif_adm --help' and then
--help is interpreted as the PIN value, removing one more attempt from
the failed ADM1 counter.

Let's use that opportunity to improve the documentation of the command.

Change-Id: I3321fae66a11efd00c53b66c7890fce84796e658
---
M docs/shell.rst
M pySim-shell.py
2 files changed, 32 insertions(+), 7 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/44/34944/1
diff --git a/docs/shell.rst b/docs/shell.rst
index 7e04792..6da16ec 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -137,10 +137,11 @@

verify_adm
~~~~~~~~~~
-Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order
-to get write/update permissions to most of the files on SIM cards.

-Currently only ADM1 is supported.
+.. argparse::
+ :module: pySim-shell
+ :func: PySimCommands.verify_adm_parser
+

Example (successful):
::
diff --git a/pySim-shell.py b/pySim-shell.py
index c02555f..7aaa234 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -776,11 +776,19 @@
else:
self._cmd.poutput("no description available")

- def do_verify_adm(self, arg):
- """VERIFY the ADM1 PIN"""
- if arg:
+ verify_adm_parser = argparse.ArgumentParser()
+ verify_adm_parser.add_argument('ADM1', nargs='?', type=str,
+ help='ADM1 pin value. If none given, CSV file will be queried')
+
+ @cmd2.with_argparser(verify_adm_parser)
+ def do_verify_adm(self, opts):
+ """Verify the ADM (Administrator) PIN specified as argument. This is typically needed in order
+to get write/update permissions to most of the files on SIM cards.
+
+Currently only ADM1 is supported."""
+ if opts.ADM1:
# use specified ADM-PIN
- pin_adm = sanitize_pin_adm(arg)
+ pin_adm = sanitize_pin_adm(opts.ADM1)
else:
# try to find an ADM-PIN if none is specified
result = card_key_provider_get_field(

To view, visit change 34944. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I3321fae66a11efd00c53b66c7890fce84796e658
Gerrit-Change-Number: 34944
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange