-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplinter_cli_cmd_use.c
More file actions
44 lines (38 loc) · 1.13 KB
/
splinter_cli_cmd_use.c
File metadata and controls
44 lines (38 loc) · 1.13 KB
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
/**
* Copyright 2025 Tim Post
* License: Apache 2 (MIT available upon request to timthepost@protonmail.com)
*
* @file splinter_cli_cmd_use.c
* @brief Implements the CLI 'use' command.
*/
#include <stdio.h>
#include <string.h>
#include "splinter.h"
#include "splinter_cli.h"
static const char *modname = "use";
void help_cmd_use(unsigned int level) {
(void) level;
printf("%s selects a store to be the current store.\n", modname);
printf("Usage: %s <store_name_or_path>\n", modname);
return;
}
int cmd_use(int argc, char *argv[]) {
if (argc != 2) {
help_cmd_use(1);
return 1;
}
splinter_close();
if (splinter_open(argv[1]) == 0) {
strncpy(thisuser.store, argv[1], sizeof(thisuser.store) -1);
thisuser.store_conn = true;
fprintf(stderr, "%s: now connected to %s\n", modname, thisuser.store);
return 0;
} else {
thisuser.store[0] = '\0';
thisuser.store_conn = false;
fprintf(stderr, "%s: failed to connect to %s\n", modname, argv[1]);
fprintf(stderr, "%s: now disconnected.\n", modname);
return 1;
}
return 0;
}