ref: 09836b88b3d499cc89fa7d22e8ff4bf4b5913cac
dir: /tools/writefile.tool/
static char*
writefile(OToolcall tc, void*)
{
JSON *j, *jf, *jc;
char *file, *content;
char *s;
if (!allowed(tc, 1))
return abortcall(tc);
j = jsonparse(tc.arguments);
jf = jsonbyname(j, "file");
jc = jsonbyname(j, "content");
if (!jf)
goto Errnofile;
if (!jc)
goto Errnocont;
file = jsonstr(jf);
content = jsonstr(jc);
if (!file)
goto Errnofile;
if (!content)
goto Errnocont;
s = writetofile(file, content);
jsonfree(j);
return s;
Errnofile:
jsonfree(j);
return strdup("error: no file");
Errnocont:
jsonfree(j);
return strdup("error: no content");
}
static char *writefiledesc = "overwrite a file. If the file doesn't exist yet, create it.";
static char *writefileargs = ""
%%json
{
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "path to the file"
},
"content": {
"type": "string",
"description": "new content of the file. Existing content will be overwritten."
}
},
"required": [ "file", "content" ]
}
%/json
;