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/build_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ Examples:
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

var buildID string
if buildIdNewFlag {
buildID, err = execCtx.GenerateBuildID()
buildID, err = rt.GenerateBuildID()
} else {
buildID, err = execCtx.GetBuildID()
buildID, err = rt.GetBuildID()
}
if err != nil {
return fmt.Errorf("failed to manage build ID: %w", err)
Expand Down
17 changes: 8 additions & 9 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/composer"
"github.com/windsorcli/cli/pkg/composer/artifact"
"github.com/windsorcli/cli/pkg/runtime"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/runtime"
)

// bundleCmd represents the bundle command
Expand Down Expand Up @@ -35,26 +35,25 @@ Examples:
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

composerCtx := &composer.ComposerRuntime{
Runtime: *execCtx,
}

var override *composer.Composer
if existingArtifactBuilder := injector.Resolve("artifactBuilder"); existingArtifactBuilder != nil {
if artifactBuilder, ok := existingArtifactBuilder.(artifact.Artifact); ok {
composerCtx.ArtifactBuilder = artifactBuilder
override = &composer.Composer{
ArtifactBuilder: artifactBuilder,
}
}
}

comp := composer.NewComposer(composerCtx)
comp := composer.NewComposer(rt, override)

tag, _ := cmd.Flags().GetString("tag")
outputPath, _ := cmd.Flags().GetString("output")
Expand Down
24 changes: 12 additions & 12 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ var checkCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
if err := rt.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.ConfigHandler.LoadConfig(); err != nil {
if err := rt.ConfigHandler.LoadConfig(); err != nil {
return err
}

if !execCtx.ConfigHandler.IsLoaded() {
if !rt.ConfigHandler.IsLoaded() {
return fmt.Errorf("Nothing to check. Have you run \033[1mwindsor init\033[0m?")
}

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

Expand All @@ -72,29 +72,29 @@ var checkNodeHealthCmd = &cobra.Command{
nodeHealthTimeout = constants.DefaultNodeHealthCheckTimeout
}

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
if err := rt.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.ConfigHandler.LoadConfig(); err != nil {
if err := rt.ConfigHandler.LoadConfig(); err != nil {
return err
}

if !execCtx.ConfigHandler.IsLoaded() {
if !rt.ConfigHandler.IsLoaded() {
return fmt.Errorf("Nothing to check. Have you run \033[1mwindsor init\033[0m?")
}

provisionerCtx := &provisioner.ProvisionerRuntime{
Runtime: *execCtx,
Runtime: *rt,
}

prov := provisioner.NewProvisioner(provisionerCtx)
Expand Down
18 changes: 9 additions & 9 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ var getContextCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

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

contextName := execCtx.ConfigHandler.GetContext()
contextName := rt.ConfigHandler.GetContext()
fmt.Fprintln(cmd.OutOrStdout(), contextName)

return nil
Expand All @@ -47,24 +47,24 @@ var setContextCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

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

if _, err := execCtx.Shell.WriteResetToken(); err != nil {
if _, err := rt.Shell.WriteResetToken(); err != nil {
return fmt.Errorf("failed to write reset token: %w", err)
}

if err := execCtx.ConfigHandler.SetContext(args[0]); err != nil {
if err := rt.ConfigHandler.SetContext(args[0]); err != nil {
return fmt.Errorf("failed to set context: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var downCmd = &cobra.Command{
return err
}

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

Expand Down
24 changes: 12 additions & 12 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ var envCmd = &cobra.Command{

injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
if err := rt.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 {
if err := rt.HandleSessionReset(); err != nil {
return err
}

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

if err := execCtx.LoadEnvironment(decrypt); err != nil {
if err := rt.LoadEnvironment(decrypt); err != nil {
if hook || !verbose {
return nil
}
Expand All @@ -62,15 +62,15 @@ var envCmd = &cobra.Command{
}

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

Expand Down
16 changes: 8 additions & 8 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@ var execCmd = &cobra.Command{

injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.Shell.CheckTrustedDirectory(); err != nil {
if err := rt.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 {
if err := rt.HandleSessionReset(); err != nil {
return err
}

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

if err := execCtx.LoadEnvironment(true); err != nil {
if err := rt.LoadEnvironment(true); err != nil {
if !verbose {
return nil
}
return fmt.Errorf("failed to load environment: %w", err)
}

for key, value := range execCtx.GetEnvVars() {
for key, value := range rt.GetEnvVars() {
if err := os.Setenv(key, value); err != nil {
return fmt.Errorf("failed to set environment variable %s: %w", key, err)
}
Expand All @@ -65,7 +65,7 @@ var execCmd = &cobra.Command{
commandArgs = args[1:]
}

if _, err := execCtx.Shell.Exec(command, commandArgs...); err != nil {
if _, err := rt.Shell.Exec(command, commandArgs...); err != nil {
return fmt.Errorf("failed to execute command: %w", err)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ var hookCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

execCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

execCtx, err := runtime.NewRuntime(execCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := execCtx.Shell.InstallHook(args[0]); err != nil {
if err := rt.Shell.InstallHook(args[0]); err != nil {
return fmt.Errorf("error installing hook: %w", err)
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/runtime"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/project"
"github.com/windsorcli/cli/pkg/runtime"
)

// =============================================================================
Expand Down Expand Up @@ -43,24 +43,24 @@ var initCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
injector := cmd.Context().Value(injectorKey).(di.Injector)

baseCtx := &runtime.Runtime{
rt := &runtime.Runtime{
Injector: injector,
}

baseCtx, err := runtime.NewRuntime(baseCtx)
rt, err := runtime.NewRuntime(rt)
if err != nil {
return fmt.Errorf("failed to initialize context: %w", err)
}

if err := baseCtx.Shell.AddCurrentDirToTrustedFile(); err != nil {
if err := rt.Shell.AddCurrentDirToTrustedFile(); err != nil {
return fmt.Errorf("failed to add current directory to trusted file: %w", err)
}

contextName := "local"
if len(args) > 0 {
contextName = args[0]
} else {
currentContext := baseCtx.ConfigHandler.GetContext()
currentContext := rt.ConfigHandler.GetContext()
if currentContext != "" && currentContext != "local" {
contextName = currentContext
}
Expand Down Expand Up @@ -114,7 +114,7 @@ var initCmd = &cobra.Command{
}
}

proj, err := project.NewProject(injector, contextName, baseCtx)
proj, err := project.NewProject(injector, contextName, rt)
if err != nil {
return err
}
Expand All @@ -131,7 +131,7 @@ var initCmd = &cobra.Command{
}

hasSetFlags := len(initSetFlags) > 0
if err := proj.Context.ConfigHandler.SaveConfig(hasSetFlags); err != nil {
if err := proj.Runtime.ConfigHandler.SaveConfig(hasSetFlags); err != nil {
return fmt.Errorf("failed to save configuration: %w", err)
}

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

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

Expand Down
Loading
Loading