]>
git.ipfire.org Git - pakfire.git/blob - src/cli/pakfire-builder.c
0fa638522fc058df97ebbacf29227d05377bc4b8
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 #############################################################################*/
28 #include <pakfire/arch.h>
29 #include <pakfire/root.h>
30 #include <pakfire/string.h>
32 #include "lib/assert.h"
33 #include "lib/build.h"
34 #include "lib/clean.h"
35 #include "lib/command.h"
36 #include "lib/config.h"
38 #include "lib/image.h"
41 #include "lib/pakfire.h"
42 #include "lib/progressbar.h"
43 #include "lib/provides.h"
45 #include "lib/repolist.h"
46 #include "lib/requires.h"
47 #include "lib/shell.h"
48 #include "lib/search.h"
49 #include "lib/snapshot.h"
50 #include "lib/terminal.h"
51 #include "lib/version.h"
53 const char* argp_program_version
= PACKAGE_FULLVERSION
;
64 static struct argp_option options
[] = {
65 { "arch", OPT_ARCH
, "ARCH", 0, "Choose an architecture", 0 },
66 { "debug", OPT_DEBUG
, NULL
, 0, "Run in debug mode", 0 },
67 { "distro", OPT_DISTRO
, "DISTRO", 0, "Build for this distribution", 0 },
68 { "enable-repo", OPT_ENABLE_REPO
, "REPO", 0, "Enable a repository", 0 },
69 { "disable-repo", OPT_DISABLE_REPO
, "REPO", 0, "Disable a repository", 0 },
73 static const struct command commands
[] = {
74 { "build", cli_build
, 1, -1, 0 },
75 { "clean", cli_clean
, 0, 0, 0 },
76 { "dist", cli_dist
, 1, -1, 0 },
77 { "image", cli_image
, -1, -1, 0 },
78 { "info", cli_info
, 1, -1, 0 },
79 { "lint", cli_lint
, 1, -1, 0 },
80 { "provides", cli_provides
, 1, -1, 0 },
81 { "repo", cli_repo
, -1, -1, 0 },
82 { "repolist", cli_repolist
, 0, 0, 0 },
83 { "requires", cli_requires
, 1, -1, 0 },
84 { "shell", cli_shell
, 0, -1, 0 },
85 { "search", cli_search
, 1, -1, 0 },
86 { "snapshot", cli_snapshot
, 1, -1, 0 },
90 const char* args_doc
=
91 "build [OPTIONS...] MAKEFILES...\n"
97 "repo compose PATH PACKAGES...\n"
100 "shell [OPTIONS...] [COMMAND...]\n"
101 "search [OPTIONS...] PATTERN\n"
102 "snapshot [COMMAND...]";
104 static error_t
parse(int key
, char* arg
, struct argp_state
* state
, void* data
) {
105 struct cli_global_args
* args
= data
;
109 // Check if the architecture is supported
110 if (!pakfire_arch_is_supported_by_host(arg
))
111 argp_failure(state
, EXIT_FAILURE
, 0, "Unsupported architecture: %s", arg
);
117 pakfire_ctx_set_log_level(args
->ctx
, LOG_DEBUG
);
124 // Enable/Disable Repositories
126 case OPT_ENABLE_REPO
:
127 if (args
->num_enable_repos
>= MAX_REPOS
)
130 args
->enable_repos
[args
->num_enable_repos
++] = arg
;
133 case OPT_DISABLE_REPO
:
134 if (args
->num_disable_repos
>= MAX_REPOS
)
137 args
->disable_repos
[args
->num_disable_repos
++] = arg
;
141 return ARGP_ERR_UNKNOWN
;
147 static int cli_confirm(pakfire_ctx
* ctx
, pakfire_root
* root
,
148 void* data
, const char* message
, const char* question
) {
149 // Just print the message
151 printf("%s\n", message
);
156 int main(int argc
, char* argv
[]) {
157 pakfire_ctx
* ctx
= NULL
;
161 r
= pakfire_ctx_create(&ctx
, NULL
);
165 // Write logs to the console
166 pakfire_ctx_set_log_callback(ctx
, pakfire_log_stderr
, NULL
);
168 // Setup confirm callback
169 pakfire_ctx_set_confirm_callback(ctx
, cli_confirm
, NULL
);
171 // Setup progress callback
172 pakfire_ctx_set_progress_callback(ctx
, cli_setup_progressbar
, NULL
);
174 // Set the default cache path
175 r
= pakfire_ctx_set_cache_path(ctx
, "~/.cache/pakfire");
179 struct cli_global_args args
= {
181 .distro
= cli_get_default_distro(ctx
),
183 .flags
= PAKFIRE_ROOT_FLAGS_BUILD
,
186 // Parse the command line and run any commands
187 r
= cli_parse(options
, commands
, args_doc
, NULL
,
188 parse
, CLI_REQUIRE_ROOT
, argc
, argv
, &args
);
192 ctx
= pakfire_ctx_unref(ctx
);
194 fprintf(stderr
, "Context was not freed\n");