-
Notifications
You must be signed in to change notification settings - Fork 265
/
formatter_snapshot.go
50 lines (40 loc) · 1.17 KB
/
formatter_snapshot.go
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
42
43
44
45
46
47
48
49
50
package controldisplay
import (
"context"
"fmt"
"io"
"strings"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/control/controlexecute"
)
type SnapshotFormatter struct {
FormatterBase
}
func (f *SnapshotFormatter) Format(ctx context.Context, tree *controlexecute.ExecutionTree) (io.Reader, error) {
snapshot, err := executionTreeToSnapshot(tree)
if err != nil {
return nil, err
}
// determine whether to indent the snapshot
// TACTICAL: check in the context for contextKeyFormatterUse - if this is "export" then DO NOT indent
var indent = true
if formatterPurpose, ok := ctx.Value(contextKeyFormatterPurpose).(string); ok && formatterPurpose == formatterPurposeExport {
indent = false
}
// strip unwanted fields from the snapshot
snapshotStr, err := snapshot.AsStrippedJson(indent)
if err != nil {
return nil, err
}
res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotStr)))
return res, nil
}
func (f *SnapshotFormatter) FileExtension() string {
return constants.SnapshotExtension
}
func (f SnapshotFormatter) Name() string {
return constants.OutputFormatSnapshot
}
func (f *SnapshotFormatter) Alias() string {
return "sps"
}