Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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