Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

echo: add -o option #222

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <zsv/utils/file.h>
#include <zsv/utils/string.h>
#include <zsv/utils/mem.h>
#include <zsv/utils/arg.h>

enum zsv_echo_overwrite_input_type {
zsv_echo_overwrite_input_type_sqlite3 = 0
Expand Down Expand Up @@ -157,6 +158,7 @@ const char *zsv_echo_usage_msg[] = {
"",
"Options:",
" -b : output with BOM",
" -o <filename> : filename to save output to",
" --trim : trim whitespace",
" --trim-columns : trim blank columns",
" --contiguous : stop output upon scanning an entire row of blank values",
Expand Down Expand Up @@ -265,7 +267,13 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
const char *arg = argv[arg_i];
if (!strcmp(arg, "-b"))
writer_opts.with_bom = 1;
else if (!strcmp(arg, "--contiguous"))
else if (!strcmp(arg, "-o")) {
const char *output_filename = zsv_next_arg(++arg_i, argc, argv, &err);
if (output_filename && !err) {
if (!(writer_opts.stream = fopen(output_filename, "wb")))
perror(output_filename);
}
} else if (!strcmp(arg, "--contiguous"))
data.contiguous = 1;
else if (!strcmp(arg, "--trim-columns"))
data.trim_columns = 1;
Expand Down Expand Up @@ -383,6 +391,7 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
}
opts->stream = data.in;
opts->ctx = &data;

data.csv_writer = zsv_writer_new(&writer_opts);

if (overwrites_csv) {
Expand Down