2017-05-18 23:51:52 +02:00
|
|
|
// Licensed to Pulumi Corporation ("Pulumi") under one or more
|
|
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
|
|
// this work for additional information regarding copyright ownership.
|
|
|
|
// Pulumi licenses this file to You under the Apache License, Version 2.0
|
|
|
|
// (the "License"); you may not use this file except in compliance with
|
|
|
|
// the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
|
2017-04-12 19:38:12 +02:00
|
|
|
package main
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
|
|
|
|
import (
|
2017-06-11 17:58:21 +02:00
|
|
|
"fmt"
|
2017-01-19 00:52:26 +01:00
|
|
|
"strings"
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2017-05-18 20:38:28 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/compiler/core"
|
2017-06-11 17:58:21 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/eval"
|
|
|
|
"github.com/pulumi/lumi/pkg/resource/deploy"
|
2017-05-18 20:38:28 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/tokens"
|
|
|
|
"github.com/pulumi/lumi/pkg/util/cmdutil"
|
2017-06-11 17:58:21 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/util/contract"
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
)
|
|
|
|
|
2017-03-09 16:43:28 +01:00
|
|
|
func newPackEvalCmd() *cobra.Command {
|
2017-03-09 16:52:50 +01:00
|
|
|
var configEnv string
|
2017-02-10 00:56:15 +01:00
|
|
|
var dotOutput bool
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
var cmd = &cobra.Command{
|
2017-03-09 16:43:28 +01:00
|
|
|
Use: "eval [package] [-- [args]]",
|
|
|
|
Short: "Evaluate a package and print the resulting objects",
|
|
|
|
Long: "Evaluate a package and print the resulting objects\n" +
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
"\n" +
|
|
|
|
"A graph is a topologically sorted directed-acyclic-graph (DAG), representing a\n" +
|
|
|
|
"collection of resources that may be used in a deployment operation like plan or apply.\n" +
|
2017-03-09 16:43:28 +01:00
|
|
|
"This graph is produced by evaluating the contents of a blueprint package, and does not\n" +
|
2017-02-25 16:25:33 +01:00
|
|
|
"actually perform any updates to the target environment.\n" +
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
"\n" +
|
|
|
|
"By default, a blueprint package is loaded from the current directory. Optionally,\n" +
|
2017-03-09 16:43:28 +01:00
|
|
|
"a path to a package elsewhere can be provided as the [package] argument.",
|
2017-04-12 20:12:25 +02:00
|
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
2017-06-11 17:58:21 +02:00
|
|
|
contract.Assertf(!dotOutput, "TODO[pulumi/lumi#235]: DOT files not yet supported")
|
|
|
|
|
|
|
|
// First, load and compile the package.
|
|
|
|
result := compile(cmd, args)
|
|
|
|
if result == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now fire up an interpreter so we can run the program.
|
|
|
|
e := eval.New(result.B.Ctx(), nil)
|
|
|
|
|
|
|
|
// If configuration was requested, load it up and populate the object state.
|
|
|
|
if configEnv != "" {
|
|
|
|
envInfo, err := initEnvCmdName(tokens.QName(configEnv), args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-03-09 16:52:50 +01:00
|
|
|
}
|
2017-06-11 17:58:21 +02:00
|
|
|
deploy.InitEvalConfig(result.B.Ctx(), e, envInfo.Target.Config)
|
|
|
|
}
|
2017-03-09 16:52:50 +01:00
|
|
|
|
2017-06-11 17:58:21 +02:00
|
|
|
// Finally, execute the entire program, and serialize the return value (if any).
|
|
|
|
if obj, _ := e.EvaluatePackage(result.Pkg, nil); obj != nil {
|
|
|
|
fmt.Print(obj)
|
|
|
|
}
|
2017-03-07 14:47:42 +01:00
|
|
|
return nil
|
|
|
|
}),
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:52:50 +01:00
|
|
|
cmd.PersistentFlags().StringVar(
|
|
|
|
&configEnv, "config-env", "",
|
|
|
|
"Apply configuration from the specified environment before evaluating the package")
|
2017-02-10 00:56:15 +01:00
|
|
|
cmd.PersistentFlags().BoolVar(
|
|
|
|
&dotOutput, "dot", false,
|
|
|
|
"Output the graph as a DOT digraph (graph description language)")
|
|
|
|
|
Add scaffolding for mu apply, compile, and plan
This adds scaffolding but no real functionality yet, as part of
marapongo/mu#41. I am landing this now because I need to take a
not-so-brief detour to gut and overhaul the core of the existing
compiler (parsing, semantic analysis, binding, code-gen, etc),
including merging the new pkg/pack contents back into the primary
top-level namespaces (like pkg/ast and pkg/encoding).
After that, I can begin driving the compiler to achieve the
desired effects of mu compile, first and foremost, and then plan
and apply later on.
2017-01-17 23:40:55 +01:00
|
|
|
return cmd
|
|
|
|
}
|
2017-01-19 00:52:26 +01:00
|
|
|
|
|
|
|
// dashdashArgsToMap is a simple args parser that places incoming key/value pairs into a map. These are then used
|
2017-03-09 16:43:28 +01:00
|
|
|
// during package compilation as inputs to the main entrypoint function.
|
2017-06-06 15:05:35 +02:00
|
|
|
// IDEA: this is fairly rudimentary; we eventually want to support arrays, maps, and complex types.
|
2017-01-26 03:38:53 +01:00
|
|
|
func dashdashArgsToMap(args []string) core.Args {
|
|
|
|
mapped := make(core.Args)
|
2017-01-19 00:52:26 +01:00
|
|
|
|
|
|
|
for i := 0; i < len(args); i++ {
|
|
|
|
arg := args[i]
|
|
|
|
|
|
|
|
// Eat - or -- at the start.
|
|
|
|
if arg[0] == '-' {
|
|
|
|
arg = arg[1:]
|
|
|
|
if arg[0] == '-' {
|
|
|
|
arg = arg[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now find a k=v, and split the k/v part.
|
|
|
|
if eq := strings.IndexByte(arg, '='); eq != -1 {
|
|
|
|
// For --k=v, simply store v underneath k's entry.
|
2017-01-26 03:38:53 +01:00
|
|
|
mapped[tokens.Name(arg[:eq])] = arg[eq+1:]
|
2017-01-19 00:52:26 +01:00
|
|
|
} else {
|
|
|
|
if i+1 < len(args) && args[i+1][0] != '-' {
|
|
|
|
// If the next arg doesn't start with '-' (i.e., another flag) use its value.
|
2017-01-26 03:38:53 +01:00
|
|
|
mapped[tokens.Name(arg)] = args[i+1]
|
2017-01-19 00:52:26 +01:00
|
|
|
i++
|
|
|
|
} else if arg[0:3] == "no-" {
|
|
|
|
// For --no-k style args, strip off the no- prefix and store false underneath k.
|
2017-01-26 03:38:53 +01:00
|
|
|
mapped[tokens.Name(arg[3:])] = false
|
2017-01-19 00:52:26 +01:00
|
|
|
} else {
|
|
|
|
// For all other --k args, assume this is a boolean flag, and set the value of k to true.
|
2017-01-26 03:38:53 +01:00
|
|
|
mapped[tokens.Name(arg)] = true
|
2017-01-19 00:52:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mapped
|
|
|
|
}
|