diff --git a/weed/shell/command_collection_delete.go b/weed/shell/command_collection_delete.go index ba635a090..02e142bc1 100644 --- a/weed/shell/command_collection_delete.go +++ b/weed/shell/command_collection_delete.go @@ -44,7 +44,7 @@ func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writ return nil } - handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, args, applyBalancingAlias, applyBalancing) infoAboutSimulationMode(writer, *applyBalancing, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil { diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.go index ea97739e1..760d1ed86 100644 --- a/weed/shell/command_ec_balance.go +++ b/weed/shell/command_ec_balance.go @@ -44,7 +44,7 @@ func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.W return nil } - handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, args, applyBalancingAlias, applyBalancing) infoAboutSimulationMode(writer, *applyBalancing, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil { diff --git a/weed/shell/command_ec_rebuild.go b/weed/shell/command_ec_rebuild.go index ef12b080a..d7eb04add 100644 --- a/weed/shell/command_ec_rebuild.go +++ b/weed/shell/command_ec_rebuild.go @@ -70,7 +70,7 @@ func (c *commandEcRebuild) Do(args []string, commandEnv *CommandEnv, writer io.W return nil } - handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, args, applyChangesAlias, applyChanges) infoAboutSimulationMode(writer, *applyChanges, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil { diff --git a/weed/shell/command_fs_configure.go b/weed/shell/command_fs_configure.go index e1fce8354..499cb1fbd 100644 --- a/weed/shell/command_fs_configure.go +++ b/weed/shell/command_fs_configure.go @@ -160,11 +160,19 @@ 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. +// handleDeprecatedForceFlag handles the deprecated -force flag by checking if it was +// explicitly provided (in any form), printing a deprecation warning, and copying its +// value to the new flag. This ensures that explicit -force=false takes precedence. // Returns true if the deprecated flag was used. -func handleDeprecatedForceFlag(writer io.Writer, forceAlias *bool, applyFlag *bool) bool { - if *forceAlias != false { +func handleDeprecatedForceFlag(writer io.Writer, args []string, forceAlias *bool, applyFlag *bool) bool { + forceIsSet := false + for _, arg := range args { + if arg == "-force" || strings.HasPrefix(arg, "-force=") { + forceIsSet = true + break + } + } + if forceIsSet { fmt.Fprintf(writer, "WARNING: -force is deprecated, please use -apply instead\n") *applyFlag = *forceAlias return true diff --git a/weed/shell/command_fs_meta_change_volume_id.go b/weed/shell/command_fs_meta_change_volume_id.go index f819652cf..860513363 100644 --- a/weed/shell/command_fs_meta_change_volume_id.go +++ b/weed/shell/command_fs_meta_change_volume_id.go @@ -57,7 +57,7 @@ func (c *commandFsMetaChangeVolumeId) Do(args []string, commandEnv *CommandEnv, return err } - handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, args, 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 31aff5572..9d9ef6d24 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -98,7 +98,7 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *CommandEnv, writer if err = balanceCommand.Parse(args); err != nil { return nil } - handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, args, 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 eb92ec6c0..a8cc8502a 100644 --- a/weed/shell/command_volume_check_disk.go +++ b/weed/shell/command_volume_check_disk.go @@ -129,7 +129,7 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write return nil } - handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, args, applyChangesAlias, applyChanges) infoAboutSimulationMode(writer, *applyChanges, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil { diff --git a/weed/shell/command_volume_delete_empty.go b/weed/shell/command_volume_delete_empty.go index 154f8942c..45df626cf 100644 --- a/weed/shell/command_volume_delete_empty.go +++ b/weed/shell/command_volume_delete_empty.go @@ -48,7 +48,7 @@ func (c *commandVolumeDeleteEmpty) Do(args []string, commandEnv *CommandEnv, wri return nil } - handleDeprecatedForceFlag(writer, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, args, applyBalancingAlias, applyBalancing) infoAboutSimulationMode(writer, *applyBalancing, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil { diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index 0cae31c55..3e3429908 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -79,7 +79,7 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, return nil } - handleDeprecatedForceFlag(writer, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, args, applyChangesAlias, applyChanges) infoAboutSimulationMode(writer, *applyChanges, "-apply") commandEnv.noLock = !*applyChanges diff --git a/weed/shell/command_volume_server_evacuate.go b/weed/shell/command_volume_server_evacuate.go index 06e43b2e5..095ad6d5c 100644 --- a/weed/shell/command_volume_server_evacuate.go +++ b/weed/shell/command_volume_server_evacuate.go @@ -66,7 +66,7 @@ func (c *commandVolumeServerEvacuate) Do(args []string, commandEnv *CommandEnv, return nil } - handleDeprecatedForceFlag(writer, applyChangeAlias, applyChange) + handleDeprecatedForceFlag(writer, args, applyChangeAlias, applyChange) infoAboutSimulationMode(writer, *applyChange, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil && *applyChange { diff --git a/weed/shell/command_volume_tier_move.go b/weed/shell/command_volume_tier_move.go index 1cdb98f0a..9a676f134 100644 --- a/weed/shell/command_volume_tier_move.go +++ b/weed/shell/command_volume_tier_move.go @@ -76,7 +76,7 @@ func (c *commandVolumeTierMove) Do(args []string, commandEnv *CommandEnv, writer return nil } - handleDeprecatedForceFlag(writer, applyChangeAlias, applyChange) + handleDeprecatedForceFlag(writer, args, applyChangeAlias, applyChange) infoAboutSimulationMode(writer, *applyChange, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil {