Revert "initial snapshot refactoring"

This reverts commit 924682ac8c3839147507ba08425fb4e96f6218b8.
This commit is contained in:
Puskar Basu
2024-09-03 16:09:43 +05:30
parent 14299b2c5d
commit 394963a520
3 changed files with 56 additions and 132 deletions

View File

@@ -22,13 +22,10 @@ import (
"github.com/spf13/viper"
"github.com/turbot/go-kit/helpers"
pfq "github.com/turbot/pipe-fittings/queryresult"
pqueryresult "github.com/turbot/pipe-fittings/queryresult"
pfq "github.com/turbot/pipe-fittings/queryresult"
"github.com/turbot/steampipe/pkg/cmdconfig"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/error_helpers"
"github.com/turbot/steampipe/pkg/query/queryresult"
"github.com/turbot/steampipe/pkg/snapshot2"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
@@ -45,8 +42,6 @@ func ShowOutput(ctx context.Context, result *queryresult.Result, opts ...Display
outputFormat := cmdconfig.Viper().GetString(constants.ArgOutput)
switch outputFormat {
case constants.OutputFormatSnapshotShort:
rowErrors, timingResult = displaySnapshot(ctx, result)
case constants.OutputFormatJSON:
rowErrors, timingResult = displayJSON(ctx, result)
case constants.OutputFormatCSV:
@@ -202,56 +197,6 @@ func newJSONOutput() *jsonOutput {
}
func displaySnapshot(ctx context.Context, result *queryresult.Result) (int, *queryresult.TimingResult) {
rowErrors := 0
snapshotOutput := snapshot2.NewEmptySnapshot()
// add column defs to the JSON output
for _, col := range result.Cols {
// create a new column def, converting the data type to lowercase
c := pfq.ColumnDef{
Name: col.Name,
DataType: strings.ToLower(col.DataType),
}
// add to the column def array
snapshotOutput.Panels["abcd"].Columns = append(jsonOutput.Columns, c)
}
// define function to add each row to the JSON output
rowFunc := func(row []interface{}, result *queryresult.Result) {
record := map[string]interface{}{}
for idx, col := range result.Cols {
value, _ := ParseJSONOutputColumnValue(row[idx], col)
// get the column def
c := jsonOutput.Columns[idx]
// add the value under the unique column name
record[c.Name] = value
}
snapshotOutput.Panels.Rows = append(jsonOutput.Rows, record)
}
// call this function for each row
count, err := iterateResults(result, rowFunc)
if err != nil {
error_helpers.ShowError(ctx, err)
rowErrors++
return rowErrors, nil
}
// now we have iterated the rows, get the timing
snapshotOutput.Metadata = getTiming(result, count)
// display the JSON
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
encoder.SetEscapeHTML(false)
if err := encoder.Encode(snapshotOutput); err != nil {
fmt.Print("Error displaying result as JSON", err)
return 0, nil
}
return rowErrors, snapshotOutput.Metadata
}
func displayJSON(ctx context.Context, result *queryresult.Result) (int, *queryresult.TimingResult) {
rowErrors := 0
jsonOutput := newJSONOutput()

View File

@@ -1,22 +0,0 @@
package snapshot2
import (
"context"
"github.com/turbot/pipe-fittings/steampipeconfig"
"github.com/turbot/steampipe/pkg/initialisation"
)
func GenerateSnapshot(ctx context.Context, target string, initData *initialisation.InitData, inputs map[string]any) (snapshot steampipeconfig.SteampipeSnapshot, err error) {
snapshot = NewEmptySnapshot()
return snapshot, nil
}
func NewEmptySnapshot() steampipeconfig.SteampipeSnapshot {
return steampipeconfig.SteampipeSnapshot{
SchemaVersion: "20221222",
Inputs: make(map[string]interface{}),
Panels: make(map[string]steampipeconfig.SnapshotPanel),
Variables: make(map[string]string),
}
}