ghostwriter

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 10 Imported by: 0

README

ghostwriter

Github Actions

Support OpenSourceCorp on Ko-Fi!

Ghostwriter is a CLI utility to generate code, configuration, IaC, dependency files, and more from template files -- all using a single config file & Go text templates.

Similar in spirit to HashiCorp Consul Template, but does not rely on another service running to manage the config values & rendering for you.

Installation

ghostwriter is distributed as a single Go binary named ghostwrite (a verb, without the trailing "r"), and can be easily installed a number of ways.

Download Releases

The easiest way to get ghostwriter is to download the latest release from the Releases page, and extract the ghostwrite binary to somewhere on your PATH, e.g. /usr/local/bin.

Install from Source

If you have a working Go 1.17+ environment, you can install with go itself:

go install github.com/opensourcecorp/ghostwriter@<latest|vX.Y.Z>

Note that installing this way will name your binary ghostwriter to match the package name, and NOT ghostwrite as the packaging process specifies. You can either rename it, symlink it, or just call the binary as-is.

Usage

Assuming you're ok with the default behavior (documented below), and your config file has data in it, you just need to run:

ghostwrite

from the directory that you want to render templates from. That's it!

Files are written out with the same name the same as their input file, just in your output directory instead. So for example, assuming the default behavior and with a directory tree that looks like this:

.
|-- ghostwriter.yaml
|-- some
|-- files
|-- to
|-- render

then calling ghostwrite from the root will result in the following tree, having rendered your templates in-flight:

.
|-- ghostwriter.yaml
|-- some
|-- files
|-- to
|-- render
|-- gw-rendered/
    |-- some
    |-- files
    |-- to
    |-- render
CLI Options

The ghostwrite CLI supports the following flags:

  • -config-file: The config file containing your render data. Default: ghostwriter.yaml

  • -input-dir: The input directory to render templates from. Default: .

  • -output-dir: The output directory where the rendered tree will be reconstructed. Default: gw-rendered

The .gwignore file

Using entries in a file at your directory root called .gwignore, you can use regular expressions to exclude certain path patterns from ghostwrite's rendering. For example, to ignore all paths containing secret, you can put a line containing secret into the .gwignore. If you want to be sure to ignore any path containing "secret" at all, you can instead put .*secret.*. Note that these are regular expressions, not shell globs such as you might find in a .gitignore (i.e. they're processed by Go's regexp package).

Roadmap Notes

  • Explore if only touching *.gw files as templates makes sense (that's how it was in the previous Python version)

  • Allow outputs to be added to the repo's .gitignore.

  • Allow users to pass single files as render sources/targets, vs. requiring directories.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL