Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed May 29, 2024
1 parent 56f169b commit 3db5eb2
Show file tree
Hide file tree
Showing 15 changed files with 49,411 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
version: "~> 1"
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 5 additions & 20 deletions cli/cage/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,23 @@ import (
"golang.org/x/xerrors"
)

type CageCommands interface {
Commands(
envars *cage.Envars,
) []*cli.Command
}

type cageCommands struct {
type CageCommands struct {
Prompt *prompt.Prompter
cageCliProvier cageCliProvier
}

func NewCageCommands(
stdin io.Reader,
cageCliProvier cageCliProvier,
) CageCommands {
return &cageCommands{
) *CageCommands {
return &CageCommands{
Prompt: prompt.NewPrompter(stdin),
cageCliProvier: cageCliProvier,
}
}

type cageCliProvier = func(envars *cage.Envars) (cage.Cage, error)

func (c *cageCommands) Commands(envars *cage.Envars) []*cli.Command {
return []*cli.Command{
c.Up(envars),
c.RollOut(envars),
c.Run(envars),
c.Recreate(envars),
}
}

func DefalutCageCliProvider(envars *cage.Envars) (cage.Cage, error) {
conf, err := config.LoadDefaultConfig(
context.Background(),
Expand All @@ -62,7 +47,7 @@ func DefalutCageCliProvider(envars *cage.Envars) (cage.Cage, error) {
return cagecli, nil
}

func (c *cageCommands) requireArgs(
func (c *CageCommands) requireArgs(
ctx *cli.Context,
minArgs int,
maxArgs int,
Expand All @@ -77,7 +62,7 @@ func (c *cageCommands) requireArgs(
return
}

func (c *cageCommands) setupCage(
func (c *CageCommands) setupCage(
envars *cage.Envars,
dir string,
) (cage.Cage, error) {
Expand Down
11 changes: 9 additions & 2 deletions cli/cage/commands/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ func TestCommands(t *testing.T) {
stdin := strings.NewReader(input)
cagecli := mock_cage.NewMockCage(ctrl)
app := cli.NewApp()
app.Commands = commands.NewCageCommands(stdin, func(envars *cage.Envars) (cage.Cage, error) {
cmds := commands.NewCageCommands(stdin, func(envars *cage.Envars) (cage.Cage, error) {
return cagecli, nil
}).Commands(&cage.Envars{CI: input == ""})
})
envars := cage.Envars{CI: input == ""}
app.Commands = []*cli.Command{
cmds.Up(&envars),
cmds.RollOut(&envars),
cmds.Run(&envars),
cmds.Recreate(&envars),
}
return app, cagecli
}
t.Run("rollout", func(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions cli/cage/commands/export_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cli/cage/commands/recreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2"
)

func (c *cageCommands) Recreate(
func (c *CageCommands) Recreate(
envars *cage.Envars,
) *cli.Command {
return &cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cli/cage/commands/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/urfave/cli/v2"
)

func (c *cageCommands) RollOut(
func (c *CageCommands) RollOut(
envars *cage.Envars,
) *cli.Command {
return &cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cli/cage/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli/v2"
)

func (c *cageCommands) Run(
func (c *CageCommands) Run(
envars *cage.Envars,
) *cli.Command {
return &cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cli/cage/commands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2"
)

func (c *cageCommands) Up(
func (c *CageCommands) Up(
envars *cage.Envars,
) *cli.Command {
return &cli.Command{
Expand Down
29 changes: 29 additions & 0 deletions cli/cage/commands/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package commands

import (
"github.com/loilo-inc/canarycage/cli/cage/upgrade"
"github.com/urfave/cli/v2"
)

func (c *CageCommands) Upgrade(
currVersion string,
) *cli.Command {
var preRelease bool
return &cli.Command{
Name: "upgrade",
Usage: "upgrade cage binary with the latest version",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "pre-release",
Usage: "include pre-release versions",
Destination: &preRelease,
},
},
Action: func(ctx *cli.Context) error {
return upgrade.Upgrade(&upgrade.Input{
CurrentVersion: currVersion,
PreRelease: preRelease,
})
},
}
}
18 changes: 16 additions & 2 deletions cli/cage/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"

Expand All @@ -9,15 +10,28 @@ import (
"github.com/urfave/cli/v2"
)

// set by goreleaser
var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
app := cli.NewApp()
app.Name = "canarycage"
app.Version = "4.0.0-rc1"
app.Version = fmt.Sprintf("%s (commit: %s, date: %s)", version, commit, date)
app.Usage = "A deployment tool for AWS ECS"
app.Description = "A deployment tool for AWS ECS"
envars := cage.Envars{}
cmds := commands.NewCageCommands(os.Stdin, commands.DefalutCageCliProvider)
app.Commands = cmds.Commands(&envars)
app.Commands = []*cli.Command{
cmds.Up(&envars),
cmds.RollOut(&envars),
cmds.Run(&envars),
cmds.Recreate(&envars),
cmds.Upgrade(version),
}
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "ci",
Expand Down
Loading

0 comments on commit 3db5eb2

Please sign in to comment.