File: step.go

package info (click to toggle)
dasel 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,844 kB
  • sloc: sh: 53; python: 21; makefile: 21; xml: 20
file content (41 lines) | stat: -rw-r--r-- 791 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dasel

// Step is a single step in the query.
// Each function call has its own step.
// Each value in the output is simply a pointer to the actual data point in the context data.
type Step struct {
	context  *Context
	selector Selector
	index    int
	output   Values
}

func (s *Step) Selector() Selector {
	return s.selector
}

func (s *Step) Index() int {
	return s.index
}

func (s *Step) Output() Values {
	return s.output
}

func (s *Step) execute() error {
	f, err := s.context.functions.Get(s.selector.funcName)
	if err != nil {
		return err
	}
	output, err := f(s.context, s, s.selector.funcArgs)
	s.output = output
	return err
}

func (s *Step) inputs() Values {
	prevStep := s.context.Step(s.index - 1)
	if prevStep == nil {
		return Values{}
	}
	return prevStep.output
}