From fd17852648043c654e6624ed9d2f8dfb67bb7e7d Mon Sep 17 00:00:00 2001 From: pnda <43609023+ThePNDA@users.noreply.github.com> Date: Sat, 27 Mar 2021 19:31:06 +0100 Subject: [PATCH] Add option to cancel package editing --- bin/commands/manage_command.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/commands/manage_command.dart b/bin/commands/manage_command.dart index 5c2281b..2fae162 100644 --- a/bin/commands/manage_command.dart +++ b/bin/commands/manage_command.dart @@ -102,16 +102,19 @@ class ManageCommand extends Command { /// Allow the user to change any values of the [package] object. var exit = false; while(!exit) { - const fields = ['name', 'description', 'url', 'tags', 'Done, save']; + const fields = ['name', 'description', 'url', 'tags', 'Done, save', 'Cancel']; final chosenFieldToEdit = Select( prompt: 'Which value do you want to edit?', options: fields, ).interact(); - /// If they selected 'Done, save', we'll exit this loop and send the new data to the API. - if (chosenFieldToEdit == fields.length - 1) { + if (chosenFieldToEdit == fields.indexOf('Done, save')) { + /// If they selected 'Done, save', we'll exit this loop and send the new data to the API. exit = true; break; + } else if (chosenFieldToEdit == fields.indexOf('Cancel')) { + /// If they selected 'Cancel', we'll simply return this function and discard any data. + return; } switch (fields[chosenFieldToEdit]) {