Skip to content

Commit

Permalink
Fix json switch on export command (#132)
Browse files Browse the repository at this point in the history
This fixes broken implementation of the recently added --json switch.
Prior to this commit it only would have worked if --output-format json
were simultaneously supplied.
  • Loading branch information
wkalt authored Dec 20, 2023
1 parent 21c2869 commit ed2d962
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions foxglove/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ func newExportCommand(params *baseParams) (*cobra.Command, error) {
if err != nil {
dief("failed to parse end time: %s", err)
}
if isJsonOutput {
outputFormat = "json"
}
request, err := createStreamRequest(
recordingID,
importID,
Expand All @@ -901,9 +904,9 @@ func newExportCommand(params *baseParams) (*cobra.Command, error) {
if err != nil {
dief("Failed to build request: %s", err)
}
if isJsonOutput && outputFormat != "json" {
dief("Export failed. Output format conflict: --json, --output-format ", outputFormat)
}

// If there is an output file and the output format is not JSON,
// export to that file with resumable downloads.
if outputFile != "" && outputFormat != "json" {
err = doExport(
cmd.Context(),
Expand All @@ -920,10 +923,15 @@ func newExportCommand(params *baseParams) (*cobra.Command, error) {
fmt.Fprint(os.Stderr, "\n")
return
}

// Otherwise we are going to stdout. Ensure it's either JSON or
// getting redirected.
if !stdoutRedirected() && request.OutputFormat != "json" {
dief("Binary output may screw up your terminal. Please redirect to a pipe or file.")
}
defer os.Stdout.Close()

// Do the export, without resumable downloads.
err = executeExport(
cmd.Context(),
os.Stdout,
Expand Down

0 comments on commit ed2d962

Please sign in to comment.