mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-16 05:12:47 -06:00
55768aba53
Can now evaluate queries from the command line, for example: $ opa run -f json -e 'data.repl.version[x] = y' Fixes #152
42 lines
916 B
Go
42 lines
916 B
Go
// Copyright 2016 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repl
|
|
|
|
import "fmt"
|
|
|
|
// Error is the error type returned by the REPL.
|
|
type Error struct {
|
|
Code ErrCode
|
|
Message string
|
|
}
|
|
|
|
func (err *Error) Error() string {
|
|
return fmt.Sprintf("code %v: %v", err.Code, err.Message)
|
|
}
|
|
|
|
// ErrCode represents the collection of errors that may be returned by the REPL.
|
|
type ErrCode int
|
|
|
|
const (
|
|
// BadArgsErr indicates bad arguments were provided to a built-in REPL
|
|
// command.
|
|
BadArgsErr ErrCode = iota
|
|
)
|
|
|
|
func newBadArgsErr(f string, a ...interface{}) *Error {
|
|
return &Error{
|
|
Code: BadArgsErr,
|
|
Message: fmt.Sprintf(f, a...),
|
|
}
|
|
}
|
|
|
|
// stop is returned by the 'exit' command to indicate to the REPL that it should
|
|
// break and return.
|
|
type stop struct{}
|
|
|
|
func (stop) Error() string {
|
|
return "<stop>"
|
|
}
|