Command line flags for query input and output#8786
Conversation
zwass
left a comment
There was a problem hiding this comment.
Generally seems good to me. I think the section I commented on could be simplified. I'd feel better about the whole thing if it used more of the C++ style memory handling like scope_guard but I think much of this was adapted from the original SQLite C and I don't think we need to do that refactor here.
| // Run a single query from --query flag | ||
| rc = runQuery(&data, FLAGS_query.c_str()); | ||
| if (rc != 0) { | ||
| if (output_file != nullptr) { | ||
| fclose(output_file); | ||
| } | ||
| if (data.prettyPrint != nullptr) { | ||
| delete data.prettyPrint; | ||
| } | ||
| return rc; | ||
| } | ||
| } else if (!FLAGS_query_file.empty()) { | ||
| // Read query from file and execute | ||
| std::string query_content; | ||
| auto status = readFile(FLAGS_query_file, query_content); | ||
| if (!status.ok()) { | ||
| fprintf(stderr, | ||
| "Error reading query file '%s': %s\n", | ||
| FLAGS_query_file.c_str(), | ||
| status.getMessage().c_str()); | ||
| if (output_file != nullptr) { | ||
| fclose(output_file); | ||
| } | ||
| return 1; | ||
| } | ||
| rc = runQuery(&data, query_content.c_str()); | ||
| if (rc != 0) { | ||
| if (output_file != nullptr) { | ||
| fclose(output_file); | ||
| } | ||
| if (data.prettyPrint != nullptr) { | ||
| delete data.prettyPrint; | ||
| } | ||
| return rc; |
There was a problem hiding this comment.
Why do these cases return rc when the cases above just set the rc and handle it below? It seems like it spreads out all the places where error handling needs to happen.
There was a problem hiding this comment.
Probably because I told my robot to prefer early returns.
Anyhow, I moved this close (and the pretty print) one to scope guards and I cleaned this up. How's it look?
zwass
left a comment
There was a problem hiding this comment.
LGTM, always happy to see scope guard.
Fixes: #8525
Fixes: #8148
Fixes: #7972
Fixes: #7961
Reading #8525 I think there's merit to it. While in my
gocode, working with stdin and stdout is pretty simple, it does end up feeling uglier in other places. Especially in some exec wrappers where needing to use stdin means invoking a bash shell.While I was here, I took at pass at fixing some of the other stdin related things. Or closing them, because I think we have more options.
So I have Claude Code take a shot at implementing these.