cli/pkg/workspace/cmd_workspace.go
Snider a0088a34a8 fix(i18n): restore missing translation keys for health command (#65)
* fix(i18n): restore missing translation keys for health command

The locale consolidation in 39de3c2 removed keys still used by
cmd_health.go. Added back:
- cmd.dev.health.* keys (long, repos, to_push, to_pull, etc.)
- common.status.* keys (dirty, clean, synced, up_to_date)
- common.flag.registry

Also fixed workspace.LoadConfig() returning default PackagesDir
when no .core/workspace.yaml exists, which was overriding repo
paths from repos.yaml.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: add nil checks for workspace.LoadConfig callers

LoadConfig now returns nil when no .core/workspace.yaml exists.
Added defensive nil checks to all callers to prevent panics.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: align workspace.LoadConfig error handling

Both call sites now gracefully ignore errors and fall back to defaults,
since workspace config is optional for setup commands.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:55:01 +00:00

87 lines
1.8 KiB
Go

package workspace
import (
"strings"
"github.com/host-uk/core/pkg/cli"
"github.com/spf13/cobra"
)
func AddWorkspaceCommands(root *cobra.Command) {
wsCmd := &cobra.Command{
Use: "workspace",
Short: "Manage workspace configuration",
RunE: runWorkspaceInfo,
}
wsCmd.AddCommand(&cobra.Command{
Use: "active [package]",
Short: "Show or set the active package",
RunE: runWorkspaceActive,
})
root.AddCommand(wsCmd)
}
func runWorkspaceInfo(cmd *cobra.Command, args []string) error {
root, err := FindWorkspaceRoot()
if err != nil {
return cli.Err("not in a workspace")
}
config, err := LoadConfig(root)
if err != nil {
return err
}
if config == nil {
return cli.Err("workspace config not found")
}
cli.Print("Active: %s\n", cli.ValueStyle.Render(config.Active))
cli.Print("Packages: %s\n", cli.DimStyle.Render(config.PackagesDir))
if len(config.DefaultOnly) > 0 {
cli.Print("Types: %s\n", cli.DimStyle.Render(strings.Join(config.DefaultOnly, ", ")))
}
return nil
}
func runWorkspaceActive(cmd *cobra.Command, args []string) error {
root, err := FindWorkspaceRoot()
if err != nil {
return cli.Err("not in a workspace")
}
config, err := LoadConfig(root)
if err != nil {
return err
}
if config == nil {
config = DefaultConfig()
}
// If no args, show active
if len(args) == 0 {
if config.Active == "" {
cli.Println("No active package set")
return nil
}
cli.Text(config.Active)
return nil
}
// Set active
target := args[0]
if target == config.Active {
cli.Print("Active package is already %s\n", cli.ValueStyle.Render(target))
return nil
}
config.Active = target
if err := SaveConfig(root, config); err != nil {
return err
}
cli.Print("Active package set to %s\n", cli.SuccessStyle.Render(target))
return nil
}