cleanup workspace interface
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
7f456b9131
commit
b393ecc034
@ -9,6 +9,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
var newCmd = &cobra.Command{
|
||||
@ -55,7 +56,10 @@ var newCmd = &cobra.Command{
|
||||
module = p
|
||||
}
|
||||
|
||||
ws, err := workspace.Create(ctx, name, module, viper.GetString("package"))
|
||||
ws, err := workspace.Create(ctx, name, state.CreateOpts{
|
||||
Module: module,
|
||||
Package: viper.GetString("package"),
|
||||
})
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to create environment")
|
||||
}
|
||||
|
@ -229,7 +229,12 @@ func (w *Workspace) Save(ctx context.Context, st *State) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*State, error) {
|
||||
type CreateOpts struct {
|
||||
Module string
|
||||
Package string
|
||||
}
|
||||
|
||||
func (w *Workspace) Create(ctx context.Context, name string, opts CreateOpts) (*State, error) {
|
||||
envPath, err := filepath.Abs(w.envPath(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -247,6 +252,7 @@ func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*Stat
|
||||
|
||||
// Backward compat: if no plan module has been provided,
|
||||
// use `.dagger/env/<name>/plan`
|
||||
module := opts.Module
|
||||
if module == "" {
|
||||
planPath := path.Join(envPath, planDir)
|
||||
if err := os.Mkdir(planPath, 0755); err != nil {
|
||||
@ -265,7 +271,7 @@ func (w *Workspace) Create(ctx context.Context, name, module, pkg string) (*Stat
|
||||
Workspace: w.Path,
|
||||
Plan: Plan{
|
||||
Module: module,
|
||||
Package: pkg,
|
||||
Package: opts.Package,
|
||||
},
|
||||
Name: name,
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func TestWorkspace(t *testing.T) {
|
||||
require.Equal(t, root, workspace.Path)
|
||||
|
||||
// Create
|
||||
st, err := workspace.Create(ctx, "test", "", "")
|
||||
st, err := workspace.Create(ctx, "test", CreateOpts{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "test", st.Name)
|
||||
|
||||
@ -73,7 +73,7 @@ func TestEncryption(t *testing.T) {
|
||||
workspace, err := Init(ctx, root)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = workspace.Create(ctx, "test", "", "")
|
||||
_, err = workspace.Create(ctx, "test", CreateOpts{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Set a plaintext input, make sure it is not encrypted
|
||||
|
Reference in New Issue
Block a user