changeset 61:8be8188d61a5

scictl: resurrect project-update command
author David Demelier <markand@malikania.fr>
date Thu, 18 Aug 2022 10:42:42 +0200
parents 3804a2ab60ec
children eaebcc612a0d
files man/scictl.8 scictl/scictl.c
diffstat 2 files changed, 17 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/man/scictl.8	Thu Aug 18 10:12:54 2022 +0200
+++ b/man/scictl.8	Thu Aug 18 10:42:42 2022 +0200
@@ -116,9 +116,11 @@
 .It Cm project-update
 Update an existing
 .Ar project
-by setting its new fields. The
+by setting its new fields.
+.Pp
+The
 .Ar key
-argument should be one of the argument specified in the
+argument should be one of the argument name is similar to the
 .Cm project-add
 command. For example, to update the description of a project one should
 specify
@@ -128,9 +130,10 @@
 argument and a new description as
 .Ar key .
 .Pp
-Example:
+Examples:
 .Bd -literal -offset indent
 scictl project-update example desc "New description"
+scictl project-update example script "/path/to/script.sh"
 .Ed
 .\" worker-add
 .It Cm worker-add
--- a/scictl/scictl.c	Thu Aug 18 10:12:54 2022 +0200
+++ b/scictl/scictl.c	Thu Aug 18 10:42:42 2022 +0200
@@ -185,33 +185,28 @@
 static void
 cmd_project_update(int argc, char **argv)
 {
-	(void)argc;
-	(void)argv;
-#if 0
-	struct project pc;
 	struct apic req;
+	json_t *obj;
 
 	if (argc < 4)
 		usage();
 
-	if (apic_project_find(&req, &pc, argv[1]) < 0)
+	if (!(obj = apic_project_find(&req, argv[1])))
 		util_die("abort: unable to find project: %s\n", req.error);
 
-	if (strcmp(argv[2], "name") == 0)
-		replace(&pc.name, argv[3]);
-	else if (strcmp(argv[2], "desc") == 0)
-		replace(&pc.desc, argv[3]);
-	else if (strcmp(argv[2], "url") == 0)
-		replace(&pc.url, argv[3]);
+	/* Those fields are treated from argument. */
+	if (strcmp(argv[2], "name") == 0 ||
+	    strcmp(argv[2], "desc") == 0 ||
+	    strcmp(argv[2], "url") == 0)
+		json_object_set_new(obj, argv[2], json_string(argv[3]));
+	/* The script, however, is read from the file. */
 	else if (strcmp(argv[2], "script") == 0)
-		replace(&pc.script, readfile(argv[3]));
+		json_object_set_new(obj, "script", json_string(readfile(argv[3])));
 
-	if (apic_project_save(&req, &pc) < 0)
+	if (apic_project_save(&req, obj) < 0)
 		util_die("abort: unable to save project: %s\n", req.error);
 
-	apic_finish(&req);
-	project_finish(&pc);
-#endif
+	json_decref(obj);
 }
 
 static void