Skip to content
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
8 changes: 4 additions & 4 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ var checkCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.CheckTrustedDirectory(); err != nil {
if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
return fmt.Errorf("not in a trusted directory. If you are in a Windsor project, run 'windsor init' to approve")
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return err
}

Expand Down Expand Up @@ -81,11 +81,11 @@ var checkNodeHealthCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.CheckTrustedDirectory(); err != nil {
if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
return fmt.Errorf("not in a trusted directory. If you are in a Windsor project, run 'windsor init' to approve")
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var getContextCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return fmt.Errorf("failed to load config: %w", err)
}

Expand Down Expand Up @@ -56,7 +56,7 @@ var setContextCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return fmt.Errorf("failed to load config: %w", err)
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ var downCmd = &cobra.Command{
}

if !skipK8sFlag {
blueprint := proj.Composer.BlueprintHandler.Generate()
blueprint, err := proj.Composer.GenerateBlueprint()
if err != nil {
return fmt.Errorf("error generating blueprint: %w", err)
}
if err := proj.Provisioner.Uninstall(blueprint); err != nil {
return fmt.Errorf("error running blueprint cleanup: %w", err)
}
Expand All @@ -54,7 +57,10 @@ var downCmd = &cobra.Command{
}

if !skipTerraformFlag {
blueprint := proj.Composer.BlueprintHandler.Generate()
blueprint, err := proj.Composer.GenerateBlueprint()
if err != nil {
return fmt.Errorf("error generating blueprint: %w", err)
}
if err := proj.Provisioner.Down(blueprint); err != nil {
return fmt.Errorf("error tearing down infrastructure: %w", err)
}
Expand Down
16 changes: 11 additions & 5 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var envCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.CheckTrustedDirectory(); err != nil {
if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
return fmt.Errorf("not in a trusted directory. If you are in a Windsor project, run 'windsor init' to approve")
}

if err := execCtx.HandleSessionReset(); err != nil {
return err
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return err
}

Expand All @@ -62,10 +62,16 @@ var envCmd = &cobra.Command{
}

if hook {
outputFunc(execCtx.PrintEnvVarsExport())
outputFunc(execCtx.PrintAliases())
if execCtx.Shell != nil && len(execCtx.GetEnvVars()) > 0 {
outputFunc(execCtx.Shell.RenderEnvVars(execCtx.GetEnvVars(), true))
}
if execCtx.Shell != nil && len(execCtx.GetAliases()) > 0 {
outputFunc(execCtx.Shell.RenderAliases(execCtx.GetAliases()))
}
} else {
outputFunc(execCtx.PrintEnvVars())
if execCtx.Shell != nil && len(execCtx.GetEnvVars()) > 0 {
outputFunc(execCtx.Shell.RenderEnvVars(execCtx.GetEnvVars(), false))
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ var execCmd = &cobra.Command{
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.CheckTrustedDirectory(); err != nil {
if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
return fmt.Errorf("not in a trusted directory. If you are in a Windsor project, run 'windsor init' to approve")
}

if err := execCtx.HandleSessionReset(); err != nil {
return err
}

if err := execCtx.LoadConfig(); err != nil {
if err := execCtx.ConfigHandler.LoadConfig(); err != nil {
return err
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ var installCmd = &cobra.Command{
return err
}

blueprint := proj.Composer.BlueprintHandler.Generate()
blueprint, err := proj.Composer.GenerateBlueprint()
if err != nil {
return fmt.Errorf("error generating blueprint: %w", err)
}
if err := proj.Provisioner.Install(blueprint); err != nil {
return fmt.Errorf("error installing blueprint: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ var upCmd = &cobra.Command{
}
}

blueprint := proj.Composer.BlueprintHandler.Generate()
blueprint, err := proj.Composer.GenerateBlueprint()
if err != nil {
return fmt.Errorf("error generating blueprint: %w", err)
}
if err := proj.Provisioner.Up(blueprint); err != nil {
return fmt.Errorf("error starting infrastructure: %w", err)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"

blueprintv1alpha1 "github.com/windsorcli/cli/api/v1alpha1"
"github.com/windsorcli/cli/pkg/composer/artifact"
"github.com/windsorcli/cli/pkg/composer/blueprint"
"github.com/windsorcli/cli/pkg/composer/terraform"
Expand Down Expand Up @@ -159,6 +160,19 @@ func (r *Composer) Generate(overwrite ...bool) error {
return nil
}

// GenerateBlueprint generates and returns the blueprint from the blueprint handler.
// It initializes the blueprint handler if needed and loads the blueprint data before generating.
// Returns the generated blueprint or an error if initialization or loading fails.
func (r *Composer) GenerateBlueprint() (*blueprintv1alpha1.Blueprint, error) {
if err := r.BlueprintHandler.Initialize(); err != nil {
return nil, fmt.Errorf("failed to initialize blueprint handler: %w", err)
}
if err := r.BlueprintHandler.LoadBlueprint(); err != nil {
return nil, fmt.Errorf("failed to load blueprint data: %w", err)
}
return r.BlueprintHandler.Generate(), nil
}

// =============================================================================
// Private Methods
// =============================================================================
Expand Down
15 changes: 0 additions & 15 deletions pkg/composer/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,6 @@ func TestCreateComposer(t *testing.T) {
// Test Public Methods
// =============================================================================

func TestComposer_Bundle(t *testing.T) {
t.Run("HandlesBundleSuccessfully", func(t *testing.T) {
mocks := setupComposerMocks(t)
composer := NewComposer(mocks.ComposerRuntime)

// This test would need proper mocking of the artifact builder
// For now, we'll just test that the method exists and handles errors
_, err := composer.Bundle("/test/output", "v1.0.0")
// We expect an error here because we don't have proper mocks set up
if err == nil {
t.Error("Expected error due to missing mocks, but got nil")
}
})
}

func TestComposer_Push(t *testing.T) {
t.Run("HandlesPushSuccessfully", func(t *testing.T) {
mocks := setupComposerMocks(t)
Expand Down
48 changes: 0 additions & 48 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,6 @@ func NewRuntime(ctx *Runtime) (*Runtime, error) {
// Public Methods
// =============================================================================

// CheckTrustedDirectory verifies that the current directory is in the trusted file list.
// It delegates to the Shell's CheckTrustedDirectory method. Returns an error if the
// directory is not trusted or if Shell is not initialized.
func (ctx *Runtime) CheckTrustedDirectory() error {
if ctx.Shell == nil {
return fmt.Errorf("shell not initialized")
}
return ctx.Shell.CheckTrustedDirectory()
}

// LoadConfig loads configuration from all sources.
// The context paths (ContextName, ProjectRoot, ConfigRoot, TemplateRoot) are already
// set up in the constructor, so this method only needs to load the configuration data.
// Returns an error if configuration loading fails or if required dependencies are missing.
func (ctx *Runtime) LoadConfig() error {
if ctx.ConfigHandler == nil {
return fmt.Errorf("config handler not initialized")
}

return ctx.ConfigHandler.LoadConfig()
}

// HandleSessionReset checks for reset flags and session tokens, then resets managed environment
// variables if needed. It checks for WINDSOR_SESSION_TOKEN and uses the shell's CheckResetFlags
// method to determine if a reset should occur. If reset is needed, it calls Shell.Reset() and
Expand Down Expand Up @@ -281,32 +259,6 @@ func (ctx *Runtime) LoadEnvironment(decrypt bool) error {
return nil
}

// PrintEnvVars returns all collected environment variables in key=value format.
// If no environment variables are loaded, returns an empty string.
func (ctx *Runtime) PrintEnvVars() string {
if ctx.Shell == nil || len(ctx.envVars) == 0 {
return ""
}
return ctx.Shell.RenderEnvVars(ctx.envVars, false)
}

// PrintEnvVarsExport returns all collected environment variables in export key=value format.
// If no environment variables are loaded, returns an empty string.
func (ctx *Runtime) PrintEnvVarsExport() string {
if ctx.Shell == nil || len(ctx.envVars) == 0 {
return ""
}
return ctx.Shell.RenderEnvVars(ctx.envVars, true)
}

// PrintAliases returns all collected aliases using the shell's RenderAliases method.
// If no aliases are loaded, returns an empty string.
func (ctx *Runtime) PrintAliases() string {
if ctx.Shell == nil || len(ctx.aliases) == 0 {
return ""
}
return ctx.Shell.RenderAliases(ctx.aliases)
}

// GetEnvVars returns a copy of the collected environment variables.
func (ctx *Runtime) GetEnvVars() map[string]string {
Expand Down
Loading
Loading