[#xx] lens/tui: Add raw format switch

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-09-10 15:11:37 +03:00
parent 92fe5d90f5
commit fca25cc142
No known key found for this signature in database
3 changed files with 71 additions and 23 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
common "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal"
schemacommon "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/common"
schema "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/tui"
"github.com/rivo/tview"
@ -26,7 +27,10 @@ Available search filters:
Run: tuiFunc,
}
var initialPrompt string
var (
initialPrompt string
rawFormat string
)
func init() {
common.AddComponentPathFlag(tuiCMD, &vPath)
@ -37,6 +41,13 @@ func init() {
"",
"Filter prompt to start with, format 'tag:value [+ tag:value]...'",
)
tuiCMD.Flags().StringVar(
&rawFormat,
"raw-format",
"base58",
"Raw format, e.g. 'base58', 'str'",
)
}
func tuiFunc(cmd *cobra.Command, _ []string) {
@ -54,8 +65,24 @@ func runTUI(cmd *cobra.Command) error {
ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()
var parser schemacommon.Parser
switch rawFormat {
case "base58":
parser = schemacommon.WithFallback(
schema.MetabaseParser,
schemacommon.RawParser.ToFallbackParser(),
)
case "str":
parser = schemacommon.WithFallback(
schema.MetabaseParser,
schemacommon.StringParser.ToFallbackParser(),
)
default:
return fmt.Errorf("unknown raw format '%s'", rawFormat)
}
app := tview.NewApplication()
ui := tui.NewUI(ctx, app, db, schema.MetabaseParser, nil)
ui := tui.NewUI(ctx, app, db, parser, nil)
_ = ui.AddFilter("cid", tui.CIDParser, "CID")
_ = ui.AddFilter("oid", tui.OIDParser, "OID")

View file

@ -1,6 +1,8 @@
package common
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/gdamore/tcell/v2"
"github.com/mr-tron/base58"
@ -27,3 +29,25 @@ func (r *RawEntry) DetailedString() string {
func (r *RawEntry) Filter(string, any) FilterResult {
return No
}
type StringEntry struct {
key, value []byte
}
var StringParser Parser = stringParser
func stringParser(key, value []byte) (SchemaEntry, Parser, error) {
return &StringEntry{key: key, value: value}, stringParser, nil
}
func (r *StringEntry) String() string {
return FormatSimple(fmt.Sprintf("%q", r.key), tcell.ColorRed)
}
func (r *StringEntry) DetailedString() string {
return spew.Sdump(r)
}
func (r *StringEntry) Filter(string, any) FilterResult {
return No
}

View file

@ -5,25 +5,22 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/metabase/buckets"
)
var MetabaseParser = common.WithFallback(
common.Any(
buckets.GraveyardParser,
buckets.GarbageParser,
buckets.ContainerVolumeParser,
buckets.LockedParser,
buckets.ShardInfoParser,
buckets.PrimaryParser,
buckets.LockersParser,
buckets.TombstoneParser,
buckets.SmallParser,
buckets.RootParser,
buckets.OwnerParser,
buckets.UserAttributeParser,
buckets.PayloadHashParser,
buckets.ParentParser,
buckets.SplitParser,
buckets.ContainerCountersParser,
buckets.ECInfoParser,
),
common.RawParser.ToFallbackParser(),
var MetabaseParser = common.Any(
buckets.GraveyardParser,
buckets.GarbageParser,
buckets.ContainerVolumeParser,
buckets.LockedParser,
buckets.ShardInfoParser,
buckets.PrimaryParser,
buckets.LockersParser,
buckets.TombstoneParser,
buckets.SmallParser,
buckets.RootParser,
buckets.OwnerParser,
buckets.UserAttributeParser,
buckets.PayloadHashParser,
buckets.ParentParser,
buckets.SplitParser,
buckets.ContainerCountersParser,
buckets.ECInfoParser,
)