plan: default cue module to .
Fixes #699 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
696b8a4d4c
commit
919d5576d0
@ -37,7 +37,9 @@ var newCmd = &cobra.Command{
|
|||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
module := viper.GetString("module")
|
module := viper.GetString("module")
|
||||||
if module != "" {
|
if module == "" {
|
||||||
|
lg.Fatal().Msg("missing --module")
|
||||||
|
}
|
||||||
p, err := filepath.Abs(module)
|
p, err := filepath.Abs(module)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Str("path", module).Msg("unable to resolve path")
|
lg.Fatal().Err(err).Str("path", module).Msg("unable to resolve path")
|
||||||
@ -54,9 +56,8 @@ var newCmd = &cobra.Command{
|
|||||||
p = "./" + p
|
p = "./" + p
|
||||||
}
|
}
|
||||||
module = p
|
module = p
|
||||||
}
|
|
||||||
|
|
||||||
ws, err := workspace.Create(ctx, name, state.CreateOpts{
|
ws, err := workspace.Create(ctx, name, state.Plan{
|
||||||
Module: module,
|
Module: module,
|
||||||
Package: viper.GetString("package"),
|
Package: viper.GetString("package"),
|
||||||
})
|
})
|
||||||
@ -70,7 +71,7 @@ var newCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
newCmd.Flags().StringP("module", "m", "", "references the local path of the cue module to use as a plan, relative to the workspace root")
|
newCmd.Flags().StringP("module", "m", ".", "references the local path of the cue module to use as a plan, relative to the workspace root")
|
||||||
newCmd.Flags().StringP("package", "p", "", "references the name of the Cue package within the module to use as a plan. Default: defer to cue loader")
|
newCmd.Flags().StringP("package", "p", "", "references the name of the Cue package within the module to use as a plan. Default: defer to cue loader")
|
||||||
if err := viper.BindPFlags(newCmd.Flags()); err != nil {
|
if err := viper.BindPFlags(newCmd.Flags()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -229,17 +229,16 @@ func (w *Workspace) Save(ctx context.Context, st *State) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateOpts struct {
|
func (w *Workspace) Create(ctx context.Context, name string, plan Plan) (*State, error) {
|
||||||
Module string
|
|
||||||
Package string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Workspace) Create(ctx context.Context, name string, opts CreateOpts) (*State, error) {
|
|
||||||
envPath, err := filepath.Abs(w.envPath(name))
|
envPath, err := filepath.Abs(w.envPath(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(plan.Module); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Environment directory
|
// Environment directory
|
||||||
if err := os.MkdirAll(envPath, 0755); err != nil {
|
if err := os.MkdirAll(envPath, 0755); err != nil {
|
||||||
if errors.Is(err, os.ErrExist) {
|
if errors.Is(err, os.ErrExist) {
|
||||||
@ -250,29 +249,10 @@ func (w *Workspace) Create(ctx context.Context, name string, opts CreateOpts) (*
|
|||||||
|
|
||||||
manifestPath := path.Join(envPath, manifestFile)
|
manifestPath := path.Join(envPath, manifestFile)
|
||||||
|
|
||||||
// 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 {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
planRelPath, err := filepath.Rel(w.Path, planPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
module = planRelPath
|
|
||||||
}
|
|
||||||
|
|
||||||
st := &State{
|
st := &State{
|
||||||
Path: envPath,
|
Path: envPath,
|
||||||
Workspace: w.Path,
|
Workspace: w.Path,
|
||||||
Plan: Plan{
|
Plan: plan,
|
||||||
Module: module,
|
|
||||||
Package: opts.Package,
|
|
||||||
},
|
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,9 @@ func TestWorkspace(t *testing.T) {
|
|||||||
require.Equal(t, root, workspace.Path)
|
require.Equal(t, root, workspace.Path)
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
st, err := workspace.Create(ctx, "test", CreateOpts{})
|
st, err := workspace.Create(ctx, "test", Plan{
|
||||||
|
Module: ".",
|
||||||
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "test", st.Name)
|
require.Equal(t, "test", st.Name)
|
||||||
|
|
||||||
@ -78,7 +80,9 @@ func TestEncryption(t *testing.T) {
|
|||||||
workspace, err := Init(ctx, root)
|
workspace, err := Init(ctx, root)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = workspace.Create(ctx, "test", CreateOpts{})
|
_, err = workspace.Create(ctx, "test", Plan{
|
||||||
|
Module: ".",
|
||||||
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Set a plaintext input, make sure it is not encrypted
|
// Set a plaintext input, make sure it is not encrypted
|
||||||
|
@ -27,7 +27,7 @@ setup() {
|
|||||||
assert_success
|
assert_success
|
||||||
refute_output
|
refute_output
|
||||||
|
|
||||||
run "$DAGGER" new "test"
|
run "$DAGGER" new "test" --module "$DAGGER_WORKSPACE"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
run "$DAGGER" list
|
run "$DAGGER" list
|
||||||
|
Reference in New Issue
Block a user