Project from "The Book", slightly modified.
The application checks text by each new line. The terminal then returns output of the corresponding Query term and the line it resides on.
cargo install
cargo run QUERY_TERM FILENAME.FILE_EXTENSION
-
QUERY_TERM:
- The query term is searched against all text within the specified file.
- After the QUERY_TERM is found the program retruns a line with the specified text.
-
FILENAME.FILE_EXTENSION
- This is the file that is being queried against the QUERY_TERM.
-
QUERY_TERM = foo
-
FILENAME.FILE_EXTENSION = foobar.txt
"\ Hello World! My name is foo bar, and I love programming."
-
Command:
cargo run foo foobar.txt
The Terminal Output is: "My name is foo bar,"
Case Insensitive Search (C.I.S.) is similar to Case Sensitive Search (C.S.S.). Both of them use a QUERY_TERM and a FILENAME.FILE_EXTENSION as their Environment Arguments.
The difference between C.I.S. and C.S.S. is the addition of the optional argument "CASE_INSENSITIVE". The application checks whether or not it exists, and if it does then queries the text via Case Insensitivity.
Due to the varying ecosystems and the complexity of each systems API for env variables the way to do it for Windows is different then Linux/Mac.
The Terminal residing in Linux/Mac has a separate API for handling environment variables and has separate commands for interacting with the terminal.
CASE_INSENSITIVE=1 cargo run QUERY_TERM FILENAME.FILE_EXTENSION
Windows allows you to set the environment variables via the set
command.
This sets the environment variable in the OS and allows the program to perform C.I.S. .
set CASE_INSENSITIVE=1
cargo run QUERY_TERM FILENAME.FILE_EXTENSION
OR
set CASE_INSENSITIVE=1 && cargo run QUERY_TERM FILENAME.FILE_EXTENSION
To unset the ENV variable set it with an empty value:
set CASE_INSENSITIVE=
cargo run QUERY_TERM FILENAME.FILE_EXTENSION
OR
set CASE_INSENSITIVE= && cargo run QUERY_TERM FILENAME.FILE_EXTENSION
Only dependency necessary for this is ansi_term. This is used to colorize the output of the terminal.