Skip to content

Commit ab0f578

Browse files
committed
fix: add error checking and update description for InstallCommand
- Add error checking for missing `app` or `ns` inputs in the `PreRunE` function - Add error checking for missing tool name in the `PreRunE` function - Update the short description of the `InstallCommand` to include new tools: `etcdctl, mc, dnsctl` Signed-off-by: ysicing <[email protected]>
1 parent de8fcfb commit ab0f578

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

cmd/backup/app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/cockroachdb/errors"
1314
"github.com/spf13/cobra"
1415

1516
"github.com/easysoft/qcadmin/internal/api/cne"
@@ -24,6 +25,12 @@ func NewCmdBackupApp(f factory.Factory) *cobra.Command {
2425
Use: "app",
2526
Short: "backup app",
2627
Long: "backup app",
28+
PreRunE: func(cmd *cobra.Command, args []string) error {
29+
if len(app) == 0 || len(ns) == 0 {
30+
return errors.New("missing app or ns")
31+
}
32+
return nil
33+
},
2734
Run: func(cmd *cobra.Command, args []string) {
2835
log.Infof("start backup app: %s", app)
2936
cneClient := cne.NewCneAPI()

cmd/experimental/install.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,30 @@ var (
2222
installExample = templates.Examples(`
2323
# install tools
2424
z experimental install helm`)
25+
installTools = map[string]any{
26+
"helm": true,
27+
"kubectl": true,
28+
"mc": true,
29+
"etcdctl": true,
30+
"dnsctl": true,
31+
}
2532
)
2633

2734
// InstallCommand install some tools
2835
func InstallCommand(f factory.Factory) *cobra.Command {
2936
installCmd := &cobra.Command{
3037
Use: "install [flags]",
31-
Short: "install tools, like: helm, kubectl",
38+
Short: "install tools, like: helm, kubectl,etcdctl,mc,dnsctl",
3239
Example: installExample,
3340
Args: cobra.MinimumNArgs(1),
3441
PreRunE: func(cmd *cobra.Command, args []string) error {
3542
if len(args) < 1 {
3643
f.GetLog().Fatalf("args error: %v", args)
37-
return errors.New("missing args: helm or kubectl")
44+
return errors.New("missing args: tool name")
3845
}
3946
tool := args[0]
40-
if tool != "helm" && tool != "kubectl" && tool != "etcdctl" && tool != "mc" {
41-
// TODO add more tools
42-
return errors.Errorf("not support tool: %s, only suppor helm, kubectl, etcdctl", tool)
47+
if _, exist := installTools[tool]; !exist {
48+
return errors.Errorf("not support tool: %s", tool)
4349
}
4450
return nil
4551
},

0 commit comments

Comments
 (0)