Skip to content

Commit

Permalink
iot2050-firmware-update: Correct parameter definition
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
huaqianli committed Jul 12, 2024
1 parent 658ec1c commit dd3437f
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dd3437f

Please sign in to comment.