diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 54a423d..2b889c9 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -2,7 +2,11 @@ name: checks on: pull_request: + branches: + - main push: + branches: + - main workflow_dispatch: permissions: @@ -12,40 +16,64 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV - - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v4 + + - name: Capture Go Version + run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV + + - name: Setup Go + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - uses: actions/cache@v2 - continue-on-error: true - timeout-minutes: 2 + + - name: Setup Cache + uses: actions/cache@v4 if: ${{ !env.ACT }} with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} - restore-keys: ${{ runner.os }}-go- - - run: ./script/bootstrap - - run: golangci-lint run ./... + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Bootstrap + run: ./script/bootstrap + + - name: Lint + run: ./script/lint test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV - - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v4 + + - name: Capture Go Version + run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV + + - name: Setup Go + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - uses: actions/cache@v2 - continue-on-error: true - timeout-minutes: 2 + + - name: Setup Cache + uses: actions/cache@v4 if: ${{ !env.ACT }} with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} - restore-keys: ${{ runner.os }}-go- - - run: ./script/bootstrap - - run: ./script/test + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Bootstrap + run: ./script/bootstrap + + - name: Lint + run: ./script/test snapshot: needs: @@ -54,28 +82,38 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Fetch all tags run: git fetch --force --tags - - run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV - - uses: actions/setup-go@v2 + + - name: Capture Go Version + run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV + + - name: Setup Go + uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - uses: actions/cache@v2 - continue-on-error: true - timeout-minutes: 2 + + - name: Setup Cache + uses: actions/cache@v4 if: ${{ !env.ACT }} with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} - restore-keys: ${{ runner.os }}-go- + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest args: release --clean --snapshot env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# EOF diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 34f8469..99a6874 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -14,27 +14,34 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Fetch all tags run: | - git fetch --force --tags - - run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV - - uses: actions/setup-go@v2 + + - name: Capture Go Version + run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV + + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - - uses: actions/cache@v2 - continue-on-error: true - timeout-minutes: 2 + + - name: Setup Cache + uses: actions/cache@v4 if: ${{ !env.ACT }} with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} - restore-keys: ${{ runner.os }}-go- + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index 10a883b..0000000 --- a/.golangci.yaml +++ /dev/null @@ -1,18 +0,0 @@ -linters: - presets: - - bugs - - comment - - complexity - - error - - format - - import - - module - - style - - test - - unused - disable: - - golint - - interfacer - - scopelint - - exhaustivestruct - - maligned diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3dd1b0a..8a27edc 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,4 +1,5 @@ # Make sure to check the documentation at https://goreleaser.com +version: 2 before: hooks: - go mod tidy @@ -24,18 +25,12 @@ builds: - "linux_ppc64le" archives: - id: default - replacements: - "darwin": "macos" - "386": "i386" - id: binaries format: binary - replacements: - "darwin": "macos" - "386": "i386" brews: - ids: - "default" - tap: + repository: owner: docwhat name: homebrew-tap commit_author: @@ -46,7 +41,7 @@ brews: system "#{bin}/temple /etc/hosts" install: | bin.install "temple" - folder: "Formula" + directory: "Formula" homepage: "https://github.com/docwhat/temple" description: "Sick of sed? Prosaic about perl? Use temple to substitute your variables!" license: "MIT" diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..232771b --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,5 @@ +# Prettier friendly markdownlint config (all formatting rules disabled) +extends: markdownlint/style/prettier + +# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md033.md +MD033: false diff --git a/.trunk/actions b/.trunk/actions new file mode 120000 index 0000000..9193fdb --- /dev/null +++ b/.trunk/actions @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/repos/c7bed0aea4ec2763edf73f34270f4bd1/actions \ No newline at end of file diff --git a/.trunk/logs b/.trunk/logs new file mode 120000 index 0000000..c43a471 --- /dev/null +++ b/.trunk/logs @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/repos/c7bed0aea4ec2763edf73f34270f4bd1/logs \ No newline at end of file diff --git a/.trunk/notifications b/.trunk/notifications new file mode 120000 index 0000000..4e35732 --- /dev/null +++ b/.trunk/notifications @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/repos/c7bed0aea4ec2763edf73f34270f4bd1/notifications \ No newline at end of file diff --git a/.trunk/out b/.trunk/out new file mode 120000 index 0000000..43e76b5 --- /dev/null +++ b/.trunk/out @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/repos/c7bed0aea4ec2763edf73f34270f4bd1/out \ No newline at end of file diff --git a/.trunk/plugins/trunk b/.trunk/plugins/trunk new file mode 120000 index 0000000..90d1c2b --- /dev/null +++ b/.trunk/plugins/trunk @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/plugins/https---github-com-trunk-io-plugins/v1.6.1-4ebadccd80b22638 \ No newline at end of file diff --git a/.trunk/tools b/.trunk/tools new file mode 120000 index 0000000..e504faf --- /dev/null +++ b/.trunk/tools @@ -0,0 +1 @@ +/Users/christianholtje/.cache/trunk/repos/c7bed0aea4ec2763edf73f34270f4bd1/tools \ No newline at end of file diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 28f6672..af0ea68 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -7,7 +7,7 @@ cli: plugins: sources: - id: trunk - ref: v1.6.0 + ref: v1.6.1 uri: https://github.com/trunk-io/plugins # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) runtimes: @@ -19,20 +19,24 @@ runtimes: lint: enabled: - actionlint@1.7.1 - - checkov@3.2.184 + - checkov@3.2.191 - git-diff-check - gofmt@1.20.4 - golangci-lint@1.59.1 - hadolint@2.12.0 - markdownlint@0.41.0 - osv-scanner@1.8.2 - - prettier@3.3.2 + - prettier@3.3.3 - shellcheck@0.10.0 - shfmt@3.6.0 - - taplo@0.8.1 - - trivy@0.52.2 + - taplo@0.9.2 + - trivy@0.53.0 - trufflehog@3.79.0 - yamllint@1.35.1 + ignore: + - linters: [ALL] + paths: + - examples/** actions: enabled: - trunk-announce diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b295620..4dbed4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,8 @@ -Contributing -============ +# Contributing I love pull requests from everyone! -Getting Started ---------------- +## Getting Started ### Install Go @@ -16,26 +14,26 @@ If you will be contributing, then you'll want to [fork the repository](https://h Once you've forked it, then you can clone the source: -``` sh -$ git clone git@github.com:/.git +```sh +git clone git@github.com:/.git ``` Fetch the required dependencies: -``` sh -$ script/bootstrap +```sh +script/bootstrap ``` Before you do any changes, make sure the tests pass: -``` sh -$ script/test +```sh +script/test ``` Make your change. Add tests for your change. Make the tests pass: -``` sh -$ script/test +```sh +script/test ``` Push to your fork and [submit a pull request](https://help.github.com/articles/creating-a-pull-request/). @@ -47,29 +45,28 @@ Some things that will increase the chance that your pull request is accepted: - Write tests. - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). -Releases --------- +## Releases 1. Update the `CHANGELOG.md`. See [keepachangelog.com](http://keepachangelog.com/) for info. 2. Commit `CHANGELOG.md` 3. Copy the current change log entry for the version to be released. 4. Tag the new version. Example: - ``` sh - $ git tag v0.1.0 + ```sh + git tag v0.1.0 ``` 5. Push up the commit and tag: - ``` sh - $ git push - ... - $ git push --tags - ... + ```sh + git push + # ... + git push --tags + # ... ``` 6. Go to [the releases page](https://github.com/docwhat/temple/releases) 1. Click on "Edit" 2. The name should match the tag. e.g. `v0.1.0` - 2. Paste in the change log entry. - 3. Save. + 3. Paste in the change log entry. + 4. Save. diff --git a/README.md b/README.md index 2a8c921..f986464 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,20 @@ go install docwhat.org/temple ## Usage - Usage: temple +```text +Usage: temple - A simple templating engine +A simple templating engine - Arguments: - The template file to use ($TEMPLE_TEMPLATE_FILE) +Arguments: + The template file to use ($TEMPLE_TEMPLATE_FILE) - Flags: - -h, --help Show context-sensitive help. - --version Show version information - -d, --data=DATA-FILE A YAML or JSON file to use via the {{data.}} interface ($TEMPLE_DATA_FILE) - -H, --html Use HTML templating instead of text templating ($TEMPLE_USE_HTML) +Flags: + -h, --help Show context-sensitive help. + --version Show version information + -d, --data=DATA-FILE A YAML or JSON file to use via the {{data.}} interface ($TEMPLE_DATA_FILE) + -H, --html Use HTML templating instead of text templating ($TEMPLE_USE_HTML) +``` Note that the `DATA` file must have an object at the top level. You cannot use a bare string or an array. @@ -52,8 +54,8 @@ JSON Example: ```json { - "key": "value", - "key2": 2 + "key": "value", + "key2": 2 } ``` @@ -74,41 +76,41 @@ Temple supports the complete list of [Sprig functions](http://masterminds.github ### Data Sources -* `{{hostname}}` -- The systems fully qualified domain name. -* `{{uid}}` -- `UID` of the user running `temple`. -* `{{gid}}` -- `GID` of the user running `temple`. -* `{{euid}}` -- Effective `UID` of the user running `temple`. -* `{{egid}}` -- Effective `GID` of the user running `temple`. -* `{{pwd}}` -- The current working directory. -* `{{json}}` -- Access to your JSON data. Use dot notation to get access to items. e.g. `{{json.authors.greenwood.first_name}}` +- `{{hostname}}` -- The systems fully qualified domain name. +- `{{uid}}` -- `UID` of the user running `temple`. +- `{{gid}}` -- `GID` of the user running `temple`. +- `{{euid}}` -- Effective `UID` of the user running `temple`. +- `{{egid}}` -- Effective `GID` of the user running `temple`. +- `{{pwd}}` -- The current working directory. +- `{{json}}` -- Access to your JSON data. Use dot notation to get access to items. e.g. `{{json.authors.greenwood.first_name}}` ### Functions -* `{{index 99}}` -- The 99th item of the array ``. -* `{{ | js}}` -- `` escaped/quoted for JavaScript & JSON. -* `{{ | html}}` -- `` escaped/quoted for HTML. -* `{{ | urlquery}}` -- `` escaped/quoted for a URL quoting. i.e. replacing spaces with `+` and using `%NN` syntax. -* `{{ | shellquote}}` -- `` escaped/quoted for POSIX shells. -* `{{ | len}}` -- The length of the ``. +- `{{index 99}}` -- The 99th item of the array ``. +- `{{ | js}}` -- `` escaped/quoted for JavaScript & JSON. +- `{{ | html}}` -- `` escaped/quoted for HTML. +- `{{ | urlquery}}` -- `` escaped/quoted for a URL quoting. i.e. replacing spaces with `+` and using `%NN` syntax. +- `{{ | shellquote}}` -- `` escaped/quoted for POSIX shells. +- `{{ | len}}` -- The length of the ``. ### Flow Control -* `{{if }}true string{{else}}false string{{end}}` -- If/Else syntax. The `{{else}}` is optional. -* `{{range }} item: {{.}} {{else}} The list is empty {{end}}` -- Iterate over ``. The `{{else}}` is optional. +- `{{if }}true string{{else}}false string{{end}}` -- If/Else syntax. The `{{else}}` is optional. +- `{{range }} item: {{.}} {{else}} The list is empty {{end}}` -- Iterate over ``. The `{{else}}` is optional. ### Miscellaneous -* `{{ -}}` -- Trim whitespace to the right. e.g. `{{1 -}} .0` becomes `1.0`. -* `{{- }}` -- Trim whitespace to the left. -* `{{- -}}` -- Trim whitespace to the right and left. -* `{{/* comment */}}` -- Comments! +- `{{ -}}` -- Trim whitespace to the right. e.g. `{{1 -}} .0` becomes `1.0`. +- `{{- }}` -- Trim whitespace to the left. +- `{{- -}}` -- Trim whitespace to the right and left. +- `{{/* comment */}}` -- Comments! ## Related Projects -* [gomplate](https://github.com/hairyhenderson/gomplate) +- [gomplate](https://github.com/hairyhenderson/gomplate) ## Thanks -* [@alecthomas](https://github.com/alecthomas) for [kingpin](https://github.com/alecthomas/kingpin) -* [@kballard](https://github.com/kballard) for [go-shellquote](https://github.com/kballard/go-shellquote) -* [@seh](https://github.com/seh) for Go help +- [@alecthomas](https://github.com/alecthomas) for [kingpin](https://github.com/alecthomas/kingpin) +- [@kballard](https://github.com/kballard) for [go-shellquote](https://github.com/kballard/go-shellquote) +- [@seh](https://github.com/seh) for Go help diff --git a/_config.yml b/_config.yml index 259a24e..72d781d 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-tactile \ No newline at end of file +theme: jekyll-theme-tactile diff --git a/functions.go b/functions.go index 0e5c04b..75f7646 100644 --- a/functions.go +++ b/functions.go @@ -29,7 +29,6 @@ func buildFuncMap(dataFile *os.File) (FuncMap, error) { funcMap["pwd"] = os.Getwd funcMap["hostname"] = os.Hostname funcMap["data"], err = dataFunc(dataFile) - if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 6cb718a..5d1fd0d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module docwhat.org/temple -go 1.22.4 +go 1.22.5 require ( github.com/Masterminds/sprig/v3 v3.2.2 @@ -21,6 +21,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/cast v1.4.1 // indirect - golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000 // indirect + golang.org/x/crypto v0.1.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 4f77588..374e82e 100644 --- a/go.sum +++ b/go.sum @@ -48,21 +48,38 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000 h1:SL+8VVnkqyshUSz5iNnXtrBQzvFF2SkROm6t5RczFAE= -golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/main.go b/main.go index abe5613..19dfb0c 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ var ( ) // nolint: lll +// CLI is the main structure for storing information about the application. type CLI struct { Version kong.VersionFlag `name:"version" help:"Show version information"` TemplateFile string `env:"TEMPLE_TEMPLATE_FILE" arg:"" required:"" type:"existingfile" help:"The template file to use"` @@ -23,6 +24,8 @@ type CLI struct { HTML bool `short:"H" env:"TEMPLE_USE_HTML" help:"Use HTML templating instead of text templating"` } +// Run is the bulk of the process that is used by Temple. +// This can be used independently from the CLI. func (cli *CLI) Run() error { var err error @@ -38,6 +41,7 @@ func (cli *CLI) Run() error { return doTextTemplate(cli.TemplateFile, funcMap, os.Stdout) } +// main is the main entry point for the CLI and the command line configuration. func main() { cli := CLI{} diff --git a/script/build b/script/build index e3616ea..6ff361b 100755 --- a/script/build +++ b/script/build @@ -7,6 +7,6 @@ export CGO_ENABLED=0 # Force static compiling version="$(git describe --tags || echo unreleased)" ldflags="-s -w -X main.version=${version} -X main.commit=$(git rev-parse HEAD)" -go build -v -ldflags "$ldflags" ./... +go build -v -ldflags "${ldflags}" ./... # vim: set ft=sh : diff --git a/script/lint b/script/lint index cd6f32d..94bf905 100755 --- a/script/lint +++ b/script/lint @@ -4,7 +4,25 @@ set -euo pipefail -echo "Running lint..." -golangci-lint run ./... +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +readonly root + +x() { + printf -- "+" + printf -- " %q" "$@" + printf -- "\n" + "$@" +} + +flags=() + +if [[ -n ${CI-} ]]; then + echo "Running lint in CI mode..." + flags+=("--ci") +else + echo "Running lint..." +fi + +x "${root}/script/trunk" check "${flags[@]:+"${flags[@]}"}" # vim: set ft=sh : diff --git a/script/test b/script/test index 9dd6cd2..2a89660 100755 --- a/script/test +++ b/script/test @@ -6,15 +6,9 @@ set -euo pipefail # tput can be grumpy if TERM isn't set right... this wraps it if # it exists or provides an no-op replacement. -if command -v tput >/dev/null 2>&1 && tput sgr0 2>/dev/null; then - function tput { - command tput "$@" 2>/dev/null || true - } -else - function tput { - true - } -fi +function tput { + command tput "$@" 2>/dev/null || true +} function header { tput sgr0 @@ -30,15 +24,15 @@ function inc_color { if ((global_color > 7)); then global_color=1 fi - printf "%d" "$global_color" + printf "%d" "${global_color}" } function colorpipe { local c=$1 line while read -r line; do - tput setaf "$c" - printf "\t%s" "$line" + tput setaf "${c}" + printf "\t%s" "${line}" tput sgr0 echo done @@ -59,7 +53,12 @@ function runc { global_color=2 fi - "$@" | colorpipe "$global_color" || failures=$((failures + 1)) + # shellcheck disable=SC2310 + if "$@" | colorpipe "${global_color}"; then + true + else + failures=$((failures + 1)) + fi } header "Running tests..." @@ -67,7 +66,7 @@ runc go test ./... -v header "Running examples..." for example in examples/*; do - if [ ! -d "$example" ]; then + if [[ ! -d ${example} ]]; then continue fi @@ -78,22 +77,22 @@ for example in examples/*; do yaml=$(compgen -G "${example}/*.yaml" || :) TODAY_IS=$(date '+%x') - if [ -r "${json}" ] || [ -r "${yaml}" ]; then - if [ -r "${json}" ]; then - runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=json-data go run ./... --data "$json" "$template" + if [[ -r ${json} ]] || [[ -r ${yaml} ]]; then + if [[ -r ${json} ]]; then + runc env "TODAY_IS=${TODAY_IS}" RUNNING_WITH=json-data go run ./... --data "${json}" "${template}" fi - if [ -r "${yaml}" ]; then - runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=yaml-data go run ./... --data "$yaml" "$template" + if [[ -r ${yaml} ]]; then + runc env "TODAY_IS=${TODAY_IS}" RUNNING_WITH=yaml-data go run ./... --data "${yaml}" "${template}" fi else - runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=env go run ./... "$template" + runc env "TODAY_IS=${TODAY_IS}" RUNNING_WITH=env go run ./... "${template}" fi done if ((failures > 0)); then tput setaf 1 # red tput bold - printf "FAILURES: %d\n" "$failures" + printf "FAILURES: %d\n" "${failures}" tput sgr0 exit 1 fi