Run markdown codeblocks by its heading.
It searches(case ignored) for a cr.md file, then .cr.md, then README.md in the current or parent directories.
You can refer the markdown file to use with option -f
or --file
.
For more information, run with option --help
.
For example:
./cr test sh -- foo bar
Features:
- scoped env
Prefixed env
- MD_EXE
- MD_FILE
Custom env
key | value |
---|---|
scope_root | foo |
scope | global |
The basic idea is make markdown work like makemenuconfig
Test with README.md
- find the target markdown file in current dir in the name of README.md case ignored, if not found, search upper dir, or direct a file with -f or --file option
- run Tag as subcommand, following arguments as positional arguments.
- depends
- target toolchain
Show not be displayed
Run go mod tidy
go mod tidy
Build this program
go build -ldflags="-w -s"
Install this program
go run . build
PROG=$(basename "${MD_EXE}")
if command -v sudo >/dev/null; then
sudo install "${PROG}" "/usr/local/bin/${PROG}"
elif test "${PREFIX+1}"; then
install "${PROG}" "${PREFIX}/bin/${PROG}"
fi
Uninstall this program
PROG=$(basename "${MD_EXE}")
if command -v sudo >/dev/null; then
sudo rm $(command -v "${PROG}")
elif test "${PREFIX+1}"; then
rm $(command -v "${PROG}")
fi
Benchmark this program
go run . build
hyperfine "${MD_EXE} test env" "$@"
Test this program
key | value |
---|---|
scope_test | bar |
scope | test |
go run . build
${MD_EXE} test env
${MD_EXE} test env sub
${MD_EXE} test args
${MD_EXE} test multiple
echo Hello | ${MD_EXE} test stdin
echo "cr file size: $(du -ahd0 ${MD_EXE} | ${MD_EXE} test awk)"
Test scoped env
key | value |
---|---|
scope_env | 123 |
scope | env |
for env in \
MD_EXE \
MD_FILE \
scope_root \
scope_test \
scope_env \
scope; do
eval echo "env ${env}=\${${env}}"
done
Test scoped env (heading +1)
key | value |
---|---|
scope | sub |
echo "sub scope=${scope}"
Test shellscript
echo "shellscript with arguments: $*"
Test javascript
console.log(`nodejs with arguments: ${process.argv}`);
Test python
import sys
print("python with arguments: %s" %(sys.argv))
Print first column in awk
{print $1}
Test program with arguments
${MD_EXE} test sh -- a b c
${MD_EXE} test js -- a b c
${MD_EXE} test py -- a b c
Test multiple codeblocks
echo codeblock 1 in multiple
echo codeblock 2 in multiple
Read stdin in shell
echo "stdin: $(cat)"
Reset to the initial commit
git reset --hard $(git rev-list --max-parents=0 HEAD)
git pull