artiq_coreconfig: better arg parsing

This commit is contained in:
Yann Sionneau 2015-06-18 17:07:03 +02:00
parent d25a07f668
commit 77ca8bbf0f
2 changed files with 12 additions and 8 deletions

View File

@ -17,7 +17,7 @@ def get_argparser():
subparsers.required = True
p_read = subparsers.add_parser("read",
help="read key from core device config")
p_read.add_argument("-k", "--key", type=to_bytes, required=True,
p_read.add_argument("key", type=to_bytes,
help="key to be read from core device config")
p_write = subparsers.add_parser("write",
help="write key-value records to core "
@ -34,8 +34,8 @@ def get_argparser():
subparsers.add_parser("erase", help="erase core device config")
p_delete = subparsers.add_parser("delete",
help="delete key from core device config")
p_delete.add_argument("-k", "--key", action="append", default=[],
type=to_bytes, required=True,
p_delete.add_argument("key", nargs=argparse.REMAINDER,
default=[], type=to_bytes,
help="key to be deleted from core device config")
parser.add_argument("--ddb", default="ddb.pyon",
help="device database file")

View File

@ -109,18 +109,18 @@ When not specified, the artiq_coreconfig tool will assume that there is a file n
To read the record whose key is ``mac``::
$ artiq_coreconfig read -k mac
$ artiq_coreconfig read mac
To write the value ``test_value`` in the key ``my_key``::
$ artiq_coreconfig write -s my_key test_value
$ artiq_coreconfig read -k my_key
$ artiq_coreconfig read my_key
b'test_value'
You can also write entire files in a record using the ``-f`` parameter. This is useful for instance to write the ``idle`` kernel in the flash storage::
$ artiq_coreconfig write -f idle_kernel idle.elf
$ artiq_coreconfig read -k idle_kernel | head -c9
$ artiq_coreconfig read idle_kernel | head -c9
b'\x7fELF
You can write several records at once::
@ -129,7 +129,11 @@ You can write several records at once::
To remove the previously written key ``my_key``::
$ artiq_coreconfig delete -k my_key
$ artiq_coreconfig delete my_key
You can remove several keys at once::
$ artiq_coreconfig delete key1 key2
To erase the entire flash storage area::
@ -140,7 +144,7 @@ it::
$ artiq_coreconfig write -s my_key some_value
$ artiq_coreconfig write -s my_key some_other_value
$ artiq_coreconfig read -k my_key
$ artiq_coreconfig read my_key
b'some_other_value'
.. argparse::