annotate scictl.c @ 12:be3ec0e6bb8f

scid: remove status from jobresult
author David Demelier <markand@malikania.fr>
date Tue, 29 Jun 2021 21:24:16 +0200
parents 3ef8128e244f
children 67348ec46425
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 #include <err.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 #include <stdio.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 #include <stdlib.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
4 #include <string.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 #include <stdnoreturn.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 #include <unistd.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
7
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 #include "config.h"
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 #include "req.h"
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
10 #include "types.h"
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 #include "util.h"
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
12
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 noreturn static void
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 usage(void)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 fprintf(stderr, "usage: %s [-s sock] command [args...]\n", getprogname());
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 exit(1);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
18 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
19
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
20 noreturn static void
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
21 help(void)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
23 fprintf(stderr, "usage: %s job-add project tag\n", getprogname());
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
24 fprintf(stderr, " %s job-todo worker\n", getprogname());
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
25 fprintf(stderr, " %s jobresult-add id worker exitcode console\n", getprogname());
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
26 fprintf(stderr, " %s project-add name desc url script\n", getprogname());
9
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
27 fprintf(stderr, " %s project-update name key value\n", getprogname());
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
28 fprintf(stderr, " %s project-list\n", getprogname());
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
29 fprintf(stderr, " %s worker-add name desc\n", getprogname());
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
30 fprintf(stderr, " %s worker-list\n", getprogname());
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
31 exit(0);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
32 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
33
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
34 static char *
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
35 readfile(const char *path)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
36 {
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
37 FILE *fp, *str;
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
38 char buf[BUFSIZ], *console;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
39 size_t nr;
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
40
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
41 if (strcmp(path, "-") == 0)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
42 fp = stdin;
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
43 else if (!(fp = fopen(path, "r")))
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
44 err(1, "%s", path);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
45
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
46 console = util_calloc(1, SCI_MSG_MAX);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
47
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
48 if (!(str = fmemopen(console, SCI_MSG_MAX, "w")))
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
49 err(1, "fmemopen");
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
50
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
51 while ((nr = fread(buf, 1, sizeof (buf), fp)) > 0)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
52 fwrite(buf, 1, nr, str);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
53
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
54 if ((ferror(fp) && !feof(fp)) || (ferror(str) && !feof(str))) {
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
55 free(console);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
56 console = NULL;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
57 }
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
58
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
59 fclose(str);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
60 fclose(fp);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
61
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
62 return console;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
63 }
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
64
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
65 static struct req
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
66 cmd_job_add(int argc, char **argv)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
67 {
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
68 struct job job = {0};
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
69 struct project project = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
70 struct req rp, rj;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
71
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
72 if (argc < 2)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
73 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
74
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
75 if ((rp = req_project_find(&project, argv[0])).status)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
76 return rp;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
77
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
78 job.project_id = project.id;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
79 job.tag = argv[1];
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
80
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
81 rj = req_job_add(&job);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
82 req_finish(&rp);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
83
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
84 return rj;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
85 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
86
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
87 static struct req
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
88 cmd_job_todo(int argc, char **argv)
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
89 {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
90 struct project projects[SCI_PROJECT_MAX] = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
91 struct job jobs[SCI_JOB_LIST_MAX] = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
92 struct req rp, rj;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
93 size_t projectsz = UTIL_SIZE(projects), jobsz = UTIL_SIZE(jobs);
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
94
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
95 if (argc < 1)
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
96 usage();
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
97
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
98 /* First retrieve projects for a better listing. */
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
99 if ((rp = req_project_list(projects, &projectsz)).status)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
100 return rp;
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
101
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
102 if ((rj = req_job_todo(jobs, &jobsz, argv[0])).status) {
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
103 req_finish(&rp);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
104 return rj;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
105 }
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
106
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
107 for (size_t i = 0; i < jobsz; ++i) {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
108 const char *project = "unknown";
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
109
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
110 /* Find project if exists (it should). */
12
be3ec0e6bb8f scid: remove status from jobresult
David Demelier <markand@malikania.fr>
parents: 9
diff changeset
111 for (size_t p = 0; p < projectsz; ++p) {
be3ec0e6bb8f scid: remove status from jobresult
David Demelier <markand@malikania.fr>
parents: 9
diff changeset
112 if (projects[p].id == jobs[i].project_id) {
be3ec0e6bb8f scid: remove status from jobresult
David Demelier <markand@malikania.fr>
parents: 9
diff changeset
113 project = projects[p].name;
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
114 break;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
115 }
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
116 }
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
117
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
118 printf("%-16s%d\n", "id:", jobs[i].id);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
119 printf("%-16s%s\n", "tag:", jobs[i].tag);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
120 printf("%-16s%s\n", "project:", project);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
121
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
122 if (i + 1 < jobsz)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
123 printf("\n");
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
124 }
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
125
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
126 req_finish(&rp);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
127
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
128 return rj;
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
129 }
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
130
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
131 static struct req
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
132 cmd_jobresult_add(int argc, char **argv)
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
133 {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
134 struct jobresult res = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
135 struct worker wk = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
136 struct req rw, rj;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
137 char *log;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
138
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
139 if (argc < 5)
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
140 usage();
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
141
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
142 /* Find worker id. */
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
143 if ((rw = req_worker_find(&wk, argv[1])).status)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
144 return rw;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
145
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
146 res.job_id = strtoll(argv[0], NULL, 10);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
147 res.exitcode = strtoll(argv[2], NULL, 10);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
148 res.worker_id = wk.id;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
149 res.log = log = readfile(argv[3]);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
150 rj = req_jobresult_add(&res);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
151
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
152 free(log);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
153 req_finish(&rw);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
154
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
155 return rj;
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
156 }
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
157
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
158 static struct req
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
159 cmd_project_add(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
160 {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
161 struct project pc = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
162 struct req res;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
163 char *script;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
164
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
165 if (argc < 4)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
166 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
167
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
168 pc.name = argv[0];
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
169 pc.desc = argv[1];
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
170 pc.url = argv[2];
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
171 pc.script = script = readfile(argv[3]);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
172 res = req_project_add(&pc);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
173
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
174 free(script);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
175
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
176 return res;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
177 }
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
178
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
179 static struct req
9
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
180 cmd_project_update(int argc, char **argv)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
181 {
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
182 struct project pc;
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
183 struct req rget, rsend;
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
184 char *script = NULL;
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
185
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
186 if (argc < 3)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
187 help();
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
188
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
189 if ((rget = req_project_find(&pc, argv[0])).status)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
190 return rget;
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
191
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
192 if (strcmp(argv[1], "name") == 0)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
193 pc.name = argv[2];
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
194 else if (strcmp(argv[1], "desc") == 0)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
195 pc.desc = argv[2];
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
196 else if (strcmp(argv[1], "url") == 0)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
197 pc.url = argv[2];
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
198 else if (strcmp(argv[1], "script") == 0)
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
199 pc.script = script = readfile(argv[2]);
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
200
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
201 rsend = req_project_update(&pc);
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
202
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
203 req_finish(&rget);
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
204 free(script);
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
205
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
206 return rsend;
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
207 }
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
208
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
209 static struct req
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
210 cmd_project_find(int argc, char **argv)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
211 {
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
212 struct project project = {0};
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
213 struct req req;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
214
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
215 if (argc < 1)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
216 usage();
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
217 if ((req = req_project_find(&project, argv[0])).status)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
218 return req;
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
219
4
9c4fea43803c scid: some refactoring in db
David Demelier <markand@malikania.fr>
parents: 3
diff changeset
220 printf("%-16s%d\n", "id:", project.id);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
221 printf("%-16s%s\n", "name:", project.name);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
222 printf("%-16s%s\n", "desc:", project.desc);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
223 printf("%-16s%s\n", "url:", project.url);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
224 printf("\n");
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
225 printf("%s", project.script);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
226
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
227 return req;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
228 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
229
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
230 static struct req
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
231 cmd_project_list(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
232 {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
233 (void)argc;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
234 (void)argv;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
235
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
236 struct project projects[SCI_PROJECT_MAX] = {0};
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
237 struct req req;
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
238 size_t projectsz = UTIL_SIZE(projects);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
239
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
240 if ((req = req_project_list(projects, &projectsz)).status)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
241 return req;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
242
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
243 for (size_t i = 0; i < projectsz; ++i) {
4
9c4fea43803c scid: some refactoring in db
David Demelier <markand@malikania.fr>
parents: 3
diff changeset
244 printf("%-16s%d\n", "id:", projects[i].id);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
245 printf("%-16s%s\n", "name:", projects[i].name);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
246 printf("%-16s%s\n", "desc:", projects[i].desc);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
247 printf("%-16s%s\n", "url:", projects[i].url);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
248
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
249 if (i + 1 < projectsz)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
250 printf("\n");
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
251 }
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
252
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
253 return req;
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
254 }
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
255
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
256 static struct req
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
257 cmd_worker_add(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
258 {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
259 struct worker wk = {0};
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
260
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
261 if (argc < 2)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
262 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
263
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
264 wk.name = argv[0];
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
265 wk.desc = argv[1];
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
266
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
267 return req_worker_add(&wk);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
268 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
269
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
270 static struct req
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
271 cmd_worker_list(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
272 {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
273 (void)argc;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
274 (void)argv;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
275
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
276 struct worker wk[SCI_WORKER_MAX];
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
277 struct req req;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
278 size_t wksz = UTIL_SIZE(wk);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
279
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
280 if ((req = req_worker_list(wk, &wksz)).status)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
281 return req;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
282
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
283 for (size_t i = 0; i < wksz; ++i) {
4
9c4fea43803c scid: some refactoring in db
David Demelier <markand@malikania.fr>
parents: 3
diff changeset
284 printf("%-16s%d\n", "id:", wk[i].id);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
285 printf("%-16s%s\n", "name:", wk[i].name);
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
286 printf("%-16s%s\n", "desc:", wk[i].desc);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
287
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
288 if (i + 1 < wksz)
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
289 printf("\n");
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
290 }
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
291
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
292 return req;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
293 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
294
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
295 static struct {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
296 const char *name;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
297 struct req (*exec)(int, char **);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
298 } commands[] = {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
299 { "job-add", cmd_job_add },
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
300 { "job-todo", cmd_job_todo },
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
301 { "jobresult-add", cmd_jobresult_add },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
302 { "project-add", cmd_project_add },
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
303 { "project-find", cmd_project_find },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
304 { "project-list", cmd_project_list },
9
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
305 { "project-update", cmd_project_update },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
306 { "worker-add", cmd_worker_add },
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
307 { "worker-list", cmd_worker_list },
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
308 { NULL, NULL }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
309 };
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
310
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
311 int
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
312 main(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
313 {
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
314 int ch, cmdfound = 0;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
315
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
316 setprogname("scictl");
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
317
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
318 while ((ch = getopt(argc, argv, "s:")) != -1) {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
319 switch (ch) {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
320 case 's':
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
321 req_set_path(optarg);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
322 break;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
323 default:
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
324 break;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
325 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
326 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
327
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
328 argc -= optind;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
329 argv += optind;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
330
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
331 if (argc <= 0)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
332 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
333 if (strcmp(argv[0], "help") == 0)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
334 help();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
335
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
336 for (size_t i = 0; commands[i].name; ++i) {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
337 struct req res;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
338
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
339 if (strcmp(commands[i].name, argv[0]) == 0) {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
340 res = commands[i].exec(--argc, ++argv);
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
341 cmdfound = 1;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
342
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
343 if (res.status)
9
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
344 warnx("%s", json_string_value(json_object_get(res.msg, "error")));
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
345
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
346 req_finish(&res);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
347 break;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
348 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
349 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
350
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
351 if (!cmdfound)
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
352 errx(1, "abort: command %s not found", argv[0]);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
353 }