mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Provide available workloads in help message
Print all available workloads, like containerized, deployments.apps, statefulsets.apps to help user to choose one of them.
This commit is contained in:
@@ -3,9 +3,9 @@ package run
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
|
||||
|
||||
@@ -35,6 +35,26 @@ func NewCmdRun(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
var workloadDefs corev1alpha2.WorkloadDefinitionList
|
||||
err := c.List(ctx, &workloadDefs)
|
||||
if err != nil {
|
||||
fmt.Println("list workload Definition err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var workloadShortNames []string
|
||||
|
||||
workloadDefsItem := workloadDefs.Items
|
||||
|
||||
for _, wd := range workloadDefsItem {
|
||||
n := wd.ObjectMeta.Annotations["short"]
|
||||
if n == "" {
|
||||
n = wd.Name
|
||||
}
|
||||
workloadShortNames = append(workloadShortNames, n)
|
||||
wd.ObjectMeta.Annotations["short"] = n
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "run [WORKLOAD_KIND] [args]",
|
||||
DisableFlagsInUseLine: true,
|
||||
@@ -43,18 +63,15 @@ func NewCmdRun(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOStreams)
|
||||
Example: `
|
||||
rudrx run containerized frontend -p 80 oam-dev/demo:v1
|
||||
`,
|
||||
//Run: func(cmd *cobra.Command, args []string) {
|
||||
// cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
// cmdutil.CheckErr(o.Run(f, cmd))
|
||||
//},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
fmt.Println("You must specify a workload, like " + strings.Join(workloadShortNames, ", ") +
|
||||
"\nSee 'rudr run -h' for help and examples")
|
||||
}
|
||||
},
|
||||
}
|
||||
var workloadDefs corev1alpha2.WorkloadDefinitionList
|
||||
err := c.List(ctx, &workloadDefs)
|
||||
if err != nil {
|
||||
fmt.Println("list workload Definition err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, wd := range workloadDefs.Items {
|
||||
|
||||
for _, wd := range workloadDefsItem {
|
||||
templateRef, ok := wd.ObjectMeta.Annotations["defatultTemplateRef"]
|
||||
if !ok {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user