TekWizely / bash-tpl

A smart, lightweight shell script templating engine, written in Bash
MIT License
65 stars 4 forks source link

chore: Simplify State/Stack/Indent Logic #14

Closed TekWizely closed 1 year ago

TekWizely commented 1 year ago

Makes indentation tracking/fix-up logic easier to reason about

chore: Tracks text indentation fix-up 'inline'

bug: Errors if EOF found while looking for stmt-close tag

bug: Errors if stmt-close tag not at same indentation level as open

bug: Simplify default behavior for non-fully-indented stmt-blocks

chore: Changes behavior of stack vars (STATES, *_INDENTS)

chore: Removes PRINT_INDENT* variables

chore: Adds BLOCK_INDENT* variables

chore: process_tags invokes print_statement

chore: Leaves BASH_TPL_DEBUG check uncommented

chore: Makes debug values easier to read

Breaking Change: Now generates errors if stmt-close tags are either missing or don't match indentation of open-tag

Breaking Change: If not-all of a stmt-blocks lines are indented at or beyond the open block tag, then the block is rendered relative to the beginning of the line, with no indentation correction applied

TekWizely commented 1 year ago

Hey @flaix this PR is a pretty big revamp of the core logic - It simplifies several areas of logic to make the whole thing easier to reason about, and will hopefully make future enhancements easier too.

I ping you on this because this PR also changes how text is printed, making the indentation of the printf statements more predictable. i.e.:

test.tpl

one
    two
        three
    four
five

previous version

printf "%s\n" one
    printf "%s\n" $'\ttwo'
        printf "%s\n" $'\t\tthree'
    printf "%s\n" $'\tfour'
printf "%s\n" five

this pr version

printf "%s\n" one
printf "%s\n" $'\ttwo'
printf "%s\n" $'\t\tthree'
printf "%s\n" $'\tfour'
printf "%s\n" five

NOTE: This PR does not address your desire to be able to fully-disable indentation-correction - I'm still grinding on that one.

I've tested this against your Dockerfile (and my 2 formatting modifications of it mentioned previously) and I'm pleased with the results.

Lemme know if you get a chance to play with this - I'll leave the PR open for a few days before merging just in case ...

-TW

flaix commented 1 year ago

I haven't played much with it, just took the opportunity to regenerate my files. I must say the properly indented printf do look clean. 👍 With them aligned, the alignment of the printed text is much clearer.

TekWizely commented 1 year ago

Hey @flaix thanks for the note - thats good enough for me to merge and cut a new version ...