Skip to content

Commit

Permalink
echo: add -o option (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidaty authored Oct 11, 2024
1 parent 2eb29ca commit d074e7a
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit d074e7a

Please sign in to comment.