forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command line flag to eval, print, and exit
Can now evaluate queries from the command line, for example: $ opa run -f json -e 'data.repl.version[x] = y' Fixes open-policy-agent#152
- Loading branch information
Showing
6 changed files
with
230 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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>" | ||
} |
Oops, something went wrong.