forked from TrueCloudLab/frostfs-node
[#xx] lens/tui: Add raw format switch
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
92fe5d90f5
commit
fca25cc142
3 changed files with 71 additions and 23 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
common "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal"
|
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"
|
schema "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/metabase"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/tui"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/tui"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
@ -26,7 +27,10 @@ Available search filters:
|
||||||
Run: tuiFunc,
|
Run: tuiFunc,
|
||||||
}
|
}
|
||||||
|
|
||||||
var initialPrompt string
|
var (
|
||||||
|
initialPrompt string
|
||||||
|
rawFormat string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.AddComponentPathFlag(tuiCMD, &vPath)
|
common.AddComponentPathFlag(tuiCMD, &vPath)
|
||||||
|
@ -37,6 +41,13 @@ func init() {
|
||||||
"",
|
"",
|
||||||
"Filter prompt to start with, format 'tag:value [+ tag:value]...'",
|
"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) {
|
func tuiFunc(cmd *cobra.Command, _ []string) {
|
||||||
|
@ -54,8 +65,24 @@ func runTUI(cmd *cobra.Command) error {
|
||||||
ctx, cancel := context.WithCancel(cmd.Context())
|
ctx, cancel := context.WithCancel(cmd.Context())
|
||||||
defer cancel()
|
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()
|
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("cid", tui.CIDParser, "CID")
|
||||||
_ = ui.AddFilter("oid", tui.OIDParser, "OID")
|
_ = ui.AddFilter("oid", tui.OIDParser, "OID")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
|
@ -27,3 +29,25 @@ func (r *RawEntry) DetailedString() string {
|
||||||
func (r *RawEntry) Filter(string, any) FilterResult {
|
func (r *RawEntry) Filter(string, any) FilterResult {
|
||||||
return No
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/metabase/buckets"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/schema/metabase/buckets"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MetabaseParser = common.WithFallback(
|
var MetabaseParser = common.Any(
|
||||||
common.Any(
|
|
||||||
buckets.GraveyardParser,
|
buckets.GraveyardParser,
|
||||||
buckets.GarbageParser,
|
buckets.GarbageParser,
|
||||||
buckets.ContainerVolumeParser,
|
buckets.ContainerVolumeParser,
|
||||||
|
@ -24,6 +23,4 @@ var MetabaseParser = common.WithFallback(
|
||||||
buckets.SplitParser,
|
buckets.SplitParser,
|
||||||
buckets.ContainerCountersParser,
|
buckets.ContainerCountersParser,
|
||||||
buckets.ECInfoParser,
|
buckets.ECInfoParser,
|
||||||
),
|
|
||||||
common.RawParser.ToFallbackParser(),
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue