From 87249427796a91d23cacf67fb563e851a876764a Mon Sep 17 00:00:00 2001 From: chrislu Date: Sun, 9 Nov 2025 13:59:57 -0800 Subject: [PATCH] refactor --- weed/shell/command_collection_delete.go | 6 ++---- weed/shell/command_ec_balance.go | 5 +---- weed/shell/command_ec_rebuild.go | 5 +---- weed/shell/command_fs_configure.go | 12 ++++++++++++ weed/shell/command_fs_meta_change_volume_id.go | 5 +---- weed/shell/command_volume_balance.go | 5 +---- weed/shell/command_volume_check_disk.go | 5 +---- weed/shell/command_volume_delete_empty.go | 6 +----- weed/shell/command_volume_fix_replication.go | 5 +---- weed/shell/command_volume_server_evacuate.go | 5 +---- weed/shell/command_volume_tier_move.go | 5 +---- 11 files changed, 23 insertions(+), 41 deletions(-) diff --git a/weed/shell/command_collection_delete.go b/weed/shell/command_collection_delete.go index 6e85773d7..04f07035d 100644 --- a/weed/shell/command_collection_delete.go +++ b/weed/shell/command_collection_delete.go @@ -49,10 +49,8 @@ func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writ return } - if *applyBalancingAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyBalancing = *applyBalancingAlias - } + handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) + if *collectionName == "" { return fmt.Errorf("empty collection name is not allowed") } diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.go index c95c24780..1ab0713dc 100644 --- a/weed/shell/command_ec_balance.go +++ b/weed/shell/command_ec_balance.go @@ -49,10 +49,7 @@ func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.W return } - if *applyBalancingAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyBalancing = *applyBalancingAlias - } + handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) var collections []string if *collection == "EACH_COLLECTION" { diff --git a/weed/shell/command_ec_rebuild.go b/weed/shell/command_ec_rebuild.go index e309299a6..fa7e5a4ee 100644 --- a/weed/shell/command_ec_rebuild.go +++ b/weed/shell/command_ec_rebuild.go @@ -75,10 +75,7 @@ func (c *commandEcRebuild) Do(args []string, commandEnv *CommandEnv, writer io.W return } - if *applyChangesAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChanges = *applyChangesAlias - } + handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) // collect all ec nodes allEcNodes, _, err := collectEcNodes(commandEnv) diff --git a/weed/shell/command_fs_configure.go b/weed/shell/command_fs_configure.go index c27c6c7b5..e1fce8354 100644 --- a/weed/shell/command_fs_configure.go +++ b/weed/shell/command_fs_configure.go @@ -159,3 +159,15 @@ func infoAboutSimulationMode(writer io.Writer, forceMode bool, forceModeOption s } fmt.Fprintf(writer, "Running in simulation mode. Use \"%s\" option to apply the changes.\n", forceModeOption) } + +// handleDeprecatedForceFlag handles the deprecated -force flag by checking if it's set, +// printing a deprecation warning, and copying its value to the new flag. +// Returns true if the deprecated flag was used. +func handleDeprecatedForceFlag(writer io.Writer, forceAlias *bool, applyFlag *bool) bool { + if *forceAlias != false { + fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") + *applyFlag = *forceAlias + return true + } + return false +} diff --git a/weed/shell/command_fs_meta_change_volume_id.go b/weed/shell/command_fs_meta_change_volume_id.go index 2b6d1e725..f819652cf 100644 --- a/weed/shell/command_fs_meta_change_volume_id.go +++ b/weed/shell/command_fs_meta_change_volume_id.go @@ -57,10 +57,7 @@ func (c *commandFsMetaChangeVolumeId) Do(args []string, commandEnv *CommandEnv, return err } - if *applyChangesAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChanges = *applyChangesAlias - } + handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) // load the mapping mapping := make(map[needle.VolumeId]needle.VolumeId) diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 55596930d..31aff5572 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -98,10 +98,7 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *CommandEnv, writer if err = balanceCommand.Parse(args); err != nil { return nil } - if *applyBalancingAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyBalancing = *applyBalancingAlias - } + handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) c.writable = *writable c.applyBalancing = *applyBalancing diff --git a/weed/shell/command_volume_check_disk.go b/weed/shell/command_volume_check_disk.go index 6a955f42f..ce7c2348d 100644 --- a/weed/shell/command_volume_check_disk.go +++ b/weed/shell/command_volume_check_disk.go @@ -134,10 +134,7 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write return } - if *applyChangesAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChanges = *applyChangesAlias - } + handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) c.env = commandEnv c.writer = writer diff --git a/weed/shell/command_volume_delete_empty.go b/weed/shell/command_volume_delete_empty.go index d7d9da4f6..579a0e76b 100644 --- a/weed/shell/command_volume_delete_empty.go +++ b/weed/shell/command_volume_delete_empty.go @@ -2,7 +2,6 @@ package shell import ( "flag" - "fmt" "io" "log" "time" @@ -53,10 +52,7 @@ func (c *commandVolumeDeleteEmpty) Do(args []string, commandEnv *CommandEnv, wri if err = commandEnv.confirmIsLocked(args); err != nil { return } - if *applyBalancingAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyBalancing = *applyBalancingAlias - } + handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) // collect topology information topologyInfo, _, err := collectTopologyInfo(commandEnv, 0) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index e24f83f52..2588b0a21 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -80,10 +80,7 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, } infoAboutSimulationMode(writer, *applyChanges, "-apply") - if *applyChangesAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChanges = *applyChangesAlias - } + handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) commandEnv.noLock = !*applyChanges if err = commandEnv.confirmIsLocked(args); *applyChanges && err != nil { diff --git a/weed/shell/command_volume_server_evacuate.go b/weed/shell/command_volume_server_evacuate.go index 18328a103..c56823cd4 100644 --- a/weed/shell/command_volume_server_evacuate.go +++ b/weed/shell/command_volume_server_evacuate.go @@ -71,10 +71,7 @@ func (c *commandVolumeServerEvacuate) Do(args []string, commandEnv *CommandEnv, return } - if *applyChangeAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChange = *applyChangeAlias - } + handleDeprecatedForceFlag(writer, applyChangeAlias, applyChange) if *volumeServer == "" && *c.volumeRack == "" { return fmt.Errorf("need to specify volume server by -node=: or source rack") } diff --git a/weed/shell/command_volume_tier_move.go b/weed/shell/command_volume_tier_move.go index 3c20d0854..63ddb6f91 100644 --- a/weed/shell/command_volume_tier_move.go +++ b/weed/shell/command_volume_tier_move.go @@ -81,10 +81,7 @@ func (c *commandVolumeTierMove) Do(args []string, commandEnv *CommandEnv, writer return } - if *applyChangeAlias != false { - fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") - *applyChange = *applyChangeAlias - } + handleDeprecatedForceFlag(writer, applyChangeAlias, applyChange) fromDiskType := types.ToDiskType(*source) toDiskType := types.ToDiskType(*target)