do: verify the action exists before running

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2022-03-08 18:34:47 -08:00
parent 116e25ce20
commit 9f2d56f3c4
3 changed files with 30 additions and 19 deletions

View File

@@ -175,17 +175,19 @@ func (p *Plan) fillAction() {
noOpRunner,
)
actions := p.source.LookupPath(cue.MakePath(ActionSelector))
actionsComment := ""
for _, cg := range actions.Doc() {
actionsComment += cg.Text()
}
p.action = &Action{
ActionSelector.String(),
false,
actions.Path(),
actionsComment,
[]*Action{},
Name: ActionSelector.String(),
Hidden: false,
Path: cue.MakePath(ActionSelector),
Children: []*Action{},
}
actions := p.source.LookupPath(cue.MakePath(ActionSelector))
if actions.Exists() {
return
}
for _, cg := range actions.Doc() {
p.action.Comment += cg.Text()
}
tasks := flow.Tasks()
@@ -205,11 +207,11 @@ func (p *Plan) fillAction() {
}
a = &Action{
s.String(),
s.PkgPath() != "",
path,
childComment,
[]*Action{},
Name: s.String(),
Hidden: s.PkgPath() != "",
Path: path,
Comment: childComment,
Children: []*Action{},
}
prevAction.AddChild(a)
}

View File

@@ -38,6 +38,10 @@ func NewRunner(pctx *plancontext.Context, target cue.Path, s solver.Solver) *Run
}
func (r *Runner) Run(ctx context.Context, src *compiler.Value) error {
if !src.LookupPath(r.target).Exists() {
return fmt.Errorf("%s not found", r.target.String())
}
if err := r.update(cue.MakePath(), src); err != nil {
return err
}