Skip to content

Commit

Permalink
removed --config flag in favor of TORK_CONFIG env var
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Sep 7, 2023
1 parent 3031fbc commit 435a0e5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Run DB migration
run: |
go run cmd/main.go --config configs/config.ci.toml migration
TORK_CONFIG=configs/config.ci.toml go run cmd/main.go migration
- name: Run tests
run: go test -v ./...
10 changes: 0 additions & 10 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func Run() error {
app := &ucli.App{
Name: "tork",
Usage: "a distributed workflow engine",
Flags: []ucli.Flag{config()},
Before: before,
Commands: commands(),
}
Expand Down Expand Up @@ -76,7 +75,6 @@ func migrationCmd() *ucli.Command {
return &ucli.Command{
Name: "migration",
Usage: "Run the db migration script",
Flags: []ucli.Flag{},
Action: func(ctx *ucli.Context) error {
return bootstrap.Start(bootstrap.ModeMigration)
},
Expand All @@ -87,18 +85,10 @@ func healthCmd() *ucli.Command {
return &ucli.Command{
Name: "health",
Usage: "Perform a health check",
Flags: []ucli.Flag{},
Action: health,
}
}

func config() ucli.Flag {
return &ucli.StringFlag{
Name: "config",
Usage: "Set the location of the config file",
}
}

func displayBanner() {
mode := conf.StringDefault("cli.banner_mode", "console")
if mode == "off" {
Expand Down
11 changes: 4 additions & 7 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
flag "github.com/spf13/pflag"
)

var konf = koanf.New(".")
Expand All @@ -27,11 +26,9 @@ var defaultConfigPaths = []string{

func LoadConfig() error {
var paths []string
f := flag.NewFlagSet("cmd", flag.ContinueOnError)
userConfig := f.String("config", "", "")
f.Parse(os.Args[1:])
if *userConfig != "" {
paths = []string{*userConfig}
userConfig := os.Getenv("TORK_CONFIG")
if userConfig != "" {
paths = []string{userConfig}
} else {
paths = defaultConfigPaths
}
Expand All @@ -55,7 +52,7 @@ func LoadConfig() error {
return errors.Wrapf(err, "error loading config from env")
}
errMsg := fmt.Sprintf("could not find config file in any of the following paths: %s", strings.Join(paths, ","))
if *userConfig != "" {
if userConfig != "" {
return errors.Errorf(errMsg)
} else {
logger.Warn().Msg(errMsg)
Expand Down
10 changes: 4 additions & 6 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ func TestLoadConfigNotExist(t *testing.T) {
}

func TestLoadConfigNotExistUserDefined(t *testing.T) {
old := os.Args
os.Args = append(os.Args, "--config", "no.such.thing")
os.Setenv("TORK_CONFIG", "no.such.thing")
defer func() {
os.Args = old
os.Unsetenv("TORK_CONFIG")
}()
err := conf.LoadConfig()
assert.Error(t, err)
Expand Down Expand Up @@ -96,10 +95,9 @@ func TestLoadConfigCustomPath(t *testing.T) {
defer func() {
assert.NoError(t, os.Remove("myconfig.toml"))
}()
old := os.Args
os.Args = append(os.Args, "--config", "myconfig.toml")
os.Setenv("TORK_CONFIG", "myconfig.toml")
defer func() {
os.Args = old
os.Unsetenv("TORK_CONFIG")
}()
err = conf.LoadConfig()
assert.Error(t, err)
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ services:
migration:
image: golang:1.19
working_dir: /code
environment:
- TORK_CONFIG=configs/config.compose.toml
command: |
go run cmd/main.go --config configs/config.compose.toml migration
go run cmd/main.go migration
volumes:
- .:/code
depends_on:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/rabbitmq/amqp091-go v1.8.1
github.com/rs/zerolog v1.29.1
github.com/shirou/gopsutil/v3 v3.23.6
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFt
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down

0 comments on commit 435a0e5

Please sign in to comment.