Skip to content
Merged
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
18 changes: 18 additions & 0 deletions internal/cmd/prediction/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prediction

import (
"encoding/json"
"fmt"
"os/exec"

Expand Down Expand Up @@ -69,6 +70,15 @@ var listCmd = &cobra.Command{
return fmt.Errorf("failed to get predictions: %w", err)
}

if cmd.Flags().Changed("json") || !util.IsTTY() {
bytes, err := json.MarshalIndent(predictions, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal predictions: %w", err)
}
fmt.Println(string(bytes))
return nil
}

columns := []table.Column{
{Title: "ID", Width: 20},
{Title: "Version", Width: 20},
Expand Down Expand Up @@ -114,3 +124,11 @@ var listCmd = &cobra.Command{
return nil
},
}

func init() {
addListFlags(listCmd)
}

func addListFlags(cmd *cobra.Command) {
cmd.Flags().Bool("json", false, "Emit JSON")
}