Skip to content

Commit de165a4

Browse files
committed
Integrate Registry API into PRM CLI
1 parent 804b5b8 commit de165a4

1 file changed

Lines changed: 81 additions & 11 deletions

File tree

src/prm/commands/cmd_core.c

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,31 +229,101 @@ void prm_audit() {
229229

230230
// --- Registry ---
231231

232+
#define REGISTRY_URL "https://proxpl.in"
233+
#define CONFIG_FILE ".prmconfig"
234+
235+
static void save_token(const char* token) {
236+
FILE* f = fopen(CONFIG_FILE, "w");
237+
if (f) {
238+
fprintf(f, "token: %s\n", token);
239+
fclose(f);
240+
}
241+
}
242+
243+
static char* load_token() {
244+
FILE* f = fopen(CONFIG_FILE, "r");
245+
if (!f) return NULL;
246+
char line[256];
247+
static char token[128];
248+
while (fgets(line, sizeof(line), f)) {
249+
if (sscanf(line, "token: %127s", token) == 1) {
250+
fclose(f);
251+
return token;
252+
}
253+
}
254+
fclose(f);
255+
return NULL;
256+
}
257+
232258
void prm_publish() {
233-
printf("Publishing package to registry...\n");
234-
printf("Error: Authentication required. Run 'prm login' first.\n");
259+
Manifest manifest;
260+
if (!prm_load_manifest(&manifest)) {
261+
printf("Error: No project.pxcf found in current directory.\n");
262+
return;
263+
}
264+
265+
char* token = load_token();
266+
if (!token) {
267+
printf("Error: Not logged in. Run 'prm login' first.\n");
268+
return;
269+
}
270+
271+
printf("Publishing %s@%s to registry...\n", manifest.name, manifest.version);
272+
273+
// Construct curl command
274+
// Using simple JSON payload
275+
char cmd[2048];
276+
snprintf(cmd, sizeof(cmd),
277+
"curl -X POST %s/api/registry/publish "
278+
"-H \"Content-Type: application/json\" "
279+
"-H \"Authorization: Bearer %s\" "
280+
"-d \"{\\\"name\\\":\\\"%s\\\",\\\"version\\\":\\\"%s\\\",\\\"entryPoint\\\":\\\"%s\\\"}\"",
281+
REGISTRY_URL, token, manifest.name, manifest.version, manifest.entryPoint
282+
);
283+
284+
int result = system(cmd);
285+
if (result == 0) {
286+
printf("\nSuccessfully published %s@%s\n", manifest.name, manifest.version);
287+
} else {
288+
printf("\nFailed to publish package. Check your connection or token.\n");
289+
}
235290
}
236291

237292
void prm_login() {
238-
printf("Logging in to registry.proxpl.org...\n");
239-
printf("Username: ProgrammerKR\n");
240-
printf("Password: [hidden]\n");
241-
printf("Logged in successfully.\n");
293+
char token[128];
294+
printf("Logging in to %s\n", REGISTRY_URL);
295+
printf("Please enter your API token (from your dashboard): ");
296+
if (scanf("%127s", token) == 1) {
297+
save_token(token);
298+
printf("Logged in successfully.\n");
299+
}
242300
}
243301

244302
void prm_logout() {
303+
remove(CONFIG_FILE);
245304
printf("Logged out.\n");
246305
}
247306

248307
void prm_search(const char* query) {
249-
printf("Searching for '%s'...\n", query);
250-
printf("Found 0 packages.\n");
308+
if (!query) return;
309+
printf("Searching %s for '%s'...\n", REGISTRY_URL, query);
310+
311+
char cmd[1024];
312+
snprintf(cmd, sizeof(cmd), "curl -s \"%s/api/registry/search?q=%s\"", REGISTRY_URL, query);
313+
314+
system(cmd);
315+
printf("\n");
251316
}
252317

253318
void prm_info(const char* packageName) {
254-
printf("Package: %s\n", packageName);
255-
printf("Version: 1.0.0\n");
256-
printf("Description: A cool ProXPL package.\n");
319+
if (!packageName) return;
320+
printf("Package Info: %s\n", packageName);
321+
322+
char cmd[1024];
323+
snprintf(cmd, sizeof(cmd), "curl -s \"%s/api/registry/package/%s\"", REGISTRY_URL, packageName);
324+
325+
system(cmd);
326+
printf("\n");
257327
}
258328

259329
// --- Misc ---

0 commit comments

Comments
 (0)