From 4840ef5fb92e9b5ab1f267bb9372d3fbb23c5f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Sat, 14 Sep 2024 10:24:20 -0400 Subject: [PATCH] add '-o cursor' output type for debugging --- docs/release-notes/change-log.md | 6 ++++++ tui/tui.go | 19 ++++++++++++++++++- tui/tui_enum.go | 16 +++++++++++----- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/change-log.md b/docs/release-notes/change-log.md index 90e17b88..946dce70 100644 --- a/docs/release-notes/change-log.md +++ b/docs/release-notes/change-log.md @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v1.10.4 (Unreleased) + +### CLI + +* Add `-o cursor` output type to `substreams run` for debugging purposes + ## v1.10.3 ### Server diff --git a/tui/tui.go b/tui/tui.go index 1fb00b4a..200e00eb 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/streamingfast/bstream" "github.com/streamingfast/substreams/tools/test" tea "github.com/charmbracelet/bubbletea" @@ -19,7 +20,7 @@ import ( //go:generate go-enum -f=$GOFILE --nocase --marshal --names -// ENUM(TUI, JSON, JSONL, CLOCK) +// ENUM(TUI, JSON, JSONL, CLOCK, CURSOR) type OutputMode uint type TUI struct { @@ -123,6 +124,8 @@ func (ui *TUI) configureOutputMode(outputMode string) error { case OutputModeTUI: ui.prettyPrintOutput = true case OutputModeJSONL: + case OutputModeCURSOR: + fmt.Println("printing cursor only, no data") case OutputModeCLOCK: fmt.Println("Writing clock information only (no data)") case OutputModeJSON: @@ -157,6 +160,12 @@ func (ui *TUI) IncomingMessage(ctx context.Context, resp *pbsubstreamsrpc.Respon printUndoJSON(m.BlockUndoSignal.LastValidBlock, m.BlockUndoSignal.LastValidCursor) case OutputModeCLOCK: fmt.Println("UNDO:", m.BlockUndoSignal.LastValidBlock) + case OutputModeCURSOR: + cur, err := bstream.CursorFromOpaque(m.BlockUndoSignal.LastValidCursor) + if err != nil { + return err + } + fmt.Println(cur.String()) } case *pbsubstreamsrpc.Response_BlockScopedData: @@ -175,6 +184,14 @@ func (ui *TUI) IncomingMessage(ctx context.Context, resp *pbsubstreamsrpc.Respon case OutputModeCLOCK: printClock(m.BlockScopedData) return nil + case OutputModeCURSOR: + + cur, err := bstream.CursorFromOpaque(resp.GetBlockScopedData().Cursor) + if err != nil { + return err + } + fmt.Println(cur.String()) + return nil } ui.seenFirstData = true diff --git a/tui/tui_enum.go b/tui/tui_enum.go index 6674ec6f..fab498b1 100644 --- a/tui/tui_enum.go +++ b/tui/tui_enum.go @@ -20,17 +20,20 @@ const ( OutputModeJSONL // OutputModeCLOCK is a OutputMode of type CLOCK. OutputModeCLOCK + // OutputModeCURSOR is a OutputMode of type CURSOR. + OutputModeCURSOR ) var ErrInvalidOutputMode = fmt.Errorf("not a valid OutputMode, try [%s]", strings.Join(_OutputModeNames, ", ")) -const _OutputModeName = "TUIJSONJSONLCLOCK" +const _OutputModeName = "TUIJSONJSONLCLOCKCURSOR" var _OutputModeNames = []string{ _OutputModeName[0:3], _OutputModeName[3:7], _OutputModeName[7:12], _OutputModeName[12:17], + _OutputModeName[17:23], } // OutputModeNames returns a list of possible string values of OutputMode. @@ -41,10 +44,11 @@ func OutputModeNames() []string { } var _OutputModeMap = map[OutputMode]string{ - OutputModeTUI: _OutputModeName[0:3], - OutputModeJSON: _OutputModeName[3:7], - OutputModeJSONL: _OutputModeName[7:12], - OutputModeCLOCK: _OutputModeName[12:17], + OutputModeTUI: _OutputModeName[0:3], + OutputModeJSON: _OutputModeName[3:7], + OutputModeJSONL: _OutputModeName[7:12], + OutputModeCLOCK: _OutputModeName[12:17], + OutputModeCURSOR: _OutputModeName[17:23], } // String implements the Stringer interface. @@ -71,6 +75,8 @@ var _OutputModeValue = map[string]OutputMode{ strings.ToLower(_OutputModeName[7:12]): OutputModeJSONL, _OutputModeName[12:17]: OutputModeCLOCK, strings.ToLower(_OutputModeName[12:17]): OutputModeCLOCK, + _OutputModeName[17:23]: OutputModeCURSOR, + strings.ToLower(_OutputModeName[17:23]): OutputModeCURSOR, } // ParseOutputMode attempts to convert a string to a OutputMode.