cue native: environments can reference a module instead of embedding
one. Fixes #631 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
committed by
Solomon Hykes
parent
8de58eb3d0
commit
f39a88e644
@@ -38,7 +38,9 @@ var computeCmd = &cobra.Command{
|
||||
st := &state.State{
|
||||
Name: "FIXME",
|
||||
Path: args[0],
|
||||
Plan: args[0],
|
||||
Plan: state.Plan{
|
||||
Module: args[0],
|
||||
},
|
||||
}
|
||||
|
||||
for _, input := range viper.GetStringSlice("input-string") {
|
||||
|
@@ -65,6 +65,7 @@ var editCmd = &cobra.Command{
|
||||
lg.Fatal().Err(err).Msg("failed to decode file")
|
||||
}
|
||||
st.Name = newState.Name
|
||||
st.Plan = newState.Plan
|
||||
st.Inputs = newState.Inputs
|
||||
if err := workspace.Save(ctx, st); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to save state")
|
||||
|
@@ -2,6 +2,8 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -32,17 +34,40 @@ var newCmd = &cobra.Command{
|
||||
Msg("cannot use option -e,--environment for this command")
|
||||
}
|
||||
name := args[0]
|
||||
ws, err := workspace.Create(ctx, name)
|
||||
|
||||
module := viper.GetString("module")
|
||||
if 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, module, 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))
|
||||
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user