Skip to content

Commit

Permalink
- add install with brew instructions
Browse files Browse the repository at this point in the history
- upgrade readme with examples
- rename assert.name -> assert.desc
- include assert.ref to show all
  • Loading branch information
Andrii Abramov committed Nov 8, 2021
1 parent a7f0b42 commit a18fae6
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 42 deletions.
6 changes: 1 addition & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# .goreleaser.yml
brews:
- # Name template of the recipe
# Default to project name
name: goal
- name: goal

# GitHub/GitLab repository to push the formula to
tap:
Expand All @@ -26,7 +23,6 @@ brews:
folder: Formula

# Caveats for the user of your binary.
# Default is empty.
caveats: "See https://github.com/aaabramov/goal"

# Your app's homepage.
Expand Down
98 changes: 89 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,114 @@
# goal
## goal - Go Aliases

GoAl -- Go Aliases
Allows you to create local aliases withing directory/repository with proper assertions upon executions.

Start using:
**The idea behind is to:**

- simplify executing scoped repetitive commands
- avoid executing commands on wrong environment (e.g. _kubectl_, _terraform_, _helm_, _etc._)

## Install

Install via `brew`:

```shell
brew install #TODO
# Will be simplified
brew tap aaabramov/goal https://github.com/aaabramov/goal
brew install aaabramov/goal/goal
```

# Idea behind
## Usage

Create `goal.yaml` file in directory where aliases will be used:

```yaml
workspace:
desc: Current terraform workspace
cmd: terraform
args:
- workspace
- show

tf-apply-dev:
desc: Terraform apply on dev
assert:
desc: Check if on dev workspace
ref: workspace # References goal above
equals: dev # Checks whether trimmed output from 'ref' goal is equal to "dev"
cmd: terraform
args:
- apply
- -var-file
- vars/dev.tfvars

tf-apply-stage:
desc: Terraform apply on stage
assert:
desc: Check if on stage workspace
ref: workspace # References goal above
equals: stage # Checks whether trimmed output from 'ref' goal is equal to "stage"
cmd: terraform
args:
- apply
- -var-file
- vars/stage.tfvars
```

Simply type `goal` to see list of available goals and their dependencies:

```shell
$ goal
Available goals:
+----------------+--------------------------------+-----------------------------+--------------------------------+
| GOAL | CLI | DESCRIPTION | ASSERTIONS |
+----------------+--------------------------------+-----------------------------+--------------------------------+
| tf-apply-dev | terraform apply -var-file | Terraform apply on dev | [workspace] Check if on dev |
| | vars/dev.tfvars | | workspace |
| tf-apply-stage | terraform apply -var-file | Terraform apply on stage | [workspace] Check if on stage |
| | vars/stage.tfvars | | workspace |
| workspace | terraform workspace show | Current terraform workspace | |
+----------------+--------------------------------+-----------------------------+--------------------------------+
```
Let's see if _goal_ would allow us to apply terraform configuration on wrong environment:
```shell
$ terraform workspace show
dev
$ goal tf-apply-stage
⚙️ Exec tf-apply-stage
⌛ Check precondition: Check if on stage workspace
❗ Precondition failed: workspace
Output: "dev"
Expected: "stage"
CLI: terraform workspace show
```
## Idea behind
1. Local alias management
To avoid typing repeatable commands
2. AssD - Aliases as a Documentation :D
No need to read through whole README file to start operating on you infrastructure
# Project plan
## goal vs Makefile
## Project plan
- [ ] Pipe STDIN for "yes/no" inputs, etc.
- [ ] Simpler `brew tap aaabramov/goal`
- [ ] Add manual approve step
- [ ] Add "environment" management to avoid tf-plan-dev, tf-plan-stage, tf-plan-prod, etc.
- [ ] Add "depends on" other task like switch to dev?
- [ ] Recursive dependencies
- [ ] Manual approvals for proceeding
- [ ] Assertions
- [ ] ref output
- [ ] recursive assertions
- [ ] raw CLI output -- bad pattern?
- [ ] ref output
- [ ] recursive assertions
- [ ] raw CLI output -- bad pattern?
- [ ] Global aliases in `$HOME` directory?
- [ ] Self-autocompletion via [https://github.com/posener/complete](complete) library
- [ ] Generate ops-doc from commands
- [ ] Support both goal.yaml & goal.yml
- [ ] Support `-f my-goal.yaml`
- [ ] Add `goal init` which simply generated example `goal.yaml`
21 changes: 13 additions & 8 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Assert struct {
Name string `yaml:"name"`
Desc string `yaml:"desc"`
Ref string `yaml:"ref"`
Equals string `yaml:"equals"`
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *Commands) exec(name string) {
if exists {
info("⚙️ Exec %s", command.Name)
if command.Assert != nil {
info("⌛ Check precondition: %s", command.Assert.Name)
info("⌛ Check precondition: %s", command.Assert.Desc)
ref, exists := c.get(command.Assert.Ref)

if exists {
Expand All @@ -74,7 +74,7 @@ func (c *Commands) exec(name string) {
ref.cli(),
)
} else {
info("✅ Precondition: " + command.Assert.Name)
info("✅ Precondition: " + command.Assert.Desc)
}
} else {
fatal("Unknown assertion ref: %s", command.Assert.Ref)
Expand All @@ -84,7 +84,7 @@ func (c *Commands) exec(name string) {
cmd := osexec.Command(command.Cmd, command.Args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

cmd.Stdin = os.Stdin
err := cmd.Run()

if err != nil {
Expand All @@ -101,9 +101,9 @@ func (c *Commands) exec(name string) {
}

func (c *Commands) render() {
info("Available commands:")
info("Available goals:")
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "CLI", "Description", "Assertions"})
table.SetHeader([]string{"goal", "CLI", "Description", "Assertions"})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
Expand All @@ -119,10 +119,15 @@ func (c *Commands) render() {
for _, cmd := range c.commands {
assertion := ""
if cmd.Assert != nil {
assertion = cmd.Assert.Name
ref, exists := c.get(cmd.Assert.Ref)
if exists {
assertion = fmt.Sprintf("[%s] %s", ref.Name, cmd.Assert.Desc)
} else {

}
}
table.Append([]string{cmd.Name, cmd.cli(), cmd.Desc, assertion})
//fmt.Printf("\t%s: '%s' #%s\n", cmd.Name, cmd.cli(), cmd.Desc)
//fmt.Printf("\t%s: '%s' #%s\n", cmd.Desc, cmd.cli(), cmd.Desc)
}
table.Render()
}
4 changes: 2 additions & 2 deletions examples/helm/goal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ current-context:
helm-upgrade-dev-dry-run:
desc: Dry run upgrade on dev
assert:
name: Check if on dev cluster
desc: Check if on dev cluster
ref: current-context
equals: dev-cluster
cmd: helm
Expand All @@ -25,7 +25,7 @@ helm-upgrade-dev-dry-run:
helm-upgrade-dev:
desc: Upgrade on dev
assert:
name: Check if on dev cluster
desc: Check if on dev cluster
ref: current-context
equals: dev-cluster
cmd: helm
Expand Down
28 changes: 16 additions & 12 deletions examples/terraform/goal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ workspace:
- workspace
- show

tf-plan-dev:
desc: Terraform plan for dev
tf-apply-dev:
desc: Terraform apply on dev
assert:
name: Check if on dev workspace
ref: workspace
equals: dev
desc: Check if on dev workspace
ref: workspace # References goal above
equals: dev # Checks whether trimmed output from 'ref' goal is equal to "dev"
cmd: terraform
args:
- plan
- apply
- -var-file
- vars/dev.tfvars

tf-apply-dev:
desc: Terraform apply for dev
tf-apply-stage:
desc: Terraform apply on stage
assert:
name: Check if on dev workspace
ref: workspace
equals: dev
desc: Check if on stage workspace
ref: workspace # References goal above
equals: stage # Checks whether trimmed output from 'ref' goal is equal to "stage"
cmd: terraform
args:
- plan
- apply
- -var-file
- vars/stage.tfvars
26 changes: 20 additions & 6 deletions goal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ workspace:
- workspace
- show

start:
tf-apply-dev:
desc: Terraform apply on dev
assert:
desc: Check if on dev workspace
ref: workspace # References goal above
equals: dev # Checks whether trimmed output from 'ref' goal is equal to "dev"
cmd: terraform
desc: startscho
args:
- apply
- -var-file
- vars/dev.tfvars

tf-apply-stage:
desc: Terraform apply on stage
assert:
name: Check if on dev workspace
ref: workspace
equals: dev1
desc: Check if on stage workspace
ref: workspace # References goal above
equals: stage # Checks whether trimmed output from 'ref' goal is equal to "stage"
cmd: terraform
args:
- Success
- apply
- -var-file
- vars/stage.tfvars

0 comments on commit a18fae6

Please sign in to comment.