lang, engine: Add a metaparam for catching accidental dollar signs
Let's make our life easier for users!
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user