Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose optional types as a REPL option #675

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion repl/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ func newExtensionOption(extType string) (*extensionOption, error) {
var extOption cel.EnvOption
extType = strings.ToLower(extType)
switch op := extType; op {
case "optional":
extOption = cel.OptionalTypes()
case "strings":
extOption = ext.Strings()
case "protos":
Expand Down Expand Up @@ -774,7 +776,7 @@ func (e *Evaluator) loadExtensionOption(idx int, args []string) error {
argExtType := args[idx]
if argExtType == "all" {
// Load all extension types as a convenience
var extensionTypes = []string{"strings", "protos", "math", "encoders"}
var extensionTypes = []string{"optional", "strings", "protos", "math", "encoders"}
for _, val := range extensionTypes {
err := e.loadExtensionOptionType(val)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions repl/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,24 @@ func TestProcess(t *testing.T) {
wantExit: false,
wantError: false,
},
{
name: "OptionExtensionOptional",
commands: []Cmder{
&simpleCmd{
cmd: "option",
args: []string{
"--extension",
"optional",
},
},
&evalCmd{
expr: "optional.none().orValue('default')",
},
},
wantText: "default : string",
wantExit: false,
wantError: false,
},
{
name: "OptionExtensionStrings",
commands: []Cmder{
Expand Down
2 changes: 1 addition & 1 deletion repl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df
github.com/chzyer/readline v1.5.1
github.com/google/cel-go v0.13.0
github.com/google/cel-go v0.14.0
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/protobuf v1.29.1
)
Expand Down