use the workspace as the plan module

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-07-02 18:28:03 +02:00
parent 919d5576d0
commit 6e215b194e
7 changed files with 95 additions and 73 deletions

View File

@@ -36,12 +36,10 @@ var initCmd = &cobra.Command{
dir = cwd
}
ws, err := state.Init(ctx, dir)
_, err := state.Init(ctx, dir)
if err != nil {
lg.Fatal().Err(err).Msg("failed to initialize workspace")
}
lg.Info().Str("path", ws.DaggerDir()).Msg("initialized new empty workspace")
},
}

View File

@@ -1,10 +1,6 @@
package cmd
import (
"fmt"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
@@ -36,42 +32,16 @@ var newCmd = &cobra.Command{
}
name := args[0]
module := viper.GetString("module")
if module == "" {
lg.Fatal().Msg("missing --module")
}
p, err := filepath.Abs(module)
if err != nil {
lg.Fatal().Err(err).Str("path", module).Msg("unable to resolve path")
}
if !strings.HasPrefix(p, workspace.Path) {
lg.Fatal().Err(err).Str("path", module).Msg("module is outside the workspace")
}
p, err = filepath.Rel(workspace.Path, p)
if err != nil {
lg.Fatal().Err(err).Str("path", module).Msg("unable to resolve path")
}
if !strings.HasPrefix(p, ".") {
p = "./" + p
}
module = p
ws, err := workspace.Create(ctx, name, state.Plan{
Module: module,
_, err := workspace.Create(ctx, name, state.Plan{
Package: viper.GetString("package"),
})
if err != nil {
lg.Fatal().Err(err).Msg("failed to create environment")
}
lg.Info().Str("name", name).Msg("created new empty environment")
lg.Info().Str("name", name).Msg(fmt.Sprintf("to add code to the plan, copy or create cue files under: %s", ws.Plan.Module))
},
}
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("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 {
panic(err)