1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*
pkgit - package it!
Copyright (C) 2026 dacctal
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 2 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 <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include "cla_parse.h"
#include "globs.h"
#include "str.h"
// #include "declare.h"
// #include "deps_resolve.h"
#include "help.h"
// #include "name_from_url.h"
// #include "pkg_build.h"
#include "pkg_create.h"
// #include "pkg_search.h"
// #include "pkg_install.h"
// #include "pkg_list.h"
// #include "pkg_remove.h"
// #include "pkgit_globals.h"
// #include "repo_add.h"
// #include "update.h"
#define COMMAND(arg, large, small, code) \
if (strcmp(arg, large) == 0 || strcmp(arg, small) == 0) \
code
#define NOT_ENOUGH_ARGS(arg, next) \
log_error("Not enough arguments! Try: pkgit %s [%s]", (arg), (next))
void cmd_add(char **argv, int i) {
if (argv[i + 1]) {
printf("add repo %s\n", argv[i + 1]);
// repo_add(argv[i + 1], name_from_url(argv[i + 1]));
} else {
NOT_ENOUGH_ARGS(argv[i], "url");
}
}
void cmd_build(int argc, char **argv, int i, package pkg) {
if (argv[i + 1]) {
for (int j = i + 1; j < argc; j++) {
if (argv[j][0] == '-')
continue;
printf("build pkg %s\n", argv[j]);
// pkg = pkg_create(argv[j]);
// pkg_build(pkg);
}
} else {
printf("build pkg .\n");
// pkg = pkg_create(".");
// pkg_build(pkg);
}
}
void cmd_install(int argc, char **argv, int i, package pkg) {
if (argv[i + 1]) {
for (int j = i + 1; j < argc; j++) {
if (argv[j][0] == '-')
continue;
printf("install pkg %s\n", argv[j]);
// pkg = pkg_create(argv[j]);
// pkg_install(pkg);
}
} else {
// NOT_ENOUGH_ARGS(argv[i], "url/pkg");
}
}
void cmd_remove(int argc, char **argv, int i, package pkg) {
if (argv[i + 1]) {
for (int j = i + 1; j < argc; j++) {
if (argv[j][0] == '-')
continue;
printf("remove pkg %s\n", argv[j]);
// pkg = pkg_create(argv[j]);
// pkg_remove(pkg);
}
} else {
// NOT_ENOUGH_ARGS(argv[i], "url/pkg");
}
}
void flags_mod(char **argv, int i) {
for (size_t j = 1; j < strlen(argv[i]); j++) {
switch (argv[i][j]) {
case 'q':
is_verbose = 0;
break;
case 'f':
is_forced = 1;
break;
default:
break;
}
}
}
void flags_cmd(int argc, char **argv, int i, package pkg) {
for (size_t j = 1; j < strlen(argv[i]); j++) {
switch (argv[i][j]) {
case 'a':
cmd_add(argv, i);
break;
case 'b':
cmd_build(argc, argv, i, pkg);
break;
case 'c': /*deps_resolve();*/
printf("deps_resolve\n");
break;
case 'd': /*declare();*/
printf("declare\n");
break;
case 'i':
cmd_install(argc, argv, i, pkg);
break;
case 'r':
cmd_remove(argc, argv, i, pkg);
break;
case 'u': /*update();*/
printf("update\n");
break;
case 'l': /*pkgs_list();*/
printf("list\n");
break;
case 's': /*search(argv[i + 1]);*/
printf("search\n");
break;
case 'v':
printf("%s\n", VERSION);
break;
case 'h':
help();
break;
default:
break;
}
}
}
void flags_parse(int argc, char **argv, package pkg) {
for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-')
continue;
str_slc arg = str_slc_from_cstr(argv[i]);
if (argv[i][1] == '-') {
COMMAND(argv[i], "--quiet", "-q", { is_verbose = 0; });
COMMAND(argv[i], "--force", "-f", { is_forced = 1; });
} else {
flags_mod(argv, i);
flags_cmd(argc, argv, i, pkg);
}
}
}
void cmds_parse(int argc, char **argv, package pkg) {
for (int i = 1; i < argc; i++) {
COMMAND(argv[i], "--add", "a", { cmd_add(argv, i); });
COMMAND(argv[i], "--build", "b", { cmd_build(argc, argv, i, pkg); });
COMMAND(argv[i], "--install", "i",
{ cmd_install(argc, argv, i, pkg); });
COMMAND(argv[i], "--remove", "r", { cmd_remove(argc, argv, i, pkg); });
COMMAND(argv[i], "--update", "u", {/*update();*/});
COMMAND(argv[i], "--declare", "d", {/*declare();*/});
COMMAND(argv[i], "--list", "l", {/*pkgs_list();*/});
COMMAND(argv[i], "--search", "s", {/*search(argv[i + 1]);*/});
COMMAND(argv[i], "--version", "v", { printf("%s\n", VERSION); });
COMMAND(argv[i], "--help", "h", { help(); });
COMMAND(argv[i], "--check", "c", {/*deps_resolve();*/});
}
}
void cla_parse(int argc, char **argv) {
if (!argv[1]) {
help();
return;
}
package pkg = {0};
flags_parse(argc, argv, pkg);
cmds_parse(argc, argv, pkg);
}
|