/kat

A cut variation implemented in Rust

Primary LanguageRustApache License 2.0Apache-2.0

GitHub CI codecov

kat (cut variation in Rust)

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.

Capabilities

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:

  1. It doesn't handle lines with differing delim count. So 1_2_3\n4_5 would cause the second line to error out (TODO)
  2. Orders the fields/bytes/chars specified. So -f 3,2,1 would end up becoming -f 1,2,3
  3. It doesn't allow more than a single filtering criteria (bytes/chars/fields)
  4. It handles quote delimited fields (For a CSV, for e.g. "10,000 years",abc line has two fields instead of 3)

Running Tests

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

Future enhancements

  1. Improve test coverage
  2. Add support for zero terminated line delimiter (NUL byte)
  3. Add support for not printing lines which don't have the delimiter
  4. Add support for specifying a custom output delimiter

Code Coverage

Code coverage is done as part of CI builds using tarpaulin. The reports can be found at Codecov The next steps would be to:

  1. Try uploading the coverage results to Coveralls
  2. Use grcov which is a coverage tool used by Mozilla
  3. Generate release artifacts and build on multiple platforms (A sample workflow)

Reference