]>
Commit | Line | Data |
---|---|---|
fa640ef1 MT |
1 | /*############################################################################# |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2023 Pakfire development team # | |
5 | # # | |
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. # | |
10 | # # | |
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. # | |
15 | # # | |
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/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
732e2f37 | 21 | #include <argp.h> |
fa640ef1 MT |
22 | #include <limits.h> |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include <pakfire/pakfire.h> | |
28 | #include <pakfire/string.h> | |
29 | ||
817f7557 | 30 | #include "lib/assert.h" |
060a1182 | 31 | #include "lib/build.h" |
d20b1a83 | 32 | #include "lib/clean.h" |
2c80538d | 33 | #include "lib/command.h" |
5f9bc3d2 | 34 | #include "lib/dist.h" |
0a333c90 | 35 | #include "lib/image.h" |
ecdd76bd | 36 | #include "lib/info.h" |
ee8a3a64 | 37 | #include "lib/pakfire.h" |
32bbeefc | 38 | #include "lib/progressbar.h" |
d20b1a83 | 39 | #include "lib/provides.h" |
3467dd08 | 40 | #include "lib/repo.h" |
418f36f6 | 41 | #include "lib/repolist.h" |
d20b1a83 | 42 | #include "lib/requires.h" |
beee2bda | 43 | #include "lib/shell.h" |
d20b1a83 | 44 | #include "lib/search.h" |
2c80538d MT |
45 | #include "lib/terminal.h" |
46 | #include "lib/version.h" | |
fa640ef1 | 47 | |
732e2f37 | 48 | const char* argp_program_version = PACKAGE_VERSION; |
fa640ef1 | 49 | |
732e2f37 MT |
50 | enum { |
51 | OPT_ARCH = 1, | |
52 | OPT_DEBUG = 2, | |
53 | OPT_DISTRO = 3, | |
fa640ef1 | 54 | |
732e2f37 MT |
55 | OPT_ENABLE_REPO = 4, |
56 | OPT_DISABLE_REPO = 5, | |
57 | }; | |
fa640ef1 | 58 | |
732e2f37 MT |
59 | static struct argp_option options[] = { |
60 | { "arch", OPT_ARCH, "ARCH", 0, "Choose an architecture", 0 }, | |
61 | { "debug", OPT_DEBUG, NULL, 0, "Run in debug mode", 0 }, | |
62 | { "distro", OPT_DISTRO, "DISTRO", 0, "Build for this distribution", 0 }, | |
63 | { NULL }, | |
64 | }; | |
fa640ef1 | 65 | |
732e2f37 | 66 | static const struct command commands[] = { |
8cbf801d MT |
67 | { "build", cli_build, 1, -1, 0 }, |
68 | { "clean", cli_clean, 0, 0, 0 }, | |
69 | { "dist", cli_dist, 1, -1, 0 }, | |
70 | { "image", cli_image, -1, -1, 0 }, | |
71 | { "info", cli_info, 1, -1, 0 }, | |
72 | { "provides", cli_provides, 1, -1, 0 }, | |
1f81cbb2 | 73 | { "requires", cli_requires, 1, -1, 0 }, |
8cbf801d | 74 | { "search", cli_search, 1, -1, 0 }, |
c7720452 | 75 | #if 0 |
732e2f37 MT |
76 | { "repo", 0, cli_repo }, |
77 | { "repolist", 0, cli_repolist }, | |
732e2f37 | 78 | { "shell", 0, cli_shell }, |
ee8a3a64 | 79 | #endif |
732e2f37 MT |
80 | { NULL }, |
81 | }; | |
fa640ef1 | 82 | |
50d2ca50 | 83 | const char* args_doc = |
732e2f37 MT |
84 | "build [OPTIONS...] MAKEFILES...\n" |
85 | "clean\n" | |
86 | "dist MAKEFILES...\n" | |
87 | "image ...\n" | |
88 | "provides PATTERN\n" | |
89 | "repo compose PATH PACKAGES...\n" | |
90 | "repolist\n" | |
91 | "requires PATTERN\n" | |
92 | "shell [OPTIONS...]\n" | |
93 | "search [OPTIONS...] PATTERN"; | |
94 | ||
ee8a3a64 MT |
95 | static error_t parse(int key, char* arg, void* data) { |
96 | struct cli_config* config = data; | |
732e2f37 MT |
97 | |
98 | switch (key) { | |
99 | case OPT_ARCH: | |
100 | // XXX Check if the architecture is supported | |
101 | config->arch = arg; | |
fa640ef1 MT |
102 | break; |
103 | ||
732e2f37 MT |
104 | case OPT_DEBUG: |
105 | config->flags |= PAKFIRE_FLAGS_DEBUG; | |
106 | break; | |
fa640ef1 | 107 | |
732e2f37 MT |
108 | case OPT_DISTRO: |
109 | config->distro = arg; | |
110 | break; | |
fa640ef1 | 111 | |
732e2f37 | 112 | // Enable/Disable Repositories |
fa640ef1 | 113 | |
732e2f37 MT |
114 | case OPT_ENABLE_REPO: |
115 | if (config->num_enable_repos >= MAX_REPOS) | |
116 | return -ENOBUFS; | |
fa640ef1 | 117 | |
732e2f37 MT |
118 | config->enable_repos[config->num_enable_repos++] = arg; |
119 | break; | |
fa640ef1 | 120 | |
732e2f37 MT |
121 | case OPT_DISABLE_REPO: |
122 | if (config->num_disable_repos >= MAX_REPOS) | |
123 | return -ENOBUFS; | |
fa640ef1 | 124 | |
732e2f37 MT |
125 | config->disable_repos[config->num_disable_repos++] = arg; |
126 | break; | |
fa640ef1 | 127 | |
732e2f37 MT |
128 | default: |
129 | return ARGP_ERR_UNKNOWN; | |
fa640ef1 MT |
130 | } |
131 | ||
132 | return 0; | |
133 | } | |
134 | ||
fa640ef1 | 135 | int main(int argc, char* argv[]) { |
ee8a3a64 | 136 | struct cli_config config = { |
fa640ef1 MT |
137 | // XXX hard-coded distro |
138 | .distro = "ipfire3", | |
139 | .arch = NULL, | |
0d54159f | 140 | .flags = PAKFIRE_FLAGS_BUILD, |
fa640ef1 | 141 | }; |
fa640ef1 | 142 | |
ee8a3a64 | 143 | // Parse the command line and run any commands |
50d2ca50 | 144 | return cli_parse(options, commands, args_doc, NULL, parse, argc, argv, &config); |
fa640ef1 | 145 | } |