#target-directory #watch #pre-processor #target-file #include

build simple-include

A simple tool to include files in other files. Looks for lines with a given prefix and replaces them with the contents of the file they point to. Can watch for changes in the source directory and keep the target directory in sync.

4 releases (2 breaking)

0.3.0 Nov 22, 2024
0.2.1 Nov 18, 2024
0.2.0 Nov 18, 2024
0.1.0 Nov 10, 2024

#95 in Build Utils

Download history 95/week @ 2024-11-08 262/week @ 2024-11-15 168/week @ 2024-11-22 6/week @ 2024-11-29 22/week @ 2024-12-06

462 downloads per month

MIT license

20KB
330 lines

A simple include preprocessor

Reads all text files in the source directory and writes them to the target directory, replacing all instances of the include prefix followed by a file name with the contents of the included file. All subdirectories are also parsed, and copied to the target directory with the same structure.

Can be set to watch for changes in the source directory and regenerate the files in the target directory. This is useful for development, where you want to see the changes in the target directory as you make them in the source directory.

Example

If we have the following files: File main.rs

Contents:

--include disclaimer.txt
struct Food {
...

File disclaimer.txt

Contents:

//Don't sue me if it breaks

running simple-include would generate a file target/main.rs with the contents:

//Don't sue me if it breaks
struct Food {
...

If the -w (or --watch) value is set to true, the program stays running and will regenerate the target file if either main.rs or disclaimer.txt is changed.

Include syntax

The include prefix defaults to --include and can be set to something else with the -i (or --include) flag, but is always followed by a space then the filename. Paths can be relative (e.g. ../includes/header.txt) or absolute (e.g. /etc/motd)

Binary files will not be parsed, but will be copied to the target directory. This allows a typical use case where you want to run against a src folder and have all of the results copied to the target folder

Do not use when you can't trust the src directory as it will include any file referenced in an include, even if it is outside of the src directory, so --include /etc/passwd would work if the program has the right permissions, for example.

Usage

A simple tool to include files in other files. Looks for lines with a given prefix and replaces them with the contents of the file they point to. Can watch for changes in the source directory and keep the target directory in sync.

Usage: simple-include [OPTIONS]

Options:
  -w, --watch              Watch for changes in the source directory
  -s, --src <SRC>          Source directory [default: .]
  -t, --target <TARGET>    Target directory [default: target]
  -i, --include <INCLUDE>  Include Prefix [default: --include]
  -v, --verbose            Verbose output - prints the input and output file paths
  -h, --help               Print help
  -V, --version            Print version

Status

It works for me... The test cases cover only basic functionality. I have tested it on linux and windows for simple use cases. If you find a bug, please run with the -v flag and (if possible) let me know what the input and output files are, and I will try to fix it. If you are comfortable with rust (or even if you are not, but would like to try), feel free to submit a PR.

Dependencies

~1.7–8.5MB
~81K SLoC