Skip to content

Commit bfa8d89

Browse files
committed
feat: add hooks & resume space
1 parent 4ecc3a4 commit bfa8d89

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

cmd/resume/resume.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package resume
2+
3+
import (
4+
"github.com/devspace-cloud/devspace-cloud-plugin/pkg/factory"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
// NewResumeCmd creates a new cobra command for the sub command
9+
func NewResumeCmd(f factory.Factory) *cobra.Command {
10+
cmd := &cobra.Command{
11+
Use: "resume",
12+
Short: "Resume spaces",
13+
Long: `
14+
#######################################################
15+
################## devspace resume ####################
16+
#######################################################
17+
`,
18+
Args: cobra.NoArgs,
19+
}
20+
21+
cmd.AddCommand(newSpaceCmd(f))
22+
return cmd
23+
}

cmd/resume/space.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package resume
2+
3+
import (
4+
"github.com/devspace-cloud/devspace-cloud-plugin/pkg/factory"
5+
"github.com/pkg/errors"
6+
"os"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
type spaceCmd struct{}
12+
13+
func newSpaceCmd(f factory.Factory) *cobra.Command {
14+
cmd := &spaceCmd{}
15+
16+
return &cobra.Command{
17+
Use: "space",
18+
Short: "Prints the current space",
19+
Args: cobra.NoArgs,
20+
RunE: func(cobraCmd *cobra.Command, args []string) error {
21+
return cmd.Run(f, cobraCmd, args)
22+
},
23+
}
24+
}
25+
26+
// Run executes the command logic
27+
func (*spaceCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
28+
// Get kubectl client
29+
client, err := f.NewKubeClientFromContext(os.Getenv("DEVSPACE_PLUGIN_KUBE_CONTEXT_FLAG"), os.Getenv("DEVSPACE_PLUGIN_KUBE_NAMESPACE_FLAG"), false)
30+
if err != nil {
31+
return errors.Wrap(err, "new kube client")
32+
}
33+
34+
// Signal that we are working on the space if there is any
35+
return f.NewSpaceResumer(client, f.GetLog()).ResumeSpace(true)
36+
}

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/list"
99
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/remove"
1010
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/reset"
11+
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/resume"
1112
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/set"
1213
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/use"
1314
"github.com/devspace-cloud/devspace-cloud-plugin/cmd/vars"
@@ -103,6 +104,7 @@ func BuildRoot(f factory.Factory) *cobra.Command {
103104
rootCmd.AddCommand(reset.NewResetCmd(f))
104105
rootCmd.AddCommand(set.NewSetCmd(f))
105106
rootCmd.AddCommand(vars.NewVarsCmd(f))
107+
rootCmd.AddCommand(resume.NewResumeCmd(f))
106108

107109
// Add base commands
108110
rootCmd.AddCommand(NewLoginCmd(f))

plugin.yaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ commands:
4040
- name: "space"
4141
baseArgs: ["use", "space"]
4242
subCommand: "use"
43+
hooks:
44+
- event: analyze
45+
baseArgs: ["resume", "space"]
46+
- event: attach
47+
baseArgs: ["resume", "space"]
48+
- event: deploy
49+
baseArgs: ["resume", "space"]
50+
- event: dev
51+
baseArgs: ["resume", "space"]
52+
- event: enter
53+
baseArgs: ["resume", "space"]
54+
- event: logs
55+
baseArgs: ["resume", "space"]
56+
- event: open
57+
baseArgs: ["resume", "space"]
58+
- event: purge
59+
baseArgs: ["resume", "space"]
60+
- event: sync
61+
baseArgs: ["resume", "space"]
4362
vars:
4463
- name: DEVSPACE_SPACE
4564
baseArgs: ["vars", "space"]
@@ -50,16 +69,16 @@ vars:
5069
binaries:
5170
- os: darwin
5271
arch: amd64
53-
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-darwin-amd64
72+
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-cloud-plugin-darwin-amd64
5473
- os: linux
5574
arch: amd64
56-
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-linux-amd64
75+
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-cloud-plugin-linux-amd64
5776
- os: linux
5877
arch: 386
59-
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-linux-386
78+
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-cloud-plugin-linux-386
6079
- os: windows
6180
arch: amd64
62-
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-windows-amd64.exe
81+
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-cloud-plugin-windows-amd64.exe
6382
- os: windows
6483
arch: 386
65-
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-windows-386.exe
84+
path: https://github.com/devspace-cloud/devspace-cloud-plugin/releases/download/v0.0.1/devspace-cloud-plugin-windows-386.exe

0 commit comments

Comments
 (0)