apk: add -i/--interactive option (fixes #60)

and use that to figure if questions are allowed or not instead
of the verbosity level.
cute-signatures
Timo Teras 2009-07-24 14:18:07 +03:00
parent 195859b3fd
commit 1c92602172
3 changed files with 8 additions and 1 deletions

View File

@ -37,6 +37,7 @@ static struct apk_option generic_options[] = {
required_argument, "REPO" },
{ 'q', "quiet", "Print less information" },
{ 'v', "verbose", "Print more information" },
{ 'i', "interactive", "Ask confirmation for certain operations" },
{ 'V', "version", "Print program version and exit" },
{ 'f', "force", "Do what was asked even if it looks dangerous" },
{ 'U', "update-cache", "Update the repository cache" },
@ -348,6 +349,9 @@ int main(int argc, char **argv)
case 'f':
apk_flags |= APK_FORCE;
break;
case 'i':
apk_flags |= APK_INTERACTIVE;
break;
case 'U':
apk_flags |= APK_UPDATE_CACHE;
break;

View File

@ -61,6 +61,7 @@ extern unsigned int apk_flags;
#define APK_UPDATE_CACHE 0x0080
#define APK_ALLOW_UNTRUSTED 0x0100
#define APK_PURGE 0x0200
#define APK_INTERACTIVE 0x0400
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)

View File

@ -667,7 +667,7 @@ int apk_state_commit(struct apk_state *state,
}
size_diff /= 1024;
if (apk_verbosity > 1) {
if (apk_verbosity > 1 || (apk_flags & APK_INTERACTIVE)) {
r = dump_packages(state, cmp_remove,
"The following packages will be REMOVED");
r += dump_packages(state, cmp_downgrade,
@ -681,6 +681,8 @@ int apk_state_commit(struct apk_state *state,
(size_diff < 0) ?
"disk space will be freed" :
"additional disk space will be used");
}
if (apk_flags & APK_INTERACTIVE) {
fprintf(stderr, "Do you want to continue [Y/n]? ");
fflush(stderr);
r = fgetc(stdin);