Skip to content

Commit d9c3c1e

Browse files
committed
client/cordium - add var to startWorkspacereq in run cmd on subsequent runs
1 parent 8113794 commit d9c3c1e

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

client/cordium/commands/ccommon/ccommon.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package ccommon
1919
import (
2020
"strings"
2121

22+
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2223
"github.com/octelium/octelium/apis/main/metav1"
2324
"github.com/octelium/octelium/pkg/apiutils/umetav1"
25+
"github.com/pkg/errors"
2426
)
2527

2628
func GetResourceShortName(rsc umetav1.ResourceObjectI) string {
@@ -45,3 +47,18 @@ func doGetShortName(arg string) string {
4547
}
4648
return strings.Split(arg, ".")[0]
4749
}
50+
51+
func ParseVars(raw []string) ([]*pb.Workspace_Spec_Var, error) {
52+
vars := make([]*pb.Workspace_Spec_Var, 0, len(raw))
53+
for _, s := range raw {
54+
name, value, ok := strings.Cut(s, "=")
55+
if !ok || name == "" {
56+
return nil, errors.Errorf("invalid --var value %q: expected NAME=VALUE", s)
57+
}
58+
vars = append(vars, &pb.Workspace_Spec_Var{
59+
Name: name,
60+
Value: value,
61+
})
62+
}
63+
return vars, nil
64+
}

client/cordium/commands/run/cmd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"time"
2424

25+
"github.com/octelium/cordium/client/cordium/commands/ccommon"
2526
"github.com/octelium/cordium/client/cordium/commands/create/workspace"
2627
"github.com/octelium/cordium/client/cordium/commands/terminal"
2728
"github.com/octelium/cordium/pkg/apiutils/ucordiumv1"
@@ -265,6 +266,18 @@ func doRun(ctx context.Context, conn *grpc.ClientConn, ws *pb.Workspace) error {
265266
case ucordiumv1.ToWorkspace(ws).IsStopped():
266267
if _, err := c.StartWorkspace(ctx, &pb.StartWorkspaceRequest{
267268
WorkspaceRef: umetav1.GetObjectReference(ws),
269+
Config: func() *pb.StartWorkspaceRequest_Config {
270+
if len(ws.Status.LastRuns) > 0 && len(cmdArgs.Vars) > 0 {
271+
272+
if vars, err := ccommon.ParseVars(cmdArgs.Vars); err == nil {
273+
return &pb.StartWorkspaceRequest_Config{
274+
Vars: vars,
275+
}
276+
}
277+
}
278+
279+
return nil
280+
}(),
268281
}); err != nil {
269282
if !grpcerr.AlreadyExists(err) {
270283
return err

client/cordium/commands/start/cmd.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package start
1818

1919
import (
20-
"strings"
21-
20+
"github.com/octelium/cordium/client/cordium/commands/ccommon"
2221
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2322
"github.com/octelium/octelium/apis/main/metav1"
2423
"github.com/octelium/octelium/client/common/client"
2524
"github.com/octelium/octelium/client/common/cliutils"
26-
"github.com/pkg/errors"
2725
"github.com/spf13/cobra"
2826
)
2927

@@ -84,7 +82,7 @@ func doCmd(cmd *cobra.Command, args []string) error {
8482
}
8583

8684
if len(cmdArgs.Vars) > 0 {
87-
vars, err := parseVars(cmdArgs.Vars)
85+
vars, err := ccommon.ParseVars(cmdArgs.Vars)
8886
if err != nil {
8987
return err
9088
}
@@ -101,18 +99,3 @@ func doCmd(cmd *cobra.Command, args []string) error {
10199

102100
return nil
103101
}
104-
105-
func parseVars(raw []string) ([]*pb.Workspace_Spec_Var, error) {
106-
vars := make([]*pb.Workspace_Spec_Var, 0, len(raw))
107-
for _, s := range raw {
108-
name, value, ok := strings.Cut(s, "=")
109-
if !ok || name == "" {
110-
return nil, errors.Errorf("invalid --var value %q: expected NAME=VALUE", s)
111-
}
112-
vars = append(vars, &pb.Workspace_Spec_Var{
113-
Name: name,
114-
Value: value,
115-
})
116-
}
117-
return vars, nil
118-
}

0 commit comments

Comments
 (0)