databricks-cli/cmd/labs/feature/all.go

38 lines
718 B
Go
Raw Normal View History

package feature
import (
"context"
"fmt"
"os"
"path/filepath"
)
func LoadAll(ctx context.Context) (features []*Feature, err error) {
home, err := os.UserHomeDir()
if err != nil {
return nil, err
}
labsDir, err := os.ReadDir(filepath.Join(home, ".databricks", "labs"))
2023-08-07 12:36:32 +00:00
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
for _, v := range labsDir {
if !v.IsDir() {
continue
}
feature, err := NewFeature(v.Name())
if err != nil {
return nil, fmt.Errorf("%s: %w", v.Name(), err)
}
2023-08-07 12:36:32 +00:00
err = feature.loadMetadata()
if err != nil {
return nil, fmt.Errorf("%s metadata: %w", v.Name(), err)
}
features = append(features, feature)
}
return features, nil
}