-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPypm.c
More file actions
75 lines (67 loc) · 2.8 KB
/
Pypm.c
File metadata and controls
75 lines (67 loc) · 2.8 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
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
/* pypm.c – front-door for PyPM 0.3.x
*
* SPDX-License-Identifier: MIT
*
* Build: see README or top-level Makefile
* Notes:
* • Only top-level dispatch lives here.
* • Heavy lifting lives in module source files.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include "pypm.h" /* shared interface */
/* ---------------------------------------------------------------------------
* Forward declarations (implemented in their respective modules)
* ------------------------------------------------------------------------- */
int cmd_doctor(int, char **);
int cmd_sandbox(int, char **);
int cmd_plugin (int, char **);
int cmd_pypylock(int, char **);
int cmd_version(int, char **);
int cmd_getreqs(int, char **);
int cmd_setup (int, char **);
int cmd_lock (int, char **); /* lock diff / sync */
/* ---------------------------------------------------------------------------
* Usage helper
* ------------------------------------------------------------------------- */
static void usage(void)
{
puts("pypm " PYP_VERSION
"\nUSAGE: pypm <command> [options]\n"
"\nCore commands:\n"
" doctor Diagnose build environment\n"
" sandbox [-d DIR] Spawn isolated shell\n"
" plugin <subcmd> ... Manage or run plugins\n"
" pypylock [-o FILE] Produce hermetic archive\n"
" lock <subcmd> ... Lockfile operations (diff, sync)\n"
" getreqs Export requirements.txt from venv\n"
" setup [--python X] Local dev install from metadata\n"
" version Print PyPM version\n"
" help Show this help\n");
}
/* ---------------------------------------------------------------------------
* main()
* ------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
if (argc < 2) { usage(); return 1; }
const char *cmd = argv[1];
/* Fast path for most-used commands in alphabetical order */
if (!strcmp(cmd, "doctor")) return cmd_doctor(argc-1, argv+1);
if (!strcmp(cmd, "getreqs")) return cmd_getreqs(argc-1, argv+1);
if (!strcmp(cmd, "lock")) return cmd_lock (argc-1, argv+1);
if (!strcmp(cmd, "plugin")) return cmd_plugin(argc-1, argv+1);
if (!strcmp(cmd, "pypylock")) return cmd_pypylock(argc-1, argv+1);
if (!strcmp(cmd, "sandbox")) return cmd_sandbox(argc-1, argv+1);
if (!strcmp(cmd, "setup")) return cmd_setup (argc-1, argv+1);
if (!strcmp(cmd, "version")) return cmd_version(argc-1, argv+1);
/* Help aliases */
if (!strcmp(cmd, "help") || !strcmp(cmd, "-h") || !strcmp(cmd, "--help")) {
usage();
return 0;
}
fprintf(stderr, "pypm: unknown command \"%s\"\n", cmd);
usage();
return 1;
}