Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Examples:
AddStringArrayFlag(pconstants.ArgSnapshotTag, nil, "Specify tags to set on the snapshot").
AddStringFlag(pconstants.ArgSnapshotTitle, "", "The title to give a snapshot").
AddIntFlag(pconstants.ArgDatabaseQueryTimeout, 0, "The query timeout").
AddStringSliceFlag(pconstants.ArgExport, nil, "Export output to file, supported format: sps (snapshot)").
AddStringSliceFlag(pconstants.ArgExport, nil, "Export output to file, supported formats: csv, json, sps (snapshot)").
AddStringFlag(pconstants.ArgSnapshotLocation, "", "The location to write snapshots - either a local file path or a Turbot Pipes workspace").
AddBoolFlag(pconstants.ArgProgress, true, "Display snapshot upload status")

Expand Down
41 changes: 0 additions & 41 deletions pkg/export/snapshot_exporter.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/initialisation/init_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/turbot/steampipe/v2/pkg/db/db_client"
"github.com/turbot/steampipe/v2/pkg/db/db_common"
"github.com/turbot/steampipe/v2/pkg/db/db_local"
"github.com/turbot/steampipe/v2/pkg/export"
"github.com/turbot/pipe-fittings/v2/export"
"github.com/turbot/steampipe/v2/pkg/statushooks"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/query/init_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/turbot/steampipe/v2/pkg/constants"
"github.com/turbot/steampipe/v2/pkg/db/db_client"
"github.com/turbot/steampipe/v2/pkg/error_helpers"
"github.com/turbot/steampipe/v2/pkg/export"
"github.com/turbot/steampipe/v2/pkg/initialisation"
"github.com/turbot/steampipe/v2/pkg/statushooks"
"github.com/turbot/pipe-fittings/v2/export"
)

type InitData struct {
Expand Down Expand Up @@ -47,7 +47,7 @@ func NewInitData(ctx context.Context, args []string) *InitData {
}

func queryExporters() []export.Exporter {
return []export.Exporter{&export.SnapshotExporter{}}
return []export.Exporter{&export.SnapshotExporter{}, &export.CsvExporter{}, &export.JsonExporter{}}
}

func (i *InitData) Cancel() {
Expand Down
33 changes: 32 additions & 1 deletion pkg/query/queryexecute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ func executeQuery(ctx context.Context, initData *query.InitData, resolvedQuery *
return nil, rowErrors
}

if needCsvOrJson() {
exportArgs := viper.GetStringSlice(pconstants.ArgExport)
exportMsg, err := initData.ExportManager.DoExport(ctx, "query", r, exportArgs)
if err != nil {
return err, 0
}
if len(exportMsg) > 0 && viper.GetBool(pconstants.ArgProgress) {
fmt.Printf("\n") //nolint:forbidigo // intentional use of fmt
fmt.Println(strings.Join(exportMsg, "\n")) //nolint:forbidigo // intentional use of fmt
fmt.Printf("\n") //nolint:forbidigo // intentional use of fmt
}
}
// for other output formats, we call the querydisplay code in pipe-fittings
rowCount, rowErrs := querydisplay.ShowOutput(ctx, r)
// show timing
Expand All @@ -201,16 +213,35 @@ func needSnapshot() bool {
outputFormat := viper.GetString(pconstants.ArgOutput)
shouldShare := viper.GetBool(pconstants.ArgShare)
shouldUpload := viper.GetBool(pconstants.ArgSnapshot)
exportArgs := viper.GetStringSlice(constants.ArgExport)
isSnapshot := false
for _, arg := range exportArgs {
argLower := strings.ToLower(arg)
if strings.Contains(argLower, "pps") {
isSnapshot = true
}
}

// Check if the output format is a snapshot format or if ArgExport is set
if outputFormat == pconstants.OutputFormatSnapshot || outputFormat == pconstants.OutputFormatSteampipeSnapshotShort || viper.IsSet(pconstants.ArgExport) || shouldShare || shouldUpload {
if outputFormat == pconstants.OutputFormatSnapshot || outputFormat == pconstants.OutputFormatSteampipeSnapshotShort || isSnapshot || shouldShare || shouldUpload {
return true
}

// If none of the conditions are met, return false
return false
}

func needCsvOrJson() bool {
exportArgs := viper.GetStringSlice(constants.ArgExport)
for _, arg := range exportArgs {
argLower := strings.ToLower(arg)
if strings.Contains(argLower, "csv") || strings.Contains(argLower, "json") {
return true
}
}
return false
}

func publishSnapshotIfNeeded(ctx context.Context, snapshot *steampipeconfig.SteampipeSnapshot) error {
shouldShare := viper.GetBool(pconstants.ArgShare)
shouldUpload := viper.GetBool(pconstants.ArgSnapshot)
Expand Down
Loading