Skip to content

Commit

Permalink
fix(cli/env): Don't crash if an environment directory is missing spec…
Browse files Browse the repository at this point in the history
….json (#108)

* Don't crash if an environment directory is missing spec.json

* Better handling of missing spec.json file
  • Loading branch information
abh authored and sh0rez committed Nov 17, 2019
1 parent eb64779 commit 9bd15e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/tk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ func envListCmd() *cobra.Command {
}
for _, dir := range dirs {
viper.Reset()
envs = append(envs, *setupConfiguration(dir))
env := setupConfiguration(dir)
if env == nil {
log.Printf("Could not setup configuration from %q", dir)
continue
}
envs = append(envs, *env)
}

if useJSON {
Expand Down
9 changes: 7 additions & 2 deletions cmd/tk/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ func findBaseDirs() (dirs []string) {
}

if err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if _, err := os.Stat(filepath.Join(path, "main.jsonnet")); err == nil {
dirs = append(dirs, path)
requiredFiles := []string{"main.jsonnet", "spec.json"}
for _, name := range requiredFiles {
if _, err := os.Stat(filepath.Join(path, name)); err != nil {
// missing file, not a valid environment directory
return nil
}
}
dirs = append(dirs, path)
return nil
}); err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit 9bd15e6

Please sign in to comment.