Skip to content

Commit

Permalink
Problem: When a cluster command such as migrate or start is called
Browse files Browse the repository at this point in the history
without a proper configuration the current CLI proceeds with an empty
config that yields behavior hard to understand for a newcomer.

Solution: We can be more strict requiring an existing config to run such
commands. This also allows for better error messages guiding the user
during the initial project creation.
  • Loading branch information
diogob committed Jan 14, 2025
1 parent 0ae0163 commit ef710e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var migrateCmd = &cobra.Command{
ctx := context.Background()
orbs := lo.Map(cluster.Config().Orbs, func(cfg orb.OrbCfg, _ int) string { return cfg.Name })
err = migrate(ctx, cluster, dbReset, orbs, orbs)

if err != nil {
log.Fatal(err)
}
},
}

Expand All @@ -41,6 +43,10 @@ func migrate(ctx context.Context, cluster orb.OrbCluster, dbReset bool, orbs []s
err = errors.New("orbs and databases have to be of the same size")
return
}
if len(orbs) == 0 {
err = errors.New("You need at least one configured Orb to migrate")
return
}
logger := log.New(os.Stdout)
logger.SetReportTimestamp(true)
logger.Info("Starting migration...")
Expand Down
9 changes: 2 additions & 7 deletions orb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package orb

import (
"errors"
"fmt"
"github.com/omnigres/cli/internal/fileutils"
"github.com/spf13/viper"
"os"
"path/filepath"
)

Expand Down Expand Up @@ -62,12 +62,7 @@ func LoadConfig(path string) (cfg *Config, err error) {
v.SetConfigFile(filepath.Join(path, "omnigres.yaml"))
err = v.ReadInConfig()
if err != nil {
if _, ok := err.(*os.PathError); ok {
cfg = NewConfig()
err = nil
return
}
return
return nil, fmt.Errorf("omnigres.yaml not found in %s. Try setting a different workspace with -w or running omnigres init to create a new project config.", path)
}

cfg = NewConfig()
Expand Down

0 comments on commit ef710e8

Please sign in to comment.