Skip to content

Repository files navigation

mugo

License Coverage GitHub Workflow Status Go PKG Web

Lightweight template executor written in Go. It uses the text/template package to render templates.

Inspired by hugo to run small workflows.

Usage

Input file could be anything which can include go template syntax.

Usage:
  mugo <template> [flags]

Examples:
mugo -d @data.yaml template.tpl
mugo -d '{"Name": "mugo"}' -o output.txt template.tpl
mugo -d '{"Name": "mugo"}' -o output.txt - < template.tpl
mugo -d '{"Name": "mugo"}' - <<< "{{.Name}}"
mugo -d '{"Name": "mugo"}' -t @template.tpl
mugo -t '{{.Name}}' data.yaml

Flags:
  -d, --data stringArray            input data as json/yaml or file path with @ prefix could be '.yaml','.yml','.json','.toml' extension
  -r, --data-raw                    set input data as raw
  -b, --data-raw-byte               raw data is byte
      --delims string               comma or space separated list of delimiters to alternate the default "{{ }}"
      --disable-func stringArray    disabled functions for run template
      --disable-group stringArray   disabled groups for run template
      --enable-func stringArray     specific functions for run template
      --enable-group stringArray    specific function groups for run template
  -h, --help                        help for mugo
      --html                        use html/template instead
  -k, --insecure                    skip verify ssl certificate
  -l, --list                        function list
      --log-level string            log level (debug, info, warn, error), default is info (default "info")
      --no-at                       disable @ prefix for file path
      --no-retry                    disable retry on request
  -n, --no-stdin                    disable stdin input
  -o, --output string               output file, default is stdout
  -p, --parse stringArray           parse file pattern for define templates 'testdata/**/*.tpl'
      --perm-file string            create file permission, default is 0644
      --perm-folder string          create folder permission, default is 0755
      --random-seed int             seed for random function, default is 0 (random by time)
  -s, --silience                    silence log output
  -t, --template string             input template as raw or file path with @ prefix could be file with any extension
      --trust                       trust to execute dangerous functions
  -v, --version                     version for mugo
  -w, --work-dir string             work directory for run template

Example

Cow-say example:

mugo -s -r -d "Moo-ve over" https://raw.githubusercontent.com/rytsh/mugo/main/data/templates/cow.tpl

Development

Build

Build the binary with GoReleaser:

make build
# goreleaser build --snapshot --clean --single-target
Example
go run ./cmd/mugo -r -d "." -p 'testdata/tpl/*.tpl' - < testdata/readStart.tpl > output.json
go run ./cmd/mugo --trust -d '{"dir":"testdata","url":"http://localhost:5501"}' -w "." - < testdata/readSeparate.tpl
go run ./cmd/mugo --trust -d '{"dir":"testdata","url":"http://localhost:5501", "output":"output"}' -w "." data/templates/folderInfo.tpl

Releases

Contributors

Languages