Skip to content
Open
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
4 changes: 4 additions & 0 deletions cmd/skpr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import (
"github.com/skpr/cli/cmd/skpr/purge"
"github.com/skpr/cli/cmd/skpr/release"
"github.com/skpr/cli/cmd/skpr/restore"
"github.com/skpr/cli/cmd/skpr/resume"
"github.com/skpr/cli/cmd/skpr/rsync"
"github.com/skpr/cli/cmd/skpr/shell"
"github.com/skpr/cli/cmd/skpr/suspend"
"github.com/skpr/cli/cmd/skpr/trace"
"github.com/skpr/cli/cmd/skpr/validate"
"github.com/skpr/cli/cmd/skpr/version"
Expand Down Expand Up @@ -116,8 +118,10 @@ func main() {
cmd.AddCommand(purge.NewCommand())
cmd.AddCommand(release.NewCommand(featureFlags.DockerClient))
cmd.AddCommand(restore.NewCommand())
cmd.AddCommand(resume.NewCommand())
cmd.AddCommand(rsync.NewCommand())
cmd.AddCommand(shell.NewCommand())
cmd.AddCommand(suspend.NewCommand())
cmd.AddCommand(validate.NewCommand())
cmd.AddCommand(version.NewCommand())

Expand Down
37 changes: 37 additions & 0 deletions cmd/skpr/resume/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package resume

import (
"github.com/spf13/cobra"

skprcommand "github.com/skpr/cli/internal/command"
v1resume "github.com/skpr/cli/internal/command/resume"
)

var (
cmdLong = `Resume an environment.`

cmdExample = `
# Resume the dev environment
skpr resume dev`
)

// NewCommand creates a new cobra.Command for 'resume' sub command
func NewCommand() *cobra.Command {
command := v1resume.Command{}

cmd := &cobra.Command{
Use: "resume <environment>",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
DisableFlagsInUseLine: true,
Short: "Resume an environment.",
Long: cmdLong,
Example: cmdExample,
GroupID: skprcommand.GroupLifecycle,
RunE: func(cmd *cobra.Command, args []string) error {
command.Environment = args[0]
return command.Run(cmd.Context())
},
}

return cmd
}
40 changes: 40 additions & 0 deletions cmd/skpr/suspend/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package suspend

import (
"github.com/spf13/cobra"

skprcommand "github.com/skpr/cli/internal/command"
v1suspend "github.com/skpr/cli/internal/command/suspend"
)

var (
cmdLong = `Suspend an environment.`

cmdExample = `
# Suspend the dev environment
skpr suspend dev`
)

// NewCommand creates a new cobra.Command for 'suspend' sub command
func NewCommand() *cobra.Command {
command := v1suspend.Command{}

cmd := &cobra.Command{
Use: "suspend <environment>",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
DisableFlagsInUseLine: true,
Short: "Suspend an environment.",
Long: cmdLong,
Example: cmdExample,
GroupID: skprcommand.GroupLifecycle,
RunE: func(cmd *cobra.Command, args []string) error {
command.Environment = args[0]
return command.Run(cmd.Context())
},
}

cmd.Flags().BoolVarP(&command.Force, "force", "f", command.Force, "Skpr will not request a confirmation for suspending production environments")
_ = cmd.Flags().MarkHidden("force")

return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/moby/patternmatcher v0.6.1
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0
github.com/pkg/errors v0.9.1
github.com/skpr/api v1.8.5
github.com/skpr/api v1.9.1
github.com/skpr/compass v1.13.3
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.10.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
github.com/skpr/api v1.8.5 h1:7PRQ9UphXUJDzMD3HaTWF1H3SQZ0zRFyv8/x7WRMttc=
github.com/skpr/api v1.8.5/go.mod h1:3ujFy8YadnZ/eEOCoeTnmtIFeVoBu6sQjTLLUKkFVFY=
github.com/skpr/api v1.9.1 h1:QnWQGoMHoADxPJurGJo/FSqbDkPRxh6jBf/7zKsrRzQ=
github.com/skpr/api v1.9.1/go.mod h1:UEv2ZbhO49IPAS9pbLFuVSmNvXrb6aKQZXHfwutxlgA=
github.com/skpr/compass v1.13.3 h1:Ma1zjhgflSBKW5Nw3g/VEFQEfJndscQExSou6sOLuhg=
github.com/skpr/compass v1.13.3/go.mod h1:SM6S6PAku3q2r6L7QGKxu+E5vLA6TEQFZmTYoWapcGQ=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
Expand Down
2 changes: 2 additions & 0 deletions internal/command/list/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func Print(w io.Writer, list []*pb.Environment) error {
"Size",
"Routes",
"Phase",
"Suspended",
}

var rows [][]string
Expand All @@ -60,6 +61,7 @@ func Print(w io.Writer, list []*pb.Environment) error {
item.Size,
strings.Join(append(item.Ingress.Routes, item.Ingress.Domain), "\n"),
color.ApplyColorToString(item.Phase),
fmt.Sprintf("%v", item.Suspended),
})
}

Expand Down
35 changes: 35 additions & 0 deletions internal/command/resume/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package resume

import (
"context"
"fmt"
"os"

"github.com/skpr/api/pb"

"github.com/skpr/cli/internal/client"
)

// Command for resuming cron jobs.
type Command struct {
Environment string
}

// Run the command.
func (cmd *Command) Run(ctx context.Context) error {
ctx, client, err := client.New(ctx)
if err != nil {
return err
}

_, err = client.Environment().Resume(ctx, &pb.EnvironmentResumeRequest{
Name: cmd.Environment,
})
if err != nil {
return err
}

fmt.Fprintln(os.Stderr, "The environment has been resumed.")

return nil
}
50 changes: 50 additions & 0 deletions internal/command/suspend/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package suspend

import (
"context"
"fmt"
"os"

"github.com/skpr/api/pb"

"github.com/skpr/cli/internal/client"
"github.com/skpr/cli/internal/confirmation"
)

// Command to suspend cron jobs.
type Command struct {
Environment string
Force bool
}

// Run the command.
func (cmd *Command) Run(ctx context.Context) error {
ctx, client, err := client.New(ctx)
if err != nil {
return err
}

env, err := client.Environment().Get(ctx, &pb.EnvironmentGetRequest{
Name: cmd.Environment,
})
if err != nil {
return err
}

if env.Environment.Production {
if ok := confirmation.Confirm(cmd.Force, "Are you sure you want to suspend a production environment? [yes/no]"); !ok {
return nil
}
}

_, err = client.Environment().Suspend(ctx, &pb.EnvironmentSuspendRequest{
Name: cmd.Environment,
})
if err != nil {
return err
}

fmt.Fprintln(os.Stderr, "The environment has been suspended.")

return nil
}
Loading