Skip to content

Commit

Permalink
Refactor docs and cmd.version variable
Browse files Browse the repository at this point in the history
  • Loading branch information
containerscrew committed May 24, 2023
1 parent 2944ff3 commit 728e7d5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ dist/
internal/utils/markdown_render/docs/

# OSX
.DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X cmd.version={{ .Tag }}
- -s -w -X github.com/containerscrew/tftools/cmd.version={{ .Tag }}
goos:
- linux
- darwin
Expand Down
3 changes: 1 addition & 2 deletions cmd/tftools/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var (
// printBanner will print an ascii banner with colors
func printBanner() {
templ := `{{ .AnsiColor.BrightMagenta }} {{ .Title "tftools" "" 2 }}{{ .AnsiColor.Default }}
GoVersion: {{ .GoVersion }}
Author: github.com/containerscrew
Now: {{ .Now "Monday, 2 Jan 2006" }}`
banner.InitString(colorable.NewColorableStdout(), true, true, templ)
Expand Down Expand Up @@ -58,6 +57,6 @@ var versionCmd = &cobra.Command{
Short: "tftools current version",
Long: "Get the cli tftools version installed",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("tftools: %v with go version %s %s/%s", version, goversion, goos, goarch)
fmt.Printf("tftools: %s with go version %s %s/%s", version, goversion, goos, goarch)
},
}
13 changes: 12 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@

## Using go

Go install is not a good solution because in order to compile the binary you must first run go generate ./....

```bash
go install github.com/containerscrew/tftools
```
> **NOTE:** this installation mode is broken by using go:embed files. To be fixed 🛠️

> **NOTE:** this will fail as I mentioned 🛠️
You can do the following:

```bash
git clone https://github.com/containerscrew/tftools.git && cd tftools
go generate ./...
go install .
```

## Using brew

Expand Down
4 changes: 2 additions & 2 deletions internal/utils/markdown_render/pretty_markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

// Embed usage documentation.
//go:generate cp -r ../../../docs ./docs
//go:embed docs
//go:generate cp -r ../../../docs/usage.md ./usage.md
//go:embed usage.md

var usage embed.FS

Expand Down
53 changes: 53 additions & 0 deletions internal/utils/markdown_render/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Usage](#usage)
- [Summarize](#summarize)
- [Function for ~/.zshrc](#function-for-zshrc)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Usage

## Summarize

```bash
terraform plan -out plan.tfplan
terraform show -json plan.tfplan | tftools summarize
```

Or if you have the file in json

```bash
terraform plan -out plan.tfplan
terraform show -json plan.tfplan > plan.json
cat plan.json | tftools summarize
```

## Function for ~/.zshrc

Copy [this function](../scripts/tfsum.sh) in your `~/.zshrc` or `~/.bashrc` file.

```bash
function tfsum() {
if [ -z "$1" ];
then
echo "You should type 'tfsum terraform|terragrunt'"
else
echo -e "Starting tf summary..."
# Don't print output of terraform plan
# If you don't want full plan output: $1 plan -out plan.tfplan 1> /dev/null
$1 plan -out plan.tfplan
echo -e "\n\n"
$1 show -json plan.tfplan | tftools summarize
# Delete plan out file to avoid git tracking (although is included in .gitignore)
if [ -f "plan.tfplan" ]; then rm plan.tfplan; fi
fi
}
```

```bash
source ~/.zshrc
tfsum terragrunt or tfsum terraform
```

0 comments on commit 728e7d5

Please sign in to comment.