summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob Gruber <jakob.gruber@gmail.com>2010-10-08 22:59:30 +0200
committerDan McGee <dan@archlinux.org>2010-10-11 20:57:36 -0500
commit5fcb005ebd270c1ecff3403695680145253961a2 (patch)
treec48eba823a4ab1ac7b77d5c9268be0c0d1371d64 /src
parent827258f32ee898ed5422bc9219d9a42bd9bd2360 (diff)
downloadpacman-5fcb005ebd270c1ecff3403695680145253961a2.tar.xz
CLI args: stricter/better parsing
In the following, the letters SRUDQ refer to the corresponding pacman operations. Most of the work in this commit is about removing as many options as possible from the global section and moving them to where they actually belong. Additionally, --ignore{,group} are added to U and --dbonly is added to S. --dbonly added to S --asdeps moved to S/U/D --asexplicit moved to S/U/D --print-format moved to S/U/R --noprogressbar moved to S/U/R --noscriptlet moved to S/U/R --ignorepkg added to U --ignoregrp added to U -d moved to S/U/R (--nodeps) and Q (--deps) -p moved to S/U/R (--print) and Q (--file) -f moved to S/U Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index f725071a..15abecc5 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -352,6 +352,21 @@ static void setlibpaths(void)
#define check_optarg() if(!optarg) { return(1); }
+typedef void (*fn_add) (const char *s);
+
+static int parsearg_util_addlist(fn_add fn)
+{
+ alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */
+
+ check_optarg();
+ list = strsplit(optarg, ',');
+ for(item = list; item; item = alpm_list_next(item)) {
+ fn((char *)alpm_list_getdata(item));
+ }
+ FREELIST(list);
+ return(0);
+}
+
/** Helper function for parsing operation from command-line arguments.
* @param opt Keycode returned by getopt_long
* @param dryrun If nonzero, application state is NOT changed
@@ -398,8 +413,6 @@ static int parsearg_op(int opt, int dryrun)
static int parsearg_global(int opt)
{
switch(opt) {
- case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
- case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
case OP_ARCH: check_optarg(); setarch(optarg); break;
case OP_ASK:
check_optarg();
@@ -449,22 +462,10 @@ static int parsearg_global(int opt)
config->logfile = strndup(optarg, PATH_MAX);
break;
case OP_NOCONFIRM: config->noconfirm = 1; break;
- case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
- case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
- case OP_PRINTFORMAT:
- check_optarg();
- config->print_format = strdup(optarg);
- break;
case 'b':
check_optarg();
config->dbpath = strdup(optarg);
break;
- case 'd':
- config->op_q_deps = 1;
- config->flags |= PM_TRANS_FLAG_NODEPS;
- break;
- case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
- case 'p': config->op_q_isfile = 1; config->print = 1; break;
case 'r': check_optarg(); config->rootdir = strdup(optarg); break;
case 'v': (config->verbose)++; break;
default: return(1);
@@ -475,6 +476,8 @@ static int parsearg_global(int opt)
static int parsearg_database(int opt)
{
switch(opt) {
+ case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
+ case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
default: return(1);
}
return(0);
@@ -484,6 +487,7 @@ static int parsearg_query(int opt)
{
switch(opt) {
case 'c': config->op_q_changelog = 1; break;
+ case 'd': config->op_q_deps = 1; break;
case 'e': config->op_q_explicit = 1; break;
case 'g': (config->group)++; break;
case 'i': (config->op_q_info)++; break;
@@ -491,6 +495,7 @@ static int parsearg_query(int opt)
case 'l': config->op_q_list = 1; break;
case 'm': config->op_q_foreign = 1; break;
case 'o': config->op_q_owns = 1; break;
+ case 'p': config->op_q_isfile = 1; break;
case 'q': config->quiet = 1; break;
case 's': config->op_q_search = 1; break;
case 't': config->op_q_unrequired = 1; break;
@@ -503,9 +508,14 @@ static int parsearg_query(int opt)
static int parsearg_remove(int opt)
{
switch(opt) {
+ case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
+ case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
+ case OP_PRINTFORMAT: check_optarg(); config->print_format = strdup(optarg); break;
case 'c': config->flags |= PM_TRANS_FLAG_CASCADE; break;
+ case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
+ case 'p': config->print = 1; break;
case 's':
if(config->flags & PM_TRANS_FLAG_RECURSE) {
config->flags |= PM_TRANS_FLAG_RECURSEALL;
@@ -521,30 +531,23 @@ static int parsearg_remove(int opt)
static int parsearg_sync(int opt)
{
- alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */
-
switch(opt) {
- case OP_IGNORE:
- check_optarg();
- list = strsplit(optarg, ',');
- for(item = list; item; item = alpm_list_next(item)) {
- alpm_option_add_ignorepkg((char *)alpm_list_getdata(item));
- }
- FREELIST(list);
- break;
- case OP_IGNOREGROUP:
- check_optarg();
- list = strsplit(optarg, ',');
- for(item = list; item; item = alpm_list_next(item)) {
- alpm_option_add_ignoregrp((char *)alpm_list_getdata(item));
- }
- FREELIST(list);
- break;
+ case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
+ case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
+ case OP_IGNORE: parsearg_util_addlist(alpm_option_add_ignorepkg); break;
+ case OP_IGNOREGROUP: parsearg_util_addlist(alpm_option_add_ignoregrp); break;
case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
+ case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
+ case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
+ case OP_PRINTFORMAT: check_optarg(); config->print_format = strdup(optarg); break;
case 'c': (config->op_s_clean)++; break;
+ case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
+ case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
case 'g': (config->group)++; break;
case 'i': (config->op_s_info)++; break;
case 'l': config->op_q_list = 1; break;
+ case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
+ case 'p': config->print = 1; break;
case 'q': config->quiet = 1; break;
case 's': config->op_s_search = 1; break;
case 'u': (config->op_s_upgrade)++; break;
@@ -570,7 +573,17 @@ static int parsearg_deptest(int opt)
static int parsearg_upgrade(int opt)
{
switch(opt) {
+ case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
+ case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
+ case OP_IGNORE: parsearg_util_addlist(alpm_option_add_ignorepkg); break;
+ case OP_IGNOREGROUP: parsearg_util_addlist(alpm_option_add_ignoregrp); break;
+ case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
+ case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
+ case OP_PRINTFORMAT: check_optarg(); config->print_format = strdup(optarg); break;
+ case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
+ case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
+ case 'p': config->print = 1; break;
default: return(1);
}
return(0);