From dd3437f9a8c28114c5e820409666aae27cd2da20 Mon Sep 17 00:00:00 2001 From: Li Hua Qian Date: Wed, 26 Jun 2024 09:53:29 +0800 Subject: [PATCH] iot2050-firmware-update: Correct parameter definition The '-f', '--force', '-n', '--no-backup', and '-d', '--backup-dir' options are now part of a mutually exclusive group, ensuring that they cannot be used together. Having a default backup dir for -d is not reasonable for force update, and cites an abnormal case where the force update option would not work correctly. However, it's still necessary for normal update. Signed-off-by: Li Hua Qian --- .../files/iot2050-firmware-update.tmpl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/recipes-app/iot2050-firmware-update/files/iot2050-firmware-update.tmpl b/recipes-app/iot2050-firmware-update/files/iot2050-firmware-update.tmpl index 4714a1f5f..ca771c21b 100755 --- a/recipes-app/iot2050-firmware-update/files/iot2050-firmware-update.tmpl +++ b/recipes-app/iot2050-firmware-update/files/iot2050-firmware-update.tmpl @@ -941,13 +941,13 @@ def main(argv): help='Rollback the firmware to the version before the \ upgrade', action='store_true') - parser.add_argument('-n', '--no-backup', + group2 = parser.add_mutually_exclusive_group() + group2.add_argument('-n', '--no-backup', help='Do not generate a firmware backup', action='store_true') - parser.add_argument('-d', '--backup-dir', + group2.add_argument('-d', '--backup-dir', help='Specify the firmware backup directory', - nargs=1, - default=os.getenv('HOME')) + nargs=1) parser.add_argument('-q', '--quiet', help='Update firmware quietly with the original \ firmware auto backed up and rollback in case of \ @@ -956,6 +956,8 @@ def main(argv): try: args = parser.parse_args() + if args.force and (args.no_backup or args.backup_dir): + parser.error("argument -f/--force: not allowed with -n/--no-backup, -d/--backup-dir") except IOError as e: print(e.strerror, file=sys.stderr) return ErrorCode.INVALID_ARG.value @@ -997,6 +999,8 @@ def main(argv): if args.force: updater = ForceUpdate(interactor, args.firmware) else: + if not args.backup_dir: + args.backup_dir = os.getenv('HOME') updater = FirmwareUpdate( tarball, args.backup_dir,