Port `--file` (command file) feature to Go
What is a command file
A command file is a file containing command line options (commands) and/or identifiers (e.g. transaction hashes).
Example 1, single command only
--verbose --fmt json --output /tmp/out.json
Example 2, single identifier only
15644881
Example 3, mixed single command with identifier
--verbose --fmt json --output /tmp/out.json 15644881
Example 4, multiple commands only
--verbose --fmt json --output /tmp/out.json
--fmt csv --output /tmp/out.csv
--verbose --fmt tsv --output /tmp/out.tsv
Example 5, multiple identifiers only
15644883
15644882
15644881
Example 6, mixed multiple commands and identifiers
--verbose --fmt json --output /tmp/out.json
--fmt csv --output /tmp/out.csv
--verbose --fmt tsv --output /tmp/out.tsv
15644883
15644882
15644881
Example 7, mixed with identifiers on the same line
--verbose --fmt json --output /tmp/out.json
--fmt csv --output /tmp/out.csv
--verbose --fmt tsv --output /tmp/out.tsv
15644883 15644882 15644881
Example 8, mixed with identifiers and commands on the same line
--verbose --fmt json --output /tmp/out.json 15644883
--fmt csv --output /tmp/out.csv
--verbose --fmt tsv --output /tmp/out.tsv
15644882
15644881
How it should work
Each command adds additional data processing, but all commands are processed in the same time, so the result is same as calling chifra multiple times, but performance is improved. Example 6 would make chifra to produce the output in three different formats while processing the blocks.
All identifiers are collected together and applied to each command. Example 6 results in json, csv and tsv formats being produced for all 3 blocks. Example 7 is same as Example 6 (multiple identifiers placed on the same line without any command equal identifiers placed one-per-line).
In Example 8, a line in the file contains both commands and identifiers and there are identifiers listed later in the file. In such a case, the commands in the first line of the Example would only receive 15644883 as an identifier and all other commands would receive the two remaining identifiers (15644882, 15644881). In other words, JSON output would be produced only for block 15644883. csv and tsv outputs would be produced for both blocks 15644882 and 15644881.
Example 3 would simply apply commands to given block and is same as calling chifra on the command line.
Example 1 and 4 would expect identifiers to be provided on the command line. Example 2 and 5 would apply no additional commands.
If identifiers are provided in a file and on the command line, they are merged together into one array (this includes only identifiers listed on their own lines in the file): File:
15644883
15644882
15644881
and command line: chifra blocks 15644879 15644880 result in processing of all blocks (in the file and on the command line).
File:
--verbose --fmt json 15644883
15644882
15644881
and command line: chifra blocks 15644879 15644880 would only produce JSON for block 15644883. The default output would be printed for blocks 15644879, 15644880 (command line) and 15644881, 15644882 (from file).
@tjayrush is the description above correct?
I'm going to write gold test cases (and mark them local so they don't fail the testing) for the eight cases above, so we can see what the results should look like. See #2380
I merged your first PR for adding the --output option to the streaming code. It works fine.
Two additional test cases from today's discussion:
--file file contents:
address1 address2 --fmt csv
address3 address4 --fmt csv
Two different tests with the same file:
chifra export --traces --file file --fmt json
chifra export --accounting --fmt txt --file file
Upshot: Order in command line doesn't matter, options found in the --file override options found on the command line.
--file file contents:
address1 --output thing.csv
address2 --output thing.txt
Upshot: 'global' flags in the command file are recognized.