diff options
author | Xavier Chantry <shiningxc@gmail.com> | 2009-08-31 20:17:05 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2009-09-08 22:02:08 -0500 |
commit | 90e3e026d1236ad89c142b427d7eeb842bbb7ff4 (patch) | |
tree | 2afa66bf7e7ce4358318710abcf606c952c4af8b | |
parent | 12b55958d8884bd6828e0888ab9dc10d38bcd72f (diff) | |
download | pacman-90e3e026d1236ad89c142b427d7eeb842bbb7ff4.tar.xz |
Re-add the non-user friendly --ask option
This re-implements the --ask option which was removed in commit
1ff8e7f364a9f640ada7526384646d510ac29967.
This option does not have to be exposed to the user (help,doc,etc), but is
very very useful for pactest if we want to have more coverage there.
This was rewritten in a smarter way, without code duplication. And with a
different behavior : this option is now only used to inverse default
behavior to questions.
We still use bit operations based on the following struct :
/* Transaction Conversations (ie, questions) */
typedef enum _pmtransconv_t {
PM_TRANS_CONV_INSTALL_IGNOREPKG = 0x01,
PM_TRANS_CONV_REPLACE_PKG = 0x02,
PM_TRANS_CONV_CONFLICT_PKG = 0x04,
PM_TRANS_CONV_CORRUPTED_PKG = 0x08,
PM_TRANS_CONV_LOCAL_NEWER = 0x10,
PM_TRANS_CONV_REMOVE_PKGS = 0x20,
} pmtransconv_t;
for each conv matched, the default answer is inversed.
--ask 0 : all default answers are preserved
--ask 4 : only conflict question is inversed
--ask 63 : all questions are inversed (63 == 1+2+4+8+16+32)
Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | src/pacman/callback.c | 6 | ||||
-rw-r--r-- | src/pacman/conf.h | 2 | ||||
-rw-r--r-- | src/pacman/pacman.c | 7 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 9376ab6c..05d7ed01 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -304,6 +304,12 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, (char *)data1); break; } + if(config->noask) { + if(config->ask & event) { + /* inverse the default answer */ + *response = !*response; + } + } } /* callback to handle display of transaction progress */ diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2d3de987..3c588a7e 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -63,6 +63,8 @@ typedef struct __config_t { unsigned short group; pmtransflag_t flags; + unsigned short noask; + unsigned int ask; /* conf file options */ unsigned short chomp; /* I Love Candy! */ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 454505a0..64598b09 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -384,6 +384,7 @@ static int parseargs(int argc, char *argv[]) {"debug", optional_argument, 0, 1003}, {"noprogressbar", no_argument, 0, 1004}, {"noscriptlet", no_argument, 0, 1005}, + {"ask", required_argument, 0, 1006}, {"cachedir", required_argument, 0, 1007}, {"asdeps", no_argument, 0, 1008}, {"logfile", required_argument, 0, 1009}, @@ -441,6 +442,7 @@ static int parseargs(int argc, char *argv[]) break; case 1004: config->noprogressbar = 1; break; case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break; + case 1006: config->noask = 1; config->ask = atoi(optarg); break; case 1007: if(alpm_option_add_cachedir(optarg) != 0) { pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), @@ -1065,6 +1067,11 @@ int main(int argc, char *argv[]) alpm_option_set_totaldlcb(cb_dl_total); } + /* noask is meant to be non-interactive */ + if(config->noask) { + config->noconfirm = 1; + } + #if defined(HAVE_GETEUID) && !defined(CYGWIN) /* check if we have sufficient permission for the requested operation */ if(myuid > 0 && needs_root()) { |