From 3dfcd947873ec95ac8c60a12115212808b4e9af5 Mon Sep 17 00:00:00 2001 From: Future Outlier Date: Thu, 16 Nov 2023 22:58:08 +0800 Subject: [PATCH 1/2] first commit Signed-off-by: Future Outlier --- cmd/get/get.go | 132 +++++++++++++++++++++++++++++++++++++------------ go.mod | 16 ++++-- go.sum | 31 ++++++++++-- 3 files changed, 141 insertions(+), 38 deletions(-) diff --git a/cmd/get/get.go b/cmd/get/get.go index 7c1b5ea1..234eb640 100644 --- a/cmd/get/get.go +++ b/cmd/get/get.go @@ -1,6 +1,12 @@ package get import ( + "fmt" + "os" + "strings" + + tea "github.com/charmbracelet/bubbletea" + "github.com/fatih/color" "github.com/flyteorg/flytectl/cmd/config/subcommand/clusterresourceattribute" "github.com/flyteorg/flytectl/cmd/config/subcommand/execution" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionclusterlabel" @@ -17,6 +23,87 @@ import ( "github.com/spf13/cobra" ) +type model struct { + choices []string + cursor int + selected string +} + +var GetResourcesFuncs = map[string]cmdcore.CommandEntry{ + "project": {CmdFunc: getProjectsFunc, Aliases: []string{"projects"}, ProjectDomainNotRequired: true, + Short: projectShort, + Long: projectLong, PFlagProvider: project.DefaultConfig}, + "task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}, Short: taskShort, + Long: taskLong, PFlagProvider: task.DefaultConfig}, + "workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}, Short: workflowShort, + Long: workflowLong, PFlagProvider: workflow.DefaultConfig}, + "launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}, Short: launchPlanShort, + Long: launchPlanLong, PFlagProvider: launchplan.DefaultConfig}, + "execution": {CmdFunc: getExecutionFunc, Aliases: []string{"executions"}, Short: executionShort, + Long: executionLong, PFlagProvider: execution.DefaultConfig}, + "task-resource-attribute": {CmdFunc: getTaskResourceAttributes, Aliases: []string{"task-resource-attributes"}, + Short: taskResourceAttributesShort, + Long: taskResourceAttributesLong, PFlagProvider: taskresourceattribute.DefaultFetchConfig}, + "cluster-resource-attribute": {CmdFunc: getClusterResourceAttributes, Aliases: []string{"cluster-resource-attributes"}, + Short: clusterResourceAttributesShort, + Long: clusterResourceAttributesLong, PFlagProvider: clusterresourceattribute.DefaultFetchConfig}, + "execution-queue-attribute": {CmdFunc: getExecutionQueueAttributes, Aliases: []string{"execution-queue-attributes"}, + Short: executionQueueAttributesShort, + Long: executionQueueAttributesLong, PFlagProvider: executionqueueattribute.DefaultFetchConfig}, + "execution-cluster-label": {CmdFunc: getExecutionClusterLabel, Aliases: []string{"execution-cluster-labels"}, + Short: executionClusterLabelShort, + Long: executionClusterLabelLong, PFlagProvider: executionclusterlabel.DefaultFetchConfig}, + "plugin-override": {CmdFunc: getPluginOverridesFunc, Aliases: []string{"plugin-overrides"}, + Short: pluginOverrideShort, + Long: pluginOverrideLong, PFlagProvider: pluginoverride.DefaultFetchConfig}, + "workflow-execution-config": {CmdFunc: getWorkflowExecutionConfigFunc, Aliases: []string{"workflow-execution-config"}, + Short: workflowExecutionConfigShort, + Long: workflowExecutionConfigLong, PFlagProvider: workflowexecutionconfig.DefaultFetchConfig, ProjectDomainNotRequired: true}, +} + +func (m model) Init() tea.Cmd { + return nil +} + +func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch msg.String() { + case "up": + if m.cursor > 0 { + m.cursor-- + } + case "down": + if m.cursor < len(m.choices)-1 { + m.cursor++ + } + case "enter": + m.selected = m.choices[m.cursor] + fmt.Println("You selected:", m.selected) + // if cmdFunc, exists := GetResourcesFuncs[m.selected]; exists { + // cmdFunc[m.selected] + // } + + return m, tea.Quit + } + } + return m, nil +} + +func (m model) View() string { + var s strings.Builder + blue := color.New(color.FgBlue) + + for i, choice := range m.choices { + if i == m.cursor { + blue.Fprintf(&s, "> %s\n", choice) + } else { + fmt.Fprintf(&s, " %s\n", choice) + } + } + return s.String() +} + // Long descriptions are whitespace sensitive when generating docs using sphinx. const ( getCmdShort = `Fetches various Flyte resources such as tasks, workflows, launch plans, executions, and projects.` @@ -34,41 +121,22 @@ func CreateGetCommand() *cobra.Command { Use: "get", Short: getCmdShort, Long: getCmdLong, + Run: func(cmd *cobra.Command, args []string) { + p := tea.NewProgram(model{ + choices: []string{"project", "task", "workflow", "launchplan", + "task-resource-attribute", "cluster-resource-attribute", "execution-queue-attribute", + "execution-cluster-label", "plugin-override", "workflow-execution-config"}, + }) + if err := p.Start(); err != nil { + fmt.Fprintf(os.Stderr, "Error occurred: %v\n", err) + os.Exit(1) + } + }, } - getResourcesFuncs := map[string]cmdcore.CommandEntry{ - "project": {CmdFunc: getProjectsFunc, Aliases: []string{"projects"}, ProjectDomainNotRequired: true, - Short: projectShort, - Long: projectLong, PFlagProvider: project.DefaultConfig}, - "task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}, Short: taskShort, - Long: taskLong, PFlagProvider: task.DefaultConfig}, - "workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}, Short: workflowShort, - Long: workflowLong, PFlagProvider: workflow.DefaultConfig}, - "launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}, Short: launchPlanShort, - Long: launchPlanLong, PFlagProvider: launchplan.DefaultConfig}, - "execution": {CmdFunc: getExecutionFunc, Aliases: []string{"executions"}, Short: executionShort, - Long: executionLong, PFlagProvider: execution.DefaultConfig}, - "task-resource-attribute": {CmdFunc: getTaskResourceAttributes, Aliases: []string{"task-resource-attributes"}, - Short: taskResourceAttributesShort, - Long: taskResourceAttributesLong, PFlagProvider: taskresourceattribute.DefaultFetchConfig}, - "cluster-resource-attribute": {CmdFunc: getClusterResourceAttributes, Aliases: []string{"cluster-resource-attributes"}, - Short: clusterResourceAttributesShort, - Long: clusterResourceAttributesLong, PFlagProvider: clusterresourceattribute.DefaultFetchConfig}, - "execution-queue-attribute": {CmdFunc: getExecutionQueueAttributes, Aliases: []string{"execution-queue-attributes"}, - Short: executionQueueAttributesShort, - Long: executionQueueAttributesLong, PFlagProvider: executionqueueattribute.DefaultFetchConfig}, - "execution-cluster-label": {CmdFunc: getExecutionClusterLabel, Aliases: []string{"execution-cluster-labels"}, - Short: executionClusterLabelShort, - Long: executionClusterLabelLong, PFlagProvider: executionclusterlabel.DefaultFetchConfig}, - "plugin-override": {CmdFunc: getPluginOverridesFunc, Aliases: []string{"plugin-overrides"}, - Short: pluginOverrideShort, - Long: pluginOverrideLong, PFlagProvider: pluginoverride.DefaultFetchConfig}, - "workflow-execution-config": {CmdFunc: getWorkflowExecutionConfigFunc, Aliases: []string{"workflow-execution-config"}, - Short: workflowExecutionConfigShort, - Long: workflowExecutionConfigLong, PFlagProvider: workflowexecutionconfig.DefaultFetchConfig, ProjectDomainNotRequired: true}, - } + fmt.Println("getCmd:", getCmd) - cmdcore.AddCommands(getCmd, getResourcesFuncs) + cmdcore.AddCommands(getCmd, GetResourcesFuncs) return getCmd } diff --git a/go.mod b/go.mod index 4beaf4d5..bc3bf368 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,12 @@ require ( github.com/apoorvam/goterminal v0.0.0-20180523175556-614d345c47e5 github.com/avast/retry-go v3.0.0+incompatible github.com/awalterschulze/gographviz v2.0.3+incompatible + github.com/charmbracelet/bubbletea v0.24.2 github.com/disiqueira/gotree v1.0.0 github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 github.com/enescakir/emoji v1.0.0 + github.com/fatih/color v1.13.0 github.com/flyteorg/flyte/flyteidl v1.9.12 github.com/flyteorg/flyte/flytepropeller v1.9.12 github.com/flyteorg/flyte/flytestdlib v1.9.12 @@ -67,9 +69,11 @@ require ( github.com/Microsoft/go-winio v0.5.0 // indirect github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect github.com/aws/aws-sdk-go v1.44.2 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/containerd/containerd v1.5.10 // indirect github.com/coocood/freecache v1.1.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect @@ -81,7 +85,6 @@ require ( github.com/dustin/go-humanize v1.0.0 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect - github.com/fatih/color v1.13.0 // indirect github.com/flyteorg/flyte/flyteplugins v0.0.0-00010101000000-000000000000 // indirect github.com/flyteorg/stow v0.3.7 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect @@ -111,15 +114,21 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/morikuni/aec v1.0.0 // indirect + github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/reflow v0.3.0 // indirect + github.com/muesli/termenv v0.15.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/ncw/swift v1.0.53 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect @@ -142,6 +151,7 @@ require ( golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/net v0.9.0 // indirect + golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.7.0 // indirect golang.org/x/term v0.7.0 // indirect golang.org/x/time v0.1.0 // indirect diff --git a/go.sum b/go.sum index 00892a20..48b3c066 100644 --- a/go.sum +++ b/go.sum @@ -137,6 +137,8 @@ github.com/awalterschulze/gographviz v2.0.3+incompatible/go.mod h1:GEV5wmg4YquNw github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= github.com/aws/aws-sdk-go v1.44.2 h1:5VBk5r06bgxgRKVaUtm1/4NT/rtrnH2E4cnAYv5zgQc= github.com/aws/aws-sdk-go v1.44.2/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -161,6 +163,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= +github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw= github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= @@ -196,6 +200,8 @@ github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE= github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw= github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/containerd v1.2.10/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -614,6 +620,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/landoop/tableprinter v0.0.0-20180806200924-8bd8c2576d27 h1:O664tckOIC4smyHDDJPXAh/YBYYc0Y1O8S5wmZDm3d8= github.com/landoop/tableprinter v0.0.0-20180806200924-8bd8c2576d27/go.mod h1:f0X1c0za3TbET/rl5ThtCSel0+G3/yZ8iuU9BxnyVK0= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -630,11 +638,15 @@ github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZb github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= +github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= @@ -667,6 +679,14 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P github.com/mouuff/go-rocket-update v1.5.1 h1:qGgUu/MP+aVQ63laEguRNimmNTPKs29xz0lZW6QRFaQ= github.com/mouuff/go-rocket-update v1.5.1/go.mod h1:CnOyUYCxAJyC1g1mebSGC7gJysLTlX+RpxKgD1B0zLs= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs= +github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= @@ -780,6 +800,7 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -1042,6 +1063,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1131,6 +1154,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= From e12f475dd593ee960833e82e437184a77db705f2 Mon Sep 17 00:00:00 2001 From: Future Outlier Date: Sat, 18 Nov 2023 15:47:33 +0800 Subject: [PATCH 2/2] tabel v1 Signed-off-by: Future Outlier --- cmd/get/get.go | 132 ++++++++++++------------------------------------ cmd/get/task.go | 89 ++++++++++++++++++++++++++++++++ go.mod | 6 ++- go.sum | 7 ++- 4 files changed, 131 insertions(+), 103 deletions(-) diff --git a/cmd/get/get.go b/cmd/get/get.go index 234eb640..7c1b5ea1 100644 --- a/cmd/get/get.go +++ b/cmd/get/get.go @@ -1,12 +1,6 @@ package get import ( - "fmt" - "os" - "strings" - - tea "github.com/charmbracelet/bubbletea" - "github.com/fatih/color" "github.com/flyteorg/flytectl/cmd/config/subcommand/clusterresourceattribute" "github.com/flyteorg/flytectl/cmd/config/subcommand/execution" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionclusterlabel" @@ -23,87 +17,6 @@ import ( "github.com/spf13/cobra" ) -type model struct { - choices []string - cursor int - selected string -} - -var GetResourcesFuncs = map[string]cmdcore.CommandEntry{ - "project": {CmdFunc: getProjectsFunc, Aliases: []string{"projects"}, ProjectDomainNotRequired: true, - Short: projectShort, - Long: projectLong, PFlagProvider: project.DefaultConfig}, - "task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}, Short: taskShort, - Long: taskLong, PFlagProvider: task.DefaultConfig}, - "workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}, Short: workflowShort, - Long: workflowLong, PFlagProvider: workflow.DefaultConfig}, - "launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}, Short: launchPlanShort, - Long: launchPlanLong, PFlagProvider: launchplan.DefaultConfig}, - "execution": {CmdFunc: getExecutionFunc, Aliases: []string{"executions"}, Short: executionShort, - Long: executionLong, PFlagProvider: execution.DefaultConfig}, - "task-resource-attribute": {CmdFunc: getTaskResourceAttributes, Aliases: []string{"task-resource-attributes"}, - Short: taskResourceAttributesShort, - Long: taskResourceAttributesLong, PFlagProvider: taskresourceattribute.DefaultFetchConfig}, - "cluster-resource-attribute": {CmdFunc: getClusterResourceAttributes, Aliases: []string{"cluster-resource-attributes"}, - Short: clusterResourceAttributesShort, - Long: clusterResourceAttributesLong, PFlagProvider: clusterresourceattribute.DefaultFetchConfig}, - "execution-queue-attribute": {CmdFunc: getExecutionQueueAttributes, Aliases: []string{"execution-queue-attributes"}, - Short: executionQueueAttributesShort, - Long: executionQueueAttributesLong, PFlagProvider: executionqueueattribute.DefaultFetchConfig}, - "execution-cluster-label": {CmdFunc: getExecutionClusterLabel, Aliases: []string{"execution-cluster-labels"}, - Short: executionClusterLabelShort, - Long: executionClusterLabelLong, PFlagProvider: executionclusterlabel.DefaultFetchConfig}, - "plugin-override": {CmdFunc: getPluginOverridesFunc, Aliases: []string{"plugin-overrides"}, - Short: pluginOverrideShort, - Long: pluginOverrideLong, PFlagProvider: pluginoverride.DefaultFetchConfig}, - "workflow-execution-config": {CmdFunc: getWorkflowExecutionConfigFunc, Aliases: []string{"workflow-execution-config"}, - Short: workflowExecutionConfigShort, - Long: workflowExecutionConfigLong, PFlagProvider: workflowexecutionconfig.DefaultFetchConfig, ProjectDomainNotRequired: true}, -} - -func (m model) Init() tea.Cmd { - return nil -} - -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.String() { - case "up": - if m.cursor > 0 { - m.cursor-- - } - case "down": - if m.cursor < len(m.choices)-1 { - m.cursor++ - } - case "enter": - m.selected = m.choices[m.cursor] - fmt.Println("You selected:", m.selected) - // if cmdFunc, exists := GetResourcesFuncs[m.selected]; exists { - // cmdFunc[m.selected] - // } - - return m, tea.Quit - } - } - return m, nil -} - -func (m model) View() string { - var s strings.Builder - blue := color.New(color.FgBlue) - - for i, choice := range m.choices { - if i == m.cursor { - blue.Fprintf(&s, "> %s\n", choice) - } else { - fmt.Fprintf(&s, " %s\n", choice) - } - } - return s.String() -} - // Long descriptions are whitespace sensitive when generating docs using sphinx. const ( getCmdShort = `Fetches various Flyte resources such as tasks, workflows, launch plans, executions, and projects.` @@ -121,22 +34,41 @@ func CreateGetCommand() *cobra.Command { Use: "get", Short: getCmdShort, Long: getCmdLong, - Run: func(cmd *cobra.Command, args []string) { - p := tea.NewProgram(model{ - choices: []string{"project", "task", "workflow", "launchplan", - "task-resource-attribute", "cluster-resource-attribute", "execution-queue-attribute", - "execution-cluster-label", "plugin-override", "workflow-execution-config"}, - }) - if err := p.Start(); err != nil { - fmt.Fprintf(os.Stderr, "Error occurred: %v\n", err) - os.Exit(1) - } - }, } - fmt.Println("getCmd:", getCmd) + getResourcesFuncs := map[string]cmdcore.CommandEntry{ + "project": {CmdFunc: getProjectsFunc, Aliases: []string{"projects"}, ProjectDomainNotRequired: true, + Short: projectShort, + Long: projectLong, PFlagProvider: project.DefaultConfig}, + "task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}, Short: taskShort, + Long: taskLong, PFlagProvider: task.DefaultConfig}, + "workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}, Short: workflowShort, + Long: workflowLong, PFlagProvider: workflow.DefaultConfig}, + "launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}, Short: launchPlanShort, + Long: launchPlanLong, PFlagProvider: launchplan.DefaultConfig}, + "execution": {CmdFunc: getExecutionFunc, Aliases: []string{"executions"}, Short: executionShort, + Long: executionLong, PFlagProvider: execution.DefaultConfig}, + "task-resource-attribute": {CmdFunc: getTaskResourceAttributes, Aliases: []string{"task-resource-attributes"}, + Short: taskResourceAttributesShort, + Long: taskResourceAttributesLong, PFlagProvider: taskresourceattribute.DefaultFetchConfig}, + "cluster-resource-attribute": {CmdFunc: getClusterResourceAttributes, Aliases: []string{"cluster-resource-attributes"}, + Short: clusterResourceAttributesShort, + Long: clusterResourceAttributesLong, PFlagProvider: clusterresourceattribute.DefaultFetchConfig}, + "execution-queue-attribute": {CmdFunc: getExecutionQueueAttributes, Aliases: []string{"execution-queue-attributes"}, + Short: executionQueueAttributesShort, + Long: executionQueueAttributesLong, PFlagProvider: executionqueueattribute.DefaultFetchConfig}, + "execution-cluster-label": {CmdFunc: getExecutionClusterLabel, Aliases: []string{"execution-cluster-labels"}, + Short: executionClusterLabelShort, + Long: executionClusterLabelLong, PFlagProvider: executionclusterlabel.DefaultFetchConfig}, + "plugin-override": {CmdFunc: getPluginOverridesFunc, Aliases: []string{"plugin-overrides"}, + Short: pluginOverrideShort, + Long: pluginOverrideLong, PFlagProvider: pluginoverride.DefaultFetchConfig}, + "workflow-execution-config": {CmdFunc: getWorkflowExecutionConfigFunc, Aliases: []string{"workflow-execution-config"}, + Short: workflowExecutionConfigShort, + Long: workflowExecutionConfigLong, PFlagProvider: workflowexecutionconfig.DefaultFetchConfig, ProjectDomainNotRequired: true}, + } - cmdcore.AddCommands(getCmd, GetResourcesFuncs) + cmdcore.AddCommands(getCmd, getResourcesFuncs) return getCmd } diff --git a/cmd/get/task.go b/cmd/get/task.go index b5e1b13d..93142386 100644 --- a/cmd/get/task.go +++ b/cmd/get/task.go @@ -2,6 +2,8 @@ package get import ( "context" + "fmt" + "os" "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyte/flytestdlib/logger" @@ -11,8 +13,30 @@ import ( "github.com/flyteorg/flytectl/pkg/ext" "github.com/flyteorg/flytectl/pkg/printer" "github.com/golang/protobuf/proto" + + "github.com/charmbracelet/bubbles/table" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" ) +type model struct { + table table.Model +} + +func (m model) Init() tea.Cmd { return nil } + +func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + return m, tea.Quit +} + +func (m model) View() string { + return baseStyle.Render(m.table.View()) + "\n" +} + +var baseStyle = lipgloss.NewStyle(). + BorderStyle(lipgloss.NormalBorder()). + BorderForeground(lipgloss.Color("240")) + const ( taskShort = "Gets task resources" taskLong = ` @@ -142,6 +166,67 @@ func TaskToTableProtoMessages(l []*admin.Task) []proto.Message { return messages } +// TODO, the width need to be calculated based on the text width +func printBubbleTeaTable(tasks []*admin.Task) error { + columns := []table.Column{ + {Title: "Version", Width: 10}, + {Title: "Name", Width: 20}, + {Title: "Type", Width: 15}, + // {Title: "Inputs", Width: 30}, + // {Title: "Outputs", Width: 30}, + // {Title: "Discoverable", Width: 15}, + // {Title: "Discovery Version", Width: 20}, + // {Title: "Created At", Width: 25}, + } + + var rows []table.Row + for _, task := range tasks { + row := table.Row{ + task.Id.Version, + task.Id.Name, + task.Closure.CompiledTask.Template.Type, + // task.Closure.CompiledTask.Template.Interface.Inputs.Variables._formatted_descriptions.Description, + + // task.closure.compiledTask.template.type, + + // task.Id.Type, + // task.Closure.CompiledTask.Template.Type, + // task.Closure.CompiledTask.Template.Interface.Inputs.Variables, + // task.Closure.CompiledTask.Template.Interface.Outputs.Variables, + // task.Closure.CompiledTask.Template.Metadata.Discoverable, + // task.Closure.CompiledTask.Template.Metadata.DiscoveryVersion, + // task.Closure.CreatedAt, + } + rows = append(rows, row) + } + + t := table.New( + table.WithColumns(columns), + table.WithRows(rows), + table.WithFocused(true), + table.WithHeight(7), + ) + s := table.DefaultStyles() + s.Header = s.Header. + BorderStyle(lipgloss.NormalBorder()). + BorderForeground(lipgloss.Color("240")). + BorderBottom(true). + Bold(false) + s.Selected = s.Selected. + Foreground(lipgloss.Color("229")). + Background(lipgloss.Color("57")). + Bold(false) + t.SetStyles(s) + + m := model{t} + if _, err := tea.NewProgram(m).Run(); err != nil { + fmt.Println("Error running program:", err) + os.Exit(1) + } + + return nil +} + func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { taskPrinter := printer.Printer{} var tasks []*admin.Task @@ -161,6 +246,9 @@ func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandConte } tasks, err = cmdCtx.AdminFetcherExt().FetchAllVerOfTask(ctx, "", config.GetConfig().Project, config.GetConfig().Domain, taskConfig.DefaultConfig.Filter) + // fmt.Println("@@@", tasks) + return printBubbleTeaTable(tasks) + if err != nil { return err } @@ -168,6 +256,7 @@ func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandConte if config.GetConfig().MustOutputFormat() == printer.OutputFormatTABLE { return taskPrinter.Print(config.GetConfig().MustOutputFormat(), taskColumns, TaskToTableProtoMessages(tasks)...) } + return taskPrinter.Print(config.GetConfig().MustOutputFormat(), taskColumns, TaskToProtoMessages(tasks)...) } diff --git a/go.mod b/go.mod index bc3bf368..d6043ba2 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/apoorvam/goterminal v0.0.0-20180523175556-614d345c47e5 github.com/avast/retry-go v3.0.0+incompatible github.com/awalterschulze/gographviz v2.0.3+incompatible + github.com/charmbracelet/bubbles v0.16.1 github.com/charmbracelet/bubbletea v0.24.2 github.com/disiqueira/gotree v1.0.0 github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 github.com/enescakir/emoji v1.0.0 - github.com/fatih/color v1.13.0 github.com/flyteorg/flyte/flyteidl v1.9.12 github.com/flyteorg/flyte/flytepropeller v1.9.12 github.com/flyteorg/flyte/flytestdlib v1.9.12 @@ -73,6 +73,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/charmbracelet/lipgloss v0.7.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/containerd/containerd v1.5.10 // indirect github.com/coocood/freecache v1.1.1 // indirect @@ -82,9 +83,10 @@ require ( github.com/dnaeon/go-vcr v1.2.0 // indirect github.com/docker/distribution v2.8.0+incompatible // indirect github.com/docker/go-units v0.4.0 // indirect - github.com/dustin/go-humanize v1.0.0 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect + github.com/fatih/color v1.13.0 // indirect github.com/flyteorg/flyte/flyteplugins v0.0.0-00010101000000-000000000000 // indirect github.com/flyteorg/stow v0.3.7 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect diff --git a/go.sum b/go.sum index 48b3c066..08071ec3 100644 --- a/go.sum +++ b/go.sum @@ -163,8 +163,12 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= +github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= +github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= +github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= github.com/checkpoint-restore/go-criu/v4 v4.1.0/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw= github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= @@ -331,8 +335,9 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=