diff --git a/go.mod b/go.mod index 221674a..04bb899 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16 require ( bunnyshell.com/dev v0.5.5 - bunnyshell.com/sdk v0.14.2 + bunnyshell.com/sdk v0.15.0 github.com/AlecAivazis/survey/v2 v2.3.7 github.com/briandowns/spinner v1.23.0 github.com/fatih/color v1.15.0 diff --git a/go.sum b/go.sum index cb707db..2d72999 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ bunnyshell.com/dev v0.5.5 h1:dqFr6ZTPWvfqtgQGDPzHDfG0hNvNMZDqXAKS2+ekFzY= bunnyshell.com/dev v0.5.5/go.mod h1:KlqPdOh60vqAfnuGUw9AKc0RVhXpNzWg46QKJSP/jog= bunnyshell.com/sdk v0.14.2 h1:x6V1w+JioFu0jbkRYTCsz0A4mqg9LuSOHlawaFfZBao= bunnyshell.com/sdk v0.14.2/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138= +bunnyshell.com/sdk v0.15.0 h1:zPL1OCPTrVs97Muisyz8JoqiN3XqPsE6GLkc5u7cV3k= +bunnyshell.com/sdk v0.15.0/go.mod h1:RfgfUzZ4WHZGCkToUfu2/hoQS6XsQc8IdPTVAlpS138= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= diff --git a/pkg/api/common/partial_action.go b/pkg/api/common/partial_action.go new file mode 100644 index 0000000..1ea34dd --- /dev/null +++ b/pkg/api/common/partial_action.go @@ -0,0 +1,52 @@ +package common + +import ( + "fmt" + + "github.com/spf13/pflag" +) + +const componentVarName = "component" + +type PartialActionOptions struct { + ActionOptions + + components []string + + flags *pflag.FlagSet +} + +func NewPartialActionOptions(id string) *PartialActionOptions { + return &PartialActionOptions{ + ActionOptions: *NewActionOptions(id), + + components: []string{}, + } +} + +func (pao *PartialActionOptions) UpdateFlagSet(flags *pflag.FlagSet) { + pao.ActionOptions.UpdateFlagSet(flags) + + // We'll need this later to check if the flag was provided at all - in order to determine if it was a partial action or not. + pao.flags = flags + + usage := fmt.Sprintf("Execute a partial action with the set components. Provide \"--%s ''\" for a no-components operation.", componentVarName) + flags.StringArrayVar(&pao.components, componentVarName, pao.components, usage) +} + +// Handle the "--component ”" case. +func (pao *PartialActionOptions) GetActionComponents() []string { + if len(pao.components) == 1 && pao.components[0] == "" { + return []string{} + } + + return pao.components +} + +func (pao *PartialActionOptions) IsPartial() bool { + if pao.flags == nil { + return false + } + + return pao.flags.Lookup(componentVarName).Changed +} diff --git a/pkg/api/environment/action_deploy.go b/pkg/api/environment/action_deploy.go index 025db64..f29fc8d 100644 --- a/pkg/api/environment/action_deploy.go +++ b/pkg/api/environment/action_deploy.go @@ -7,18 +7,34 @@ import ( "bunnyshell.com/cli/pkg/api/common" "bunnyshell.com/cli/pkg/lib" "bunnyshell.com/sdk" + "github.com/spf13/pflag" +) + +const ( + IncludedDepdendenciesNone string = "none" + IncludedDepdendenciesAll string = "all" + IncludedDepdendenciesMissing string = "missing" ) type DeployOptions struct { - common.ActionOptions + common.PartialActionOptions + + IncludedDepdendencies string } func NewDeployOptions(id string) *DeployOptions { return &DeployOptions{ - ActionOptions: *common.NewActionOptions(id), + PartialActionOptions: *common.NewPartialActionOptions(id), + IncludedDepdendencies: IncludedDepdendenciesNone, } } +func (options *DeployOptions) UpdateFlagSet(flags *pflag.FlagSet) { + options.PartialActionOptions.UpdateFlagSet(flags) + + flags.StringVar(&options.IncludedDepdendencies, "included-dependencies", options.IncludedDepdendencies, "Include dependencies in the deployment (none, all, missing)") +} + func Deploy(options *DeployOptions) (*sdk.EventItem, error) { model, resp, err := DeployRaw(options) if err != nil { @@ -34,7 +50,14 @@ func DeployRaw(options *DeployOptions) (*sdk.EventItem, *http.Response, error) { ctx, cancel := lib.GetContextFromProfile(profile) defer cancel() - request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentDeploy(ctx, options.ID) + isPartialAction := options.IsPartial() + + request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentDeploy(ctx, options.ID). + EnvironmentPartialDeployAction(sdk.EnvironmentPartialDeployAction{ + IsPartial: &isPartialAction, + Components: options.GetActionComponents(), + IncludedDependencies: &options.IncludedDepdendencies, + }) return request.Execute() } diff --git a/pkg/api/environment/action_start.go b/pkg/api/environment/action_start.go index bd0370e..7e5b06f 100644 --- a/pkg/api/environment/action_start.go +++ b/pkg/api/environment/action_start.go @@ -7,18 +7,27 @@ import ( "bunnyshell.com/cli/pkg/api/common" "bunnyshell.com/cli/pkg/lib" "bunnyshell.com/sdk" + "github.com/spf13/pflag" ) type StartOptions struct { - common.ActionOptions + common.PartialActionOptions + + WithDependencies bool } func NewStartOptions(id string) *StartOptions { return &StartOptions{ - ActionOptions: *common.NewActionOptions(id), + PartialActionOptions: *common.NewPartialActionOptions(id), } } +func (options *StartOptions) UpdateFlagSet(flags *pflag.FlagSet) { + options.PartialActionOptions.UpdateFlagSet(flags) + + flags.BoolVar(&options.WithDependencies, "with-dependencies", options.WithDependencies, "Start the component dependencies too.") +} + func Start(options *StartOptions) (*sdk.EventItem, error) { model, resp, err := StartRaw(options) if err != nil { @@ -34,7 +43,14 @@ func StartRaw(options *StartOptions) (*sdk.EventItem, *http.Response, error) { ctx, cancel := lib.GetContextFromProfile(profile) defer cancel() - request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentStart(ctx, options.ID) + isPartialAction := options.IsPartial() + + request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentStart(ctx, options.ID). + EnvironmentPartialStartAction(sdk.EnvironmentPartialStartAction{ + IsPartial: &isPartialAction, + Components: options.GetActionComponents(), + WithDependencies: &options.WithDependencies, + }) return request.Execute() } diff --git a/pkg/api/environment/action_stop.go b/pkg/api/environment/action_stop.go index 3d52ddf..a6823dc 100644 --- a/pkg/api/environment/action_stop.go +++ b/pkg/api/environment/action_stop.go @@ -10,12 +10,12 @@ import ( ) type StopOptions struct { - common.ActionOptions + common.PartialActionOptions } func NewStopOptions(id string) *StopOptions { return &StopOptions{ - ActionOptions: *common.NewActionOptions(id), + PartialActionOptions: *common.NewPartialActionOptions(id), } } @@ -34,7 +34,13 @@ func StopRaw(options *StopOptions) (*sdk.EventItem, *http.Response, error) { ctx, cancel := lib.GetContextFromProfile(profile) defer cancel() - request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentStop(ctx, options.ID) + isPartialAction := options.IsPartial() + + request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentStop(ctx, options.ID). + EnvironmentPartialAction(sdk.EnvironmentPartialAction{ + IsPartial: &isPartialAction, + Components: options.GetActionComponents(), + }) return request.Execute() }