lang, engine: Add a metaparam for catching accidental dollar signs

Let's make our life easier for users!
This commit is contained in:
James Shubin
2024-08-22 20:41:48 -04:00
parent 8dc0d44513
commit a0972c0752
10 changed files with 72 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ import (
"context"
"encoding/gob"
"fmt"
"strings"
"github.com/purpleidea/mgmt/engine/local"
"github.com/purpleidea/mgmt/pgraph"
@@ -272,6 +273,12 @@ func Validate(res Res) error {
return errwrap.Wrapf(err, "the Res has an invalid meta param")
}
// TODO: pull dollar prefix from a constant
// This catches typos where the user meant to use ${var} interpolation.
if !res.MetaParams().Dollar && strings.HasPrefix(res.Name(), "$") {
return fmt.Errorf("the Res name starts with a $")
}
return res.Validate()
}