nk412 / optparse

Simple command line arguments parser for BASH
MIT License
158 stars 32 forks source link

Tempfile-free evaluation by `optparse.compose` (fullly backward-compatible) #27

Open ShamrockLee opened 2 years ago

ShamrockLee commented 2 years ago

The previous API requires a temporary file to be created and sourced, which might be a problem in restricted environments where accessing to temporary directories are restricted or where file IO is relatively expensive. Besides, the temporary files are often left undeleted despite the rm line being sourced.

This PR proposes a way to print out the configuration headers through a new function optparse.compose, which can be evaluated (eval "$(optparse.compose)") or sourced (. <<(optparse.compose)) in the user scripts to include the configurations without the need of temporary files.

The changes are a backward-compatible, as optparse.build now write to the temporary file the result of optparse.compose plus the line remove $tempfile.

This PR also include some house-keeping such as removing trailing white spaces and tabs from the generated result, sample_head.sh and README.md.