From: Michael Tremer Date: Fri, 29 Sep 2023 09:11:47 +0000 (+0000) Subject: cli: pakfire-builder: Implement dist command X-Git-Tag: 0.9.30~1610 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f9bc3d2143cc7f7c491aabc14f9ec405a00ba4b;p=pakfire.git cli: pakfire-builder: Implement dist command Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index e94fd4fe0..2e0356494 100644 --- a/Makefile.am +++ b/Makefile.am @@ -435,6 +435,8 @@ libcli_la_SOURCES = \ src/cli/lib/clean.h \ src/cli/lib/command.c \ src/cli/lib/command.h \ + src/cli/lib/dist.c \ + src/cli/lib/dist.h \ src/cli/lib/dump.c \ src/cli/lib/dump.h \ src/cli/lib/info.c \ diff --git a/src/cli/lib/dist.c b/src/cli/lib/dist.c new file mode 100644 index 000000000..876cc64ca --- /dev/null +++ b/src/cli/lib/dist.c @@ -0,0 +1,100 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include +#include +#include + +#include "command.h" +#include "dist.h" + +#include +#include + +#define MAX_MAKEFILES 128 + +struct config { + const char* resultdir; +}; + +static void help(void) { + printf( + "%s [OPTIONS...] dist MAKEFILES...\n\n" + "Options:\n" + " -h --help Show help\n", + program_invocation_short_name + ); + + exit(0); +} + +static int parse_argv(int argc, char* argv[]) { + static const struct option options[] = { + { "help", no_argument, NULL, 'h' }, + { NULL }, + }; + int c; + + for (;;) { + c = getopt_long(argc, argv, "h", options, NULL); + if (c < 0) + break; + + switch (c) { + case 'h': + help(); + + case '?': + return -EINVAL; + + default: + break; + } + } + + return 0; +} + +int cli_dist(struct pakfire* pakfire, int argc, char* argv[]) { + struct config config = { + .resultdir = NULL, + }; + char cwd[PATH_MAX]; + int r; + + // Parse commandline + r = parse_argv(argc, argv); + if (r) + return r; + + // Set result directory to PWD + if (!config.resultdir) + config.resultdir = getcwd(cwd, sizeof(cwd)); + + // Run for all arguments + for (int i = optind; i < argc; i++) { + r = pakfire_dist(pakfire, argv[i], config.resultdir, NULL); + if (r) + break; + } + + return r; +} diff --git a/src/cli/lib/dist.h b/src/cli/lib/dist.h new file mode 100644 index 000000000..97f5583cb --- /dev/null +++ b/src/cli/lib/dist.h @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CLI_DIST_H +#define PAKFIRE_CLI_DIST_H + +#include + +int cli_dist(struct pakfire* pakfire, int argc, char* argv[]); + +#endif /* PAKFIRE_CLI_DIST_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index d7a85901b..fa57051dd 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -30,6 +30,7 @@ #include "lib/clean.h" #include "lib/command.h" +#include "lib/dist.h" #include "lib/info.h" #include "lib/provides.h" #include "lib/repolist.h" @@ -56,6 +57,7 @@ struct config { static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) { static const struct command commands[] = { { "clean", 0, cli_clean }, + { "dist", 0, cli_dist }, { "info", 0, cli_info }, { "provides", 0, cli_provides }, { "repolist", 0, cli_repolist },