From 7f1536911b284f7135af13d31b64e34e47c3115a Mon Sep 17 00:00:00 2001 From: jennijuju Date: Mon, 21 Sep 2020 21:41:17 -0400 Subject: [PATCH] When doing `sectors update-state`, show a list of existing states if user inputs an invalid one. --- cmd/lotus-storage-miner/sectors.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 438aaad0d97..8232fc86400 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/fatih/color" "os" "sort" "strconv" @@ -403,8 +404,9 @@ var sectorsCapacityCollateralCmd = &cli.Command{ } var sectorsUpdateCmd = &cli.Command{ - Name: "update-state", - Usage: "ADVANCED: manually update the state of a sector, this may aid in error recovery", + Name: "update-state", + Usage: "ADVANCED: manually update the state of a sector, this may aid in error recovery", + ArgsUsage: " ", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "really-do-it", @@ -430,8 +432,14 @@ var sectorsUpdateCmd = &cli.Command{ return xerrors.Errorf("could not parse sector number: %w", err) } - if _, ok := sealing.ExistSectorStateList[sealing.SectorState(cctx.Args().Get(1))]; !ok { - return xerrors.Errorf("Not existing sector state") + newState := cctx.Args().Get(1) + if _, ok := sealing.ExistSectorStateList[sealing.SectorState(newState)]; !ok { + bold := color.New(color.Bold).SprintFunc() + fmt.Printf("%s is not a valid state. Possible states for sectors are: \n", bold(newState)) + for state := range sealing.ExistSectorStateList { + fmt.Printf("%s\n", string(state)) + } + return nil } return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), api.SectorState(cctx.Args().Get(1)))