Skip to content

Commit

Permalink
feat: add a flag to disable piped stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
freedmand committed Nov 30, 2021
1 parent 53d73ed commit cf02384
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -35,6 +35,7 @@ The CLI supports the following flags:
- `--include-filing-id` / `-i`: if this flag is passed, then the generated output will include a column at the beginning of every generated file called `filing_id` that gets passed the filing ID. This can be useful for bulk uploading CSVs into a database
- `--silent` / `-s` : suppress all non-error output messages
- `--warn` / `-w` : show warning messages (e.g. for rows with unexpected numbers of fields or field types that don't match exactly)
- `--no-stdin` / `-x`: disable receiving piped input from other programs (stdin)

The short form of flags can be combined, e.g. `-is` would include filing IDs and suppress output.

Expand Down
13 changes: 13 additions & 0 deletions src/main.c
Expand Up @@ -16,6 +16,8 @@ const char *FLAG_SILENT = "--silent";
const char FLAG_SILENT_SHORT = 's';
const char *FLAG_WARN = "--warn";
const char FLAG_WARN_SHORT = 'w';
const char *FLAG_DISABLE_STDIN = "--no-stdin";
const char FLAG_DISABLE_STDIN_SHORT = 'x';

void printUsage(char *argv[])
{
Expand All @@ -24,6 +26,7 @@ void printUsage(char *argv[])
fprintf(stderr, " %s, -%c: include a filing_id column at the beginning of\n every output CSV\n", FLAG_FILING_ID, FLAG_FILING_ID_SHORT);
fprintf(stderr, " %s, -%c : suppress all stdout messages\n\n", FLAG_SILENT, FLAG_SILENT_SHORT);
fprintf(stderr, " %s, -%c : show warning messages\n\n", FLAG_WARN, FLAG_WARN_SHORT);
fprintf(stderr, " %s, -%c : disable piped input\n\n", FLAG_DISABLE_STDIN, FLAG_DISABLE_STDIN_SHORT);
}

/* Small main program to retrieve from a url using fgets and fread saving the
Expand Down Expand Up @@ -80,6 +83,11 @@ int main(int argc, char *argv[])
warn = 1;
flagOffset++;
}
else if (strcmp(argv[1 + flagOffset], FLAG_DISABLE_STDIN) == 0)
{
piped = 0;
flagOffset++;
}
else
{
// Try to extract flags in short form
Expand All @@ -101,6 +109,11 @@ int main(int argc, char *argv[])
warn = 1;
matched = 1;
}
else if (argv[1 + flagOffset][i] == FLAG_DISABLE_STDIN_SHORT)
{
piped = 0;
matched = 1;
}
else
{
printUsage(argv);
Expand Down

0 comments on commit cf02384

Please sign in to comment.