diff --git a/lang/gapi.go b/lang/gapi.go index 45a14d20..bbc95a9a 100644 --- a/lang/gapi.go +++ b/lang/gapi.go @@ -25,6 +25,7 @@ import ( "github.com/purpleidea/mgmt/gapi" "github.com/purpleidea/mgmt/lang/funcs/vars" + "github.com/purpleidea/mgmt/lang/inputs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/unification" "github.com/purpleidea/mgmt/pgraph" @@ -179,7 +180,7 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) { // the fs input here is the local fs we're reading to get the files from // this is different from the fs variable which is our output dest!!! - output, err := parseInput(input, localFs) + output, err := inputs.ParseInput(input, localFs) if err != nil { return nil, errwrap.Wrapf(err, "could not activate an input parser") } @@ -652,7 +653,7 @@ func (obj *GAPI) Get(getInfo *gapi.GetInfo) error { // the fs input here is the local fs we're reading to get the files from // this is different from the fs variable which is our output dest!!! - output, err := parseInput(input, localFs) + output, err := inputs.ParseInput(input, localFs) if err != nil { return errwrap.Wrapf(err, "could not activate an input parser") } diff --git a/lang/inputs.go b/lang/inputs/inputs.go similarity index 98% rename from lang/inputs.go rename to lang/inputs/inputs.go index 6c763a2b..e0594c3b 100644 --- a/lang/inputs.go +++ b/lang/inputs/inputs.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package lang +package inputs import ( "fmt" @@ -67,9 +67,9 @@ type ParsedInput struct { Workers []func(engine.Fs) error // copy files here that aren't listed! } -// parseInput runs the list if input parsers to know how to run the lexer, +// ParseInput runs the list if input parsers to know how to run the lexer, // parser, and so on... The fs input is the source filesystem to look in. -func parseInput(s string, fs engine.Fs) (*ParsedInput, error) { +func ParseInput(s string, fs engine.Fs) (*ParsedInput, error) { var err error var output *ParsedInput activated := false diff --git a/lang/interpret_test.go b/lang/interpret_test.go index c84b50df..d5be8c90 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -35,6 +35,7 @@ import ( "github.com/purpleidea/mgmt/etcd" "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/funcs/vars" + "github.com/purpleidea/mgmt/lang/inputs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/interpret" "github.com/purpleidea/mgmt/lang/unification" @@ -753,10 +754,10 @@ func TestAstFunc1(t *testing.T) { input := "/" logf("input: %s", input) - output, err := parseInput(input, fs) // raw code can be passed in + output, err := inputs.ParseInput(input, fs) // raw code can be passed in if err != nil { t.Errorf("test #%d: FAIL", index) - t.Errorf("test #%d: parseInput failed: %+v", index, err) + t.Errorf("test #%d: ParseInput failed: %+v", index, err) return } for _, fn := range output.Workers { @@ -1249,10 +1250,10 @@ func TestAstFunc2(t *testing.T) { input := "/" logf("input: %s", input) - output, err := parseInput(input, fs) // raw code can be passed in + output, err := inputs.ParseInput(input, fs) // raw code can be passed in if err != nil { t.Errorf("test #%d: FAIL", index) - t.Errorf("test #%d: parseInput failed: %+v", index, err) + t.Errorf("test #%d: ParseInput failed: %+v", index, err) return } for _, fn := range output.Workers { diff --git a/lang/lang.go b/lang/lang.go index eef6a5cb..fececbd6 100644 --- a/lang/lang.go +++ b/lang/lang.go @@ -26,6 +26,7 @@ import ( "github.com/purpleidea/mgmt/lang/funcs" _ "github.com/purpleidea/mgmt/lang/funcs/core" // import so the funcs register "github.com/purpleidea/mgmt/lang/funcs/vars" + "github.com/purpleidea/mgmt/lang/inputs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/interpret" "github.com/purpleidea/mgmt/lang/unification" @@ -99,13 +100,13 @@ func (obj *Lang) Init() error { // we used to support stdin passthrough, but we we got rid of it for now // the fs input here is the local fs we're reading to get the files from // which is usually etcdFs. - output, err := parseInput(obj.Input, obj.Fs) + output, err := inputs.ParseInput(obj.Input, obj.Fs) if err != nil { return errwrap.Wrapf(err, "could not activate an input parser") } if len(output.Workers) > 0 { // either programming error, or someone hacked in something here - // by the time *this* parseInput runs, we should be standardized + // by the time *this* ParseInput runs, we should be standardized return fmt.Errorf("input contained file system workers") } reader := bytes.NewReader(output.Main) diff --git a/lang/lang_test.go b/lang/lang_test.go index 21879756..9bdccf69 100644 --- a/lang/lang_test.go +++ b/lang/lang_test.go @@ -26,6 +26,7 @@ import ( "github.com/purpleidea/mgmt/engine" "github.com/purpleidea/mgmt/engine/resources" _ "github.com/purpleidea/mgmt/lang/funcs/core" // import so the funcs register + "github.com/purpleidea/mgmt/lang/inputs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/util" @@ -97,9 +98,9 @@ func runInterpret(t *testing.T, code string) (*pgraph.Graph, error) { afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil fs := &util.Fs{Afero: afs} - output, err := parseInput(code, fs) // raw code can be passed in + output, err := inputs.ParseInput(code, fs) // raw code can be passed in if err != nil { - return nil, errwrap.Wrapf(err, "parseInput failed") + return nil, errwrap.Wrapf(err, "ParseInput failed") } for _, fn := range output.Workers { if err := fn(fs); err != nil { diff --git a/lang/structs.go b/lang/structs.go index 9490f25f..fcc42e7e 100644 --- a/lang/structs.go +++ b/lang/structs.go @@ -30,6 +30,7 @@ import ( "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/funcs/bindata" "github.com/purpleidea/mgmt/lang/funcs/structs" + "github.com/purpleidea/mgmt/lang/inputs" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" langutil "github.com/purpleidea/mgmt/lang/util" @@ -3207,7 +3208,7 @@ func (obj *StmtProg) importSystemScope(name string) (*interfaces.Scope, error) { // importScopeWithInputs returns a local or remote scope from an inputs string. // The inputs string is the common frontend for a lot of our parsing decisions. func (obj *StmtProg) importScopeWithInputs(s string, scope *interfaces.Scope, parentVertex *pgraph.SelfVertex) (*interfaces.Scope, error) { - output, err := parseInput(s, obj.data.Fs) + output, err := inputs.ParseInput(s, obj.data.Fs) if err != nil { return nil, errwrap.Wrapf(err, "could not activate an input parser") }