From 5665759667ea27aed198e365bdb12bd9b1e26302 Mon Sep 17 00:00:00 2001 From: Julian Lobbes Date: Fri, 29 Jul 2022 15:13:48 +0200 Subject: [PATCH] update arg parser --- README.org | 8 ++++++++ udib/udib.py | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/README.org b/README.org index 905e6fb..4d569ce 100644 --- a/README.org +++ b/README.org @@ -4,6 +4,14 @@ As the name would suggest, it is a tool which builds a debian installation image which, if used to boot from, installs the *latest stable release* of Debian Linux to the machine without any user interaction required whatsoever. Configuration of the installed system is done by editing preseed files. +** Usage + +Obtaining a preseed example file: + +#+begin_src shell + ./udib.py get preseed-file +#+end_src + ** Prerequisites *** Target machine diff --git a/udib/udib.py b/udib/udib.py index c70df82..0208160 100755 --- a/udib/udib.py +++ b/udib/udib.py @@ -63,29 +63,10 @@ def _get_argument_parser(): """ - # FIXME add a group hierarchy # FIXME capture ISO filesystem name parser = argparse.ArgumentParser() - # create a group of mutually exclusive arguments - mutually_exclusive_group = parser.add_mutually_exclusive_group( - required=True) - mutually_exclusive_group.add_argument( - "--get-image", - help="Download the latest, unmodified Debian image and exit.", - action="store_true") - mutually_exclusive_group.add_argument( - "--get-preseed-file", - help="Download the latest Debian preseed example file and exit.", - action="store_true") - mutually_exclusive_group.add_argument( - "-p", - "--existing-preseed-file", - help="Path to the preseed configuration file to use.", - action="store") - - # add all other arguments parser.add_argument( "-o", "--output-file", @@ -93,10 +74,31 @@ def _get_argument_parser(): type=str, dest="path_to_output_file", action="store") - parser.add_argument( + + subparsers = parser.add_subparsers(required=True) + + parser_get = subparsers.add_parser("get") + parser_get.add_argument( + "WHAT", + type=str, + action="store", + help="What to retrieve (the latest installation image or the latest " \ + "preseed file).", + choices=["image", "preseed-file"]) + + parser_insert = subparsers.add_parser("insert") + parser_insert.add_argument( + "FILES", + nargs="+", + type=str, + help="A list of files to insert into the root of an installation " \ + "image.", + action="store") + parser_insert.add_argument( "-i", "--existing-image", - help="Use an existing debian image file, do not download a new one.", + help="Insert into an existing debian image file, instead of " \ + "downloading a new one.", type=str, dest="path_to_existing_image", action="store") @@ -158,6 +160,8 @@ def main(): # FIXME capture ISO filesystem name iso_filesystem_name = "Debian UDIB" + # FIXME adjust to new parser namespace + parser = _get_argument_parser() args = parser.parse_args()