Implementation of head(1) CLI utility from scratch in C++ following the Build Your Own Head Tool coding challenge.
To setup and run this project locally, please follow the below steps:
-
C/C++ Compiler: Please make sure that you have a C/C++ compiler installed on your system, preferably gcc or clang.
-
Install make:
If you are using Mac, and have Homebrew installed, use :
brew install make- Clone the project on your machine.
git clone https://github.com/MahendraDani/head.git
- Build from source
First change directory, cd head, then
makeThis command will build the project from source, and output the executable bin/cat.
To verify clean installation, try running:
./cchead data/text.txtYou should be able to see first 10 lines of the data/text.txt file printed on the console.
For usage, please read the man page of head(1)
- Read input from a file
./cchead file.txt- Read from multiple files and concatenate
./cchead file1.txt file2.txt file3.txt- Read from stdin
./cchead- Show first n lines
./cchead -n4 file.txt- Show first c bytes
./cchead -c4 file.txtAlthough writing tests was not included in the challenge, any program to be called "production-ready" should and must be appropriately tested. So I wrote a few tests in shell scripts to test my code.
Much of the inspiration of writing tests is taken from the git project (as you can see from the names of test files :P) which has a lot of tests written in shell scripts.
This also forced me to learn about shell scripting, unit testing and much more, which is also essential in writing good software.
To run the test suite, simply run :
make testIf you want to specially run a particular test file:
tests/<test_script>.shThanks!