Don't flow entire args array into the core of the engine
We were passing along the entire args array to the implementation of most commands, but the only place this was used was to pass one piece of information to the compiler we create in one case. Let's get explicit about the stuff we share from the CLI layer into the implementation of the commands and make this stuff well typed instead of a bag of strings.
This commit is contained in:
parent
b00c84a792
commit
c3b8972dce
5 changed files with 29 additions and 15 deletions
|
@ -114,13 +114,20 @@ func initEnvCmdName(name tokens.QName, args []string) (*envCmdInfo, error) {
|
||||||
if checkpoint == nil {
|
if checkpoint == nil {
|
||||||
return nil, goerr.Errorf("could not read environment information")
|
return nil, goerr.Errorf("could not read environment information")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pkgarg string
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
pkgarg = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
contract.Assert(target != nil)
|
contract.Assert(target != nil)
|
||||||
contract.Assert(checkpoint != nil)
|
contract.Assert(checkpoint != nil)
|
||||||
return &envCmdInfo{
|
return &envCmdInfo{
|
||||||
Target: target,
|
Target: target,
|
||||||
Checkpoint: checkpoint,
|
Checkpoint: checkpoint,
|
||||||
Snapshot: snapshot,
|
Snapshot: snapshot,
|
||||||
Args: args,
|
PackageArg: pkgarg,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +135,7 @@ type envCmdInfo struct {
|
||||||
Target *deploy.Target // the target environment.
|
Target *deploy.Target // the target environment.
|
||||||
Checkpoint *environment.Checkpoint // the full serialized checkpoint from which this came.
|
Checkpoint *environment.Checkpoint // the full serialized checkpoint from which this came.
|
||||||
Snapshot *deploy.Snapshot // the environment's latest deployment snapshot
|
Snapshot *deploy.Snapshot // the environment's latest deployment snapshot
|
||||||
Args []string // the args after extracting the environment name
|
PackageArg string // an optional path to a package to pass to the compiler
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmPrompt(msg string, name tokens.QName) bool {
|
func confirmPrompt(msg string, name tokens.QName) bool {
|
||||||
|
|
|
@ -48,14 +48,9 @@ func NewLumiCmd() *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareCompiler(args []string) (compiler.Compiler, *pack.Package) {
|
// TODO[pulumi/pulumi-fabric#88]: enable arguments to flow to the package itself. In that case, we want to split the
|
||||||
// TODO[pulumi/pulumi-fabric#88]: enable arguments to flow to the package itself. In that case, we want to split the
|
// arguments at the --, if any, so we can still pass arguments to the compiler itself in these cases.
|
||||||
// arguments at the --, if any, so we can still pass arguments to the compiler itself in these cases.
|
func prepareCompiler(pkgarg string) (compiler.Compiler, *pack.Package) {
|
||||||
var pkgarg string
|
|
||||||
if len(args) > 0 {
|
|
||||||
pkgarg = args[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a compiler options object and map any flags and arguments to settings on it.
|
// Create a compiler options object and map any flags and arguments to settings on it.
|
||||||
opts := core.DefaultOptions()
|
opts := core.DefaultOptions()
|
||||||
|
|
||||||
|
@ -83,9 +78,9 @@ func prepareCompiler(args []string) (compiler.Compiler, *pack.Package) {
|
||||||
|
|
||||||
// compile just uses the standard logic to parse arguments, options, and to locate/compile a package. It returns the
|
// compile just uses the standard logic to parse arguments, options, and to locate/compile a package. It returns the
|
||||||
// compilation result, or nil if an error occurred (in which case, we would expect diagnostics to have been output).
|
// compilation result, or nil if an error occurred (in which case, we would expect diagnostics to have been output).
|
||||||
func compile(args []string) *compileResult {
|
func compile(pkgarg string) *compileResult {
|
||||||
// Prepare the compiler info and, provided it succeeds, perform the compilation.
|
// Prepare the compiler info and, provided it succeeds, perform the compilation.
|
||||||
if comp, pkg := prepareCompiler(args); comp != nil {
|
if comp, pkg := prepareCompiler(pkgarg); comp != nil {
|
||||||
var b binder.Binder
|
var b binder.Binder
|
||||||
var pkgsym *symbols.Package
|
var pkgsym *symbols.Package
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
|
|
|
@ -34,8 +34,14 @@ func newPackEvalCmd() *cobra.Command {
|
||||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||||
contract.Assertf(!dotOutput, "TODO[pulumi/pulumi-fabric#235]: DOT files not yet supported")
|
contract.Assertf(!dotOutput, "TODO[pulumi/pulumi-fabric#235]: DOT files not yet supported")
|
||||||
|
|
||||||
|
var pkgarg string
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
pkgarg = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
// First, load and compile the package.
|
// First, load and compile the package.
|
||||||
result := compile(args)
|
result := compile(pkgarg)
|
||||||
if result == nil {
|
if result == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,14 @@ func newPackVerifyCmd() *cobra.Command {
|
||||||
// verify creates a compiler, much like compile, but only performs binding and verification on it. If verification
|
// verify creates a compiler, much like compile, but only performs binding and verification on it. If verification
|
||||||
// succeeds, the return value is true; if verification fails, errors will have been output, and the return is false.
|
// succeeds, the return value is true; if verification fails, errors will have been output, and the return is false.
|
||||||
func verify(cmd *cobra.Command, args []string) bool {
|
func verify(cmd *cobra.Command, args []string) bool {
|
||||||
|
var pkgarg string
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
pkgarg = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare the compiler info and, provided it succeeds, perform the verification.
|
// Prepare the compiler info and, provided it succeeds, perform the verification.
|
||||||
if comp, pkg := prepareCompiler(args); comp != nil {
|
if comp, pkg := prepareCompiler(pkgarg); comp != nil {
|
||||||
// Now perform the compilation and extract the heap snapshot.
|
// Now perform the compilation and extract the heap snapshot.
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
return comp.Verify()
|
return comp.Verify()
|
||||||
|
|
|
@ -127,7 +127,7 @@ func plan(info *envCmdInfo, opts deployOptions) (*planResult, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, compile the package, in preparatin for interpreting it and creating resources.
|
// First, compile the package, in preparatin for interpreting it and creating resources.
|
||||||
result := compile(info.Args)
|
result := compile(info.PackageArg)
|
||||||
if result == nil || !result.B.Ctx().Diag.Success() {
|
if result == nil || !result.B.Ctx().Diag.Success() {
|
||||||
return nil, fmt.Errorf("Errors during compilation: %v", result.B.Ctx().Diag.Errors())
|
return nil, fmt.Errorf("Errors during compilation: %v", result.B.Ctx().Diag.Errors())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue