cli/pkg/repos/workspace.go
Snider 10277c6094 fix(docs): respect workspace.yaml packages_dir setting (fixes #46) (#55)
* fix(docs): respect workspace.yaml packages_dir setting (fixes #46)

* fix(workspace): improve config loading logic (CR feedback)

- Expand ~ before resolving relative paths in cmd_registry
- Handle LoadWorkspaceConfig errors properly
- Update Repo.Path when PackagesDir overrides default
- Validate workspace config version
- Add unit tests for workspace config loading

* docs: add comments and increase test coverage (CR feedback)

- Add docstrings to exported functions in pkg/cli
- Add unit tests for Semantic Output (pkg/cli/output.go)
- Add unit tests for CheckBuilder (pkg/cli/check.go)
- Add unit tests for IPC Query/Perform (pkg/framework/core)

* fix(test): fix panics and failures in php package tests

- Fix panic in TestLookupLinuxKit_Bad by mocking paths
- Fix assertion errors in TestGetSSLDir_Bad and TestGetPackageInfo_Bad
- Fix formatting in test files

* fix(test): correct syntax in services_extended_test.go

* fix(ci): point coverage workflow to go.mod instead of go.work

* fix(ci): build CLI before running coverage

* fix(ci): run go generate for updater package in coverage workflow

* fix(github): allow dry-run publish without gh CLI authentication

Moves validation check after dry-run check so tests can verify dry-run behavior in CI environments.
2026-02-01 01:59:27 +00:00

47 lines
1.2 KiB
Go

package repos
import (
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
// WorkspaceConfig holds workspace-level configuration.
type WorkspaceConfig struct {
Version int `yaml:"version"`
Active string `yaml:"active"`
PackagesDir string `yaml:"packages_dir"`
}
// DefaultWorkspaceConfig returns a config with default values.
func DefaultWorkspaceConfig() *WorkspaceConfig {
return &WorkspaceConfig{
Version: 1,
PackagesDir: "./packages",
}
}
// LoadWorkspaceConfig tries to load workspace.yaml from the given directory's .core subfolder.
func LoadWorkspaceConfig(dir string) (*WorkspaceConfig, error) {
path := filepath.Join(dir, ".core", "workspace.yaml")
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return DefaultWorkspaceConfig(), nil
}
return nil, fmt.Errorf("failed to read workspace config: %w", err)
}
config := DefaultWorkspaceConfig()
if err := yaml.Unmarshal(data, config); err != nil {
return nil, fmt.Errorf("failed to parse workspace config: %w", err)
}
if config.Version != 1 {
return nil, fmt.Errorf("unsupported workspace config version: %d", config.Version)
}
return config, nil
}