break;
case '?':
- return -EINVAL;
+ break;
default:
break;
}
// Process all packages
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
// Run the build
r = pakfire_build_exec(build, argv[i]);
if (r) {
#include "command.h"
+// Do not let getopt_long print any error messages
+int opterr = 0;
+
static const struct command* command_find(const struct command* commands, const char* verb) {
for (const struct command* command = commands; command->verb; command++) {
if (strcmp(command->verb, verb) == 0)
int command_dispatch(struct pakfire* pakfire, const struct command* commands, int argc, char* argv[]) {
const struct command* command = NULL;
- if (argc < 2) {
+ if (optind >= argc) {
fprintf(stderr, "Command required\n");
return -EINVAL;
}
- const char* verb = argv[1];
+ const char* verb = argv[optind];
// Find a matching command
command = command_find(commands, verb);
return -EINVAL;
}
- // Consume the verb
- argv++;
- argc--;
-
- // Reset optind
- optind = 1;
+ // Reset optind (to parse everything again)
+ optind = 0;
return command->callback(pakfire, argc, argv);
}
config.resultdir = getcwd(cwd, sizeof(cwd));
// Run for all arguments
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_dist(pakfire, argv[i], config.resultdir, NULL);
if (r)
break;
goto ERROR;
// Perform search
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_search(pakfire, argv[i], PAKFIRE_SEARCH_NAME_ONLY, list);
if (r)
goto ERROR;
int r;
// Add the remaining command line options as packages
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_transaction_request(transaction,
PAKFIRE_JOB_INSTALL, argv[i], config->job_flags);
if (r) {
goto ERROR;
// Perform search
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_whatprovides(pakfire, argv[i], 0, list);
if (r)
goto ERROR;
int r;
// Add the remaining command line options as packages
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_transaction_request(transaction,
PAKFIRE_JOB_ERASE, argv[i], config->job_flags);
if (r) {
goto ERROR;
// Perform search
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_whatrequires(pakfire, argv[i], 0, list);
if (r)
goto ERROR;
goto ERROR;
// Perform search
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_search(pakfire, argv[i], 0, list);
if (r)
goto ERROR;
// Did the user pass any packages?
if (optind < argc) {
// Add the remaining command line options as packages
- for (int i = optind; i < argc; i++) {
+ for (int i = optind + 1; i < argc; i++) {
r = pakfire_transaction_request(transaction, PAKFIRE_JOB_UPDATE, argv[i], 0);
if (r) {
fprintf(stderr, "Could not find '%s': %m\n", argv[i]);
break;
case '?':
- return -EINVAL;
+ break;
default:
break;
goto ERROR;
// Run a command
- r = cli_main(pakfire, argc - optind + 1, argv + optind - 1);
+ r = cli_main(pakfire, argc, argv);
ERROR:
if (pakfire)
break;
case '?':
- return -EINVAL;
+ break;
default:
break;
cli_set_repo_enabled(pakfire, config.disable_repos[i], 0);
// Run a command
- r = cli_main(pakfire, argc - optind + 1, argv + optind - 1);
+ r = cli_main(pakfire, argc, argv);
ERROR:
if (f)