mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
address Wonderflow's offline advice
This commit is contained in:
@@ -25,7 +25,7 @@ var _ = ginkgo.Describe("Application", func() {
|
||||
workloadType, applicationName))
|
||||
e2e.ComponentListContext("ls", applicationName, "")
|
||||
e2e.TraitManualScalerAttachContext("vela attach scaler trait", traitAlias, applicationName)
|
||||
e2e.ApplicationShowContext("app show", applicationName, workloadType)
|
||||
e2e.ApplicationShowContext("show", applicationName, workloadType)
|
||||
e2e.ApplicationStatusContext("app status", applicationName, workloadType)
|
||||
e2e.ApplicationCompStatusContext("svc status", applicationName, workloadType, envName)
|
||||
e2e.ApplicationExecContext("exec -- COMMAND", applicationName)
|
||||
|
||||
@@ -218,7 +218,7 @@ var (
|
||||
ApplicationShowContext = func(context string, applicationName string, workloadType string) bool {
|
||||
return ginkgo.Context(context, func() {
|
||||
ginkgo.It("should show app information", func() {
|
||||
cli := fmt.Sprintf("vela app show %s", applicationName)
|
||||
cli := fmt.Sprintf("vela show %s", applicationName)
|
||||
output, err := Exec(cli)
|
||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||
// TODO(zzxwill) need to check workloadType after app show is refined
|
||||
|
||||
+34
-22
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/gosuri/uitable"
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
@@ -12,8 +14,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const DefaultChosenSvc = "ALL SERVICES"
|
||||
|
||||
func NewAppShowCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "show <APPLICATION-NAME>",
|
||||
@@ -50,26 +50,43 @@ func showApplication(cmd *cobra.Command, env *types.EnvMeta, appName string) err
|
||||
return err
|
||||
}
|
||||
|
||||
var chosenSvc string
|
||||
var validInputtedSvc bool
|
||||
inputtedSvc := cmd.Flag("svc").Value.String()
|
||||
|
||||
var svcFlag, chosenSvc string
|
||||
var svcFlagStatus string
|
||||
// to store the value of flag `--svc` set in Cli, or selected value in survey
|
||||
var targetServices []string
|
||||
if svcFlag = cmd.Flag("svc").Value.String(); svcFlag == "" {
|
||||
svcFlagStatus = oam.FlagNotSet
|
||||
} else {
|
||||
svcFlagStatus = oam.FlagIsInvalid
|
||||
}
|
||||
// all services name of the application `appName`
|
||||
var services []string
|
||||
for svcName := range app.Services {
|
||||
services = append(services, svcName)
|
||||
if inputtedSvc == svcName {
|
||||
validInputtedSvc = true
|
||||
if svcFlag == svcName {
|
||||
svcFlagStatus = oam.FlagIsValid
|
||||
targetServices = append(targetServices, svcName)
|
||||
}
|
||||
}
|
||||
|
||||
if inputtedSvc != "" && !validInputtedSvc || inputtedSvc == "" && len(services) > 1 {
|
||||
if inputtedSvc != "" && !validInputtedSvc {
|
||||
cmd.Printf("The service name '%s' is not valid\n", inputtedSvc)
|
||||
totalServices := len(services)
|
||||
if svcFlagStatus == oam.FlagNotSet && totalServices == 1 {
|
||||
targetServices = services
|
||||
}
|
||||
if svcFlagStatus == oam.FlagIsInvalid || (svcFlagStatus == oam.FlagNotSet && totalServices > 1) {
|
||||
if svcFlagStatus == oam.FlagIsInvalid {
|
||||
cmd.Printf("The service name '%s' is not valid\n", svcFlag)
|
||||
}
|
||||
chosenSvc, err = chooseSvc(services)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if chosenSvc == oam.DefaultChosenAllSvc {
|
||||
targetServices = services
|
||||
} else {
|
||||
targetServices = targetServices[:0]
|
||||
targetServices = append(targetServices, chosenSvc)
|
||||
}
|
||||
}
|
||||
|
||||
cmd.Printf("About:\n\n")
|
||||
@@ -87,14 +104,9 @@ func showApplication(cmd *cobra.Command, env *types.EnvMeta, appName string) err
|
||||
table = uitable.New()
|
||||
cmd.Printf("Services:\n\n")
|
||||
|
||||
for svcName := range app.Services {
|
||||
if inputtedSvc != "" && validInputtedSvc && svcName == inputtedSvc ||
|
||||
inputtedSvc != "" && !validInputtedSvc && (svcName == chosenSvc || chosenSvc == DefaultChosenSvc) ||
|
||||
inputtedSvc == "" && len(services) == 1 ||
|
||||
inputtedSvc == "" && len(services) > 1 && (svcName == chosenSvc || chosenSvc == DefaultChosenSvc) {
|
||||
if err := showComponent(cmd, env, svcName, appName); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, svcName := range targetServices {
|
||||
if err := showComponent(cmd, env, svcName, appName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cmd.Println(table.String())
|
||||
@@ -151,11 +163,11 @@ func showComponent(cmd *cobra.Command, env *types.EnvMeta, compName, appName str
|
||||
|
||||
func chooseSvc(services []string) (string, error) {
|
||||
var svcName string
|
||||
services = append(services, DefaultChosenSvc)
|
||||
services = append(services, oam.DefaultChosenAllSvc)
|
||||
prompt := &survey.Select{
|
||||
Message: "Please choose one service: ",
|
||||
Options: services,
|
||||
Default: DefaultChosenSvc,
|
||||
Default: oam.DefaultChosenAllSvc,
|
||||
}
|
||||
err := survey.AskOne(prompt, &svcName)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,6 +17,13 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultChosenAllSvc = "ALL SERVICES"
|
||||
FlagNotSet = "FlagNotSet"
|
||||
FlagIsInvalid = "FlagIsInvalid"
|
||||
FlagIsValid = "FlagIsValid"
|
||||
)
|
||||
|
||||
type componentMetaList []apis.ComponentMeta
|
||||
type ApplicationMetaList []apis.ApplicationMeta
|
||||
|
||||
|
||||
Reference in New Issue
Block a user