Write your own cat Tool - Python
The code is structured under cat and is using Pipenv as the package manager
See,
cat.py --help
age: cat OPTION... [FILE]...
Concatenate FILES(s) to standard output.
With no FILE, or when FILE is -, read standard input.
positional arguments:
FILE The name of the input files, when not specified, reads from stdin. (default: [<_io.BufferedReader name='<stdin>'>])
options:
-h, --help show this help message and exit
-A, --show-all equivalent to -vET (default: False)
-b, --number-nonblank
number nonempty output lines, overrides -n (default: False)
-e equivalent to -vE (default: False)
-E, --show-ends display $ at end of each line (default: False)
-n, --number number all output lines (default: False)
-s, --squeeze-blank suppress repeated empty output lines (default: False)
-t equivalent to -vT (default: False)
-T, --show-tabs display TAB characters as ^I (default: False)
-u (ignored) (default: False)
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB (default: False)
--version output the version and exit
-V Increase the verbosity (default: 0)
Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.
cat -n tests/testdata/test.txt
The cat is in ./cat.py and super straightforward for the basic options
There is not any useful test, just a place holder for future options
pytest -v
The directory contains the testdata mentioned in the challenge.
cd tests
./test.sh -p
- The option --show-nonprinting is tricky and not implemented, see open issue #14
- The handling on printing line number is also different, GNU cat uses 6-20 as fieldwidth and may be '\t', not something that I think is important at the moment