1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2023 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
23 #include <pakfire/root.h>
28 #include "transaction.h"
30 static const char* args_doc
= "remove [OPTIONS...] PACKAGES...";
32 static const char* doc
= "Remove packages";
34 #define MAX_PACKAGES 128
36 struct cli_local_args
{
40 char* packages
[MAX_PACKAGES
];
41 unsigned int num_packages
;
45 OPT_KEEP_DEPENDENCIES
= 1,
48 static struct argp_option options
[] = {
49 { "keep-dependencies", OPT_KEEP_DEPENDENCIES
, NULL
, 0, "Keep previously installed dependencies", 0 },
53 static error_t
parse(int key
, char* arg
, struct argp_state
* state
, void* data
) {
54 struct cli_local_args
* args
= data
;
57 case OPT_KEEP_DEPENDENCIES
:
58 args
->job_flags
|= PAKFIRE_JOB_KEEP_DEPS
;
62 if (args
->num_packages
>= MAX_PACKAGES
)
65 args
->packages
[args
->num_packages
++] = arg
;
69 return ARGP_ERR_UNKNOWN
;
75 static int __cli_remove(pakfire_transaction
* transaction
, int argc
, char* argv
[], void* data
) {
76 struct cli_local_args
* args
= data
;
79 for (unsigned int i
= 0; i
< args
->num_packages
; i
++) {
80 r
= pakfire_transaction_request(transaction
,
81 PAKFIRE_JOB_ERASE
, args
->packages
[i
], args
->job_flags
);
83 fprintf(stderr
, "Could not find '%s': %m\n", argv
[i
]);
91 int cli_remove(void* data
, int argc
, char* argv
[]) {
92 struct cli_global_args
* global_args
= data
;
93 struct cli_local_args local_args
= {};
94 pakfire_root
* root
= NULL
;
97 // Parse the command line
98 r
= cli_parse(options
, NULL
, args_doc
, doc
, parse
, 0, argc
, argv
, &local_args
);
103 r
= cli_setup_root(&root
, global_args
);
107 r
= cli_transaction(global_args
->ctx
, root
, argc
, argv
, 0, __cli_remove
, &local_args
);
111 pakfire_root_unref(root
);