Skip to content

Commit

Permalink
support expressions as operator for a number of commands
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Worm <tony@hofstadter.io>
  • Loading branch information
verdverm committed Oct 16, 2021
1 parent cf76c89 commit bd461c6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions structural/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func ParseOperator(op string) (Input, error) {
i := Input{ Original: op, Filename: op }

// does the op look like a file or a CUE value?
// this is an overly simple check, but should be sufficient for all formats (CUE, JSON, Yaml)
if strings.ContainsAny(op, "{}:") {
i.Filename = "expression"
}

// look for expression
if strings.Contains(i.Filename, "@") {
Expand All @@ -45,6 +49,12 @@ func ParseOperator(op string) (Input, error) {
}

func LoadOperator(i Input, doLoad bool, ctx *cue.Context) (Input, error) {
if i.Filename == "expression" {
i.Content = []byte(i.Original)
i.Value = ctx.CompileString(i.Original)
return i, i.Value.Err()
}

if doLoad || i.Entrypoints != nil {
// handle entrypoints
if i.Entrypoints == nil {
Expand Down

0 comments on commit bd461c6

Please sign in to comment.