Add the ability to specify and env config during eval
This adds the --config-env flag which can be used to apply configuration before performing evaluation of a package.
This commit is contained in:
parent
cbf5407a53
commit
783f9534c8
2 changed files with 21 additions and 6 deletions
10
cmd/env.go
10
cmd/env.go
|
@ -59,10 +59,12 @@ func initEnvCmd(cmd *cobra.Command, args []string) (*envCmdInfo, error) {
|
|||
if len(args) == 0 {
|
||||
return nil, fmt.Errorf("missing required environment name")
|
||||
}
|
||||
return initEnvCmdName(tokens.QName(args[0]), args[1:])
|
||||
}
|
||||
|
||||
func initEnvCmdName(name tokens.QName, args []string) (*envCmdInfo, error) {
|
||||
// Read in the deployment information, bailing if an IO error occurs.
|
||||
ctx := resource.NewContext(sink())
|
||||
name := tokens.QName(args[0])
|
||||
envfile, env, old := readEnv(ctx, name)
|
||||
if env == nil {
|
||||
contract.Assert(!ctx.Diag.Success())
|
||||
|
@ -74,8 +76,7 @@ func initEnvCmd(cmd *cobra.Command, args []string) (*envCmdInfo, error) {
|
|||
Env: env,
|
||||
Envfile: envfile,
|
||||
Old: old,
|
||||
Args: args[1:],
|
||||
Orig: args,
|
||||
Args: args,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -84,8 +85,7 @@ type envCmdInfo struct {
|
|||
Env *resource.Env // the environment information
|
||||
Envfile *resource.Envfile // the full serialized envfile from which this came.
|
||||
Old resource.Snapshot // the environment's latest deployment snapshot
|
||||
Args []string // the rest of the args after extracting the environment name
|
||||
Orig []string // the original args before extracting the environment name
|
||||
Args []string // the args after extracting the environment name
|
||||
}
|
||||
|
||||
func (eci *envCmdInfo) Close() error {
|
||||
|
|
|
@ -13,10 +13,12 @@ import (
|
|||
"github.com/pulumi/coconut/pkg/eval/heapstate"
|
||||
"github.com/pulumi/coconut/pkg/graph"
|
||||
"github.com/pulumi/coconut/pkg/graph/dotconv"
|
||||
"github.com/pulumi/coconut/pkg/resource"
|
||||
"github.com/pulumi/coconut/pkg/tokens"
|
||||
)
|
||||
|
||||
func newPackEvalCmd() *cobra.Command {
|
||||
var configEnv string
|
||||
var dotOutput bool
|
||||
var cmd = &cobra.Command{
|
||||
Use: "eval [package] [-- [args]]",
|
||||
|
@ -31,8 +33,18 @@ func newPackEvalCmd() *cobra.Command {
|
|||
"By default, a blueprint package is loaded from the current directory. Optionally,\n" +
|
||||
"a path to a package elsewhere can be provided as the [package] argument.",
|
||||
Run: runFunc(func(cmd *cobra.Command, args []string) error {
|
||||
// If a configuration environment was requested, load it.
|
||||
var config resource.ConfigMap
|
||||
if configEnv != "" {
|
||||
envInfo, err := initEnvCmdName(tokens.QName(configEnv), args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config = envInfo.Env.Config
|
||||
}
|
||||
|
||||
// Perform the compilation and, if non-nil is returned, output the graph.
|
||||
if result := compile(cmd, args, nil); result != nil && result.Heap != nil && result.Heap.G != nil {
|
||||
if result := compile(cmd, args, config); result != nil && result.Heap != nil && result.Heap.G != nil {
|
||||
// Serialize that evaluation graph so that it's suitable for printing/serializing.
|
||||
if dotOutput {
|
||||
// Convert the output to a DOT file.
|
||||
|
@ -51,6 +63,9 @@ func newPackEvalCmd() *cobra.Command {
|
|||
}),
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVar(
|
||||
&configEnv, "config-env", "",
|
||||
"Apply configuration from the specified environment before evaluating the package")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&dotOutput, "dot", false,
|
||||
"Output the graph as a DOT digraph (graph description language)")
|
||||
|
|
Loading…
Reference in a new issue