fix(flashnode): valid args for fla flashnode list#1000020535

Signed-off-by: clinx <chenlin1@oppo.com>
This commit is contained in:
clinx 2025-03-26 16:25:14 +08:00 committed by zhumingze1108
parent 5584dfe034
commit 3c67ab500b
2 changed files with 15 additions and 10 deletions

View File

@ -143,16 +143,19 @@ func newCmdFlashNodeGet(client *master.MasterClient) *cobra.Command {
}
func newCmdFlashNodeList(client *master.MasterClient) *cobra.Command {
var showActiveFlashNodes bool
cmd := &cobra.Command{
Use: CliOpList,
ValidArgs: []string{"true", "false"},
Short: "list all flash nodes or [active true/false] flash nodes",
Args: cobra.MinimumNArgs(0),
return &cobra.Command{
Use: CliOpList,
Short: "list all flash nodes or [active true/false] flash nodes",
Args: cobra.MinimumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
var active bool
activeFilter := -1
if len(args) == 1 {
if showActiveFlashNodes {
if active, err = strconv.ParseBool(args[0]); err != nil {
err = fmt.Errorf("Parse bool fail: %v\n", err)
return
}
if active {
activeFilter = 1
} else {
activeFilter = 0
@ -162,7 +165,7 @@ func newCmdFlashNodeList(client *master.MasterClient) *cobra.Command {
if err != nil {
return
}
stdoutln("[FlashNodes]")
stdoutln(fmt.Sprintf("[FlashNodes] active:%d", activeFilter))
tbl := table{formatFlashNodeViewTableTitle}
for _, flashNodeViewInfos := range zoneFlashNodes {
tbl = showFlashNodesView(flashNodeViewInfos, true, tbl)
@ -171,8 +174,6 @@ func newCmdFlashNodeList(client *master.MasterClient) *cobra.Command {
return
},
}
cmd.Flags().BoolVar(&showActiveFlashNodes, "active", true, "show flashnodes only contain inactive or active")
return cmd
}
func newCmdFlashNodeHTTPStat(client *master.MasterClient) *cobra.Command {

View File

@ -105,4 +105,8 @@ func testFlashNodeList(t *testing.T) {
require.Equal(t, 2, len(zoneNodes[testZone1]))
require.Equal(t, 2, len(zoneNodes[testZone2]))
require.Equal(t, 2, len(zoneNodes[testZone3]))
zoneNodes, err = mc.NodeAPI().ListFlashNodes(0)
require.NoError(t, err)
require.Equal(t, 1, len(zoneNodes[testZone3]))
}