summaryrefslogtreecommitdiff
path: root/clients/bokfctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'clients/bokfctl.c')
-rw-r--r--clients/bokfctl.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/clients/bokfctl.c b/clients/bokfctl.c
index b5ecf47..47e42ac 100644
--- a/clients/bokfctl.c
+++ b/clients/bokfctl.c
@@ -19,6 +19,7 @@ static void usage(void)
" --password PW login password (env BOKFD_PASSWORD)\n"
" --token TOKEN API token instead of user/password (env BOKFD_TOKEN)\n"
" --org ID active org for this request\n"
+ " --dry-run validate a mutating command without writing\n"
" --version\n"
"\n"
"examples:\n"
@@ -44,6 +45,7 @@ int main(int argc, char **argv)
int64_t org = 0;
const char *cmd = NULL;
const char *args_json = NULL;
+ int dry_run = 0;
for (int i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -88,6 +90,8 @@ int main(int argc, char **argv)
return 2;
}
org = strtoll(val, NULL, 10);
+ } else if (strcmp(a, "--dry-run") == 0) {
+ dry_run = 1;
} else if (strcmp(a, "--version") == 0) {
printf("bokfctl %s\n", BOKF_VERSION);
return 0;
@@ -160,6 +164,28 @@ int main(int argc, char **argv)
}
}
free(session);
+ if (dry_run) {
+ yyjson_mut_doc *md = yyjson_mut_doc_new(NULL);
+ yyjson_doc *qd = yyjson_read(req, strlen(req), 0);
+ yyjson_mut_val *root = qd ? yyjson_val_mut_copy(md, yyjson_doc_get_root(qd))
+ : NULL;
+ char *out = NULL;
+ if (root && yyjson_mut_is_obj(root)) {
+ yyjson_mut_obj_remove_key(root, "dry_run");
+ yyjson_mut_obj_add_bool(md, root, "dry_run", true);
+ yyjson_mut_doc_set_root(md, root);
+ out = yyjson_mut_write(md, 0, NULL);
+ }
+ yyjson_doc_free(qd);
+ yyjson_mut_doc_free(md);
+ free(req);
+ if (!out) {
+ fprintf(stderr, "bokfctl: request must be a JSON object\n");
+ client_close(&conn);
+ return 2;
+ }
+ req = out;
+ }
if (client_send_line(&conn, req) != 0) {
fprintf(stderr, "bokfctl: send failed: %s\n", client_last_error());
free(req);