A variation of cut
command implemented in Rust as part of reading "Command line rust" book. This repo uses the latest version of clap which has a different API compared to the API used in the book.
This program supports the following capabilities:
kat 0.1.0
sanjayts
USAGE:
kat [OPTIONS] [FILE]...
ARGS:
<FILE>... [default: -]
OPTIONS:
-b, --bytes <LIST>
-c, --characters <LIST>
-d, --delimiter <DELIM> Use DELIM instead of TAB for delimiter [default: "\t"]
-f, --fields <LIST>
-h, --help Print help information
-V, --version Print version information
This program differs from the original cut
in a number of ways:
- It doesn't handle lines with differing delim count. So
1_2_3\n4_5
would cause the second line to error out (TODO) - Orders the fields/bytes/chars specified. So
-f 3,2,1
would end up becoming-f 1,2,3
- It doesn't allow more than a single filtering criteria (bytes/chars/fields)
- It handles quote delimited fields (For a CSV, for e.g.
"10,000 years",abc
line has two fields instead of 3)
We have a mix of unit and integration tests in our code. The unit tests are in the lib.rs and main.rs file under their respective test mod. We can run unit tests in respective modules using the command:
cargo test --bin kat #run tests in main
cargo test --lib # run tests in lib.rs
cargo test --test cli # run integration tests in cli.rs
- Improve test coverage
- Add support for zero terminated line delimiter (NUL byte)
- Add support for not printing lines which don't have the delimiter
- Add support for specifying a custom output delimiter
Code coverage is done as part of CI builds using tarpaulin. The reports can be found at Codecov The next steps would be to:
- Try uploading the coverage results to Coveralls
- Use grcov which is a coverage tool used by Mozilla
- Generate release artifacts and build on multiple platforms (A sample workflow)