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

updated README, paste usage. add placeholder for paste tests #262

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
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: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ generic-delimited and fixed-width formats, as well as multi-row-span headers
The ZSV CLI can be compiled to virtually any target, including
[WebAssembly](examples/js), and offers features including `select`, `count`,
direct CSV `sql`, `flatten`, `serialize`, `2json` conversion, `2db` sqlite3
conversion, `stack`, `pretty`, `2tsv`, `compare`, `paste` and more.
conversion, `stack`, `pretty`, `2tsv`, `compare`, `paste`, `overwrite` and more.

The ZSV CLI also includes `sheet`, an in-console interactive grid viewer (TO DO:
that can be extended with your custom code for manipulating and) for viewing
Expand Down Expand Up @@ -102,7 +102,8 @@ that implements the expected
- Includes the `zsv` CLI with the following built-in commands:
- `sheet`, an in-console interactive and extendable grid viewer
- `select`, `count`, `sql` query, `desc`ribe, `flatten`, `serialize`, `2json`,
`2db`, `stack`, `pretty`, `2tsv`, `paste`, `compare`, `jq`, `prop`, `rm`
`2db`, `stack`, `pretty`, `2tsv`, `paste`, `compare`, `overwrite`,
`jq`, `prop`, `rm`
- easily [convert between CSV/JSON/sqlite3](docs/csv_json_sqlite.md)
- [compare multiple files](docs/compare.md)
- CLI is easy to extend/customize with a few lines of code via modular plug-in
Expand Down Expand Up @@ -308,15 +309,17 @@ needs.
- `2tsv`: convert to TSV (tab-delimited) format
- `compare`: compare two or more tables of data and output the differences
- `paste` (alpha): horizontally paste two tables together (given inputs X and Y,
output 1...N rows where each row all columns of X in row N, followed by all
columns of Y in row N)
output 1...N rows where each row contains the entire corresponding
row in X followed by the entire corresponding row in Y)
- `serialize` (inverse of flatten): convert an NxM table to a single 3x (Nx(M-1))
table with columns: Row, Column Name, Column Value
- `flatten` (inverse of serialize): flatten a table by combining rows that share
a common value in a specified identifier column
- `stack`: merge CSV files vertically
- `jq`: run a `jq` filter
- `2db`: [convert from JSON to sqlite3 db](docs/csv_json_sqlite.md)
- `overwrite`: overwrite a cell value; changes will be reflected in any zsv
command when the --apply-overwrites option is specified
- `prop`: view or save parsing options associated with a file, such as initial
rows to ignore, or header row span. Saved options are be applied by default
when processing that file.
Expand Down
1 change: 1 addition & 0 deletions TO-DO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# CLI
- add index-related parser options to general command-line options
- change --overwrite-auto to --apply-overwrites

---
## Performance
Expand Down
40 changes: 25 additions & 15 deletions app/paste.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@
#include "zsv_command.h"

static int zsv_paste_usage() {
static const char *usage = "Usage: paste <filename> [<filename> ...]\n"
"\n"
"Options:\n"
" -h,--help : show usage\n";
printf("%s\n", usage);
return 1;
/* clang-format off */
static const char *usage[] = {
"Usage: paste <filename> [<filename> ...]",
"",
"Horizontally paste two tables together: given inputs X, Y, ... of N rows",
"outputs 1...N rows, where each row i contains:",
" row i of input X,",
" followed by row i of input Y,",
" [followed by ...]",
"",
"Options:",
" -h,--help : show usage",
NULL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI
Adding a trailing comma at the end of last element will make clang-format to preserve this format.
No need to turn the formatting off here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, will do that thank you!

};
/* clang-format on */
for (int i = 0; usage[i]; i++)
printf("%s\n", usage[i]);
return 0;
}

struct zsv_paste_input_file {
Expand Down Expand Up @@ -114,10 +126,15 @@ static enum zsv_paste_status zsv_paste_add_input(const char *fname, struct zsv_p

int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
struct zsv_prop_handler *custom_prop_handler, const char *opts_used) {
for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
return zsv_paste_usage();
}

struct zsv_paste_input_file *inputs = NULL;
struct zsv_paste_input_file **next_input = &inputs;
enum zsv_paste_status status = zsv_paste_status_ok;

struct zsv_csv_writer_options writer_opts = zsv_writer_get_default_opts();
zsv_csv_writer writer = zsv_writer_new(&writer_opts);
if (!writer) {
Expand All @@ -127,15 +144,8 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op

for (int i = 1; status == zsv_paste_status_ok && i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) {
zsv_paste_usage();
goto zsv_paste_done;
}

if (0) { // !strcmp(arg, "-x") || !strcmp(arg, "--my-arg")) { ...
} else {
if (!(!strcmp(arg, "-h") || !strcmp(arg, "--help")))
status = zsv_paste_add_input(arg, next_input, &next_input, opts, custom_prop_handler, opts_used);
}
}

if (status == zsv_paste_status_ok) {
Expand Down
5 changes: 4 additions & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TEST_DATA_DIR=${THIS_LIB_BASE}/data
SOURCES=echo count count-pull select select-pull sql 2json serialize flatten pretty desc stack 2db 2tsv jq compare overwrite
TARGETS=$(addprefix ${BUILD_DIR}/bin/zsv_,$(addsuffix ${EXE},${SOURCES}))

TESTS=test-blank-leading-rows $(addprefix test-,${SOURCES}) test-rm test-mv test-2json-help test-sheet
TESTS=test-blank-leading-rows $(addprefix test-,${SOURCES}) test-rm test-mv test-2json-help test-sheet test-paste

ifeq ($(ZSV_BUILD_SHEET),1)
SOURCES+=sheet
Expand Down Expand Up @@ -100,6 +100,9 @@ CLI:

test: ${TESTS}

test-paste:
@echo "TO DO: test paste"

.SECONDARY: worldcitiespop_mil.csv

.PHONY: help test test-% test-stack clean
Expand Down