github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/plugin/describe.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package plugin 21 22 import ( 23 "fmt" 24 "io" 25 26 "github.com/spf13/cobra" 27 "k8s.io/cli-runtime/pkg/genericiooptions" 28 cmdutil "k8s.io/kubectl/pkg/cmd/util" 29 "k8s.io/kubectl/pkg/util/templates" 30 ) 31 32 var pluginDescribeExample = templates.Examples(` 33 # Describe a plugin 34 kbcli plugin describe [PLUGIN] 35 36 # Describe a plugin with index 37 kbcli plugin describe [INDEX/PLUGIN] 38 `) 39 40 func NewPluginDescribeCmd(streams genericiooptions.IOStreams) *cobra.Command { 41 cmd := &cobra.Command{ 42 Use: "describe", 43 Short: "Describe a plugin", 44 Example: pluginDescribeExample, 45 Args: cobra.ExactArgs(1), 46 Run: func(cmd *cobra.Command, args []string) { 47 cmdutil.CheckErr(printPluginInfo(streams.Out, args[0])) 48 }, 49 } 50 return cmd 51 } 52 53 func printPluginInfo(out io.Writer, name string) error { 54 indexName, pluginName := CanonicalPluginName(name) 55 plugin, err := LoadPluginByName(paths.IndexPluginsPath(indexName), pluginName) 56 if err != nil { 57 return err 58 } 59 60 fmt.Fprintf(out, "NAME: %s\n", plugin.Name) 61 fmt.Fprintf(out, "INDEX: %s\n", indexName) 62 if platform, ok, err := GetMatchingPlatform(plugin.Spec.Platforms); err == nil && ok { 63 if platform.URI != "" { 64 fmt.Fprintf(out, "URI: %s\n", platform.URI) 65 fmt.Fprintf(out, "SHA256: %s\n", platform.Sha256) 66 } 67 } 68 if plugin.Spec.Version != "" { 69 fmt.Fprintf(out, "VERSION: %s\n", plugin.Spec.Version) 70 } 71 if plugin.Spec.Homepage != "" { 72 fmt.Fprintf(out, "HOMEPAGE: %s\n", plugin.Spec.Homepage) 73 } 74 if plugin.Spec.Description != "" { 75 fmt.Fprintf(out, "DESCRIPTION: \n%s\n", plugin.Spec.Description) 76 } 77 if plugin.Spec.Caveats != "" { 78 fmt.Fprintf(out, "CAVEATS:\n%s\n", indent(plugin.Spec.Caveats)) 79 } 80 return nil 81 }