diff --git a/weed/shell/command_collection_delete.go b/weed/shell/command_collection_delete.go index 02e142bc1..92473e8e3 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, args, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, colDeleteCommand, 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 760d1ed86..935348602 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, args, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, balanceCommand, 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 d7eb04add..bef56d191 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, args, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, fixCommand, 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 499cb1fbd..547879f43 100644 --- a/weed/shell/command_fs_configure.go +++ b/weed/shell/command_fs_configure.go @@ -161,21 +161,18 @@ func infoAboutSimulationMode(writer io.Writer, forceMode bool, forceModeOption s } // handleDeprecatedForceFlag handles the deprecated -force flag by checking if it was -// explicitly provided (in any form), printing a deprecation warning, and copying its +// explicitly provided, 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, args []string, forceAlias *bool, applyFlag *bool) bool { +func handleDeprecatedForceFlag(writer io.Writer, fs *flag.FlagSet, forceAlias *bool, applyFlag *bool) { forceIsSet := false - for _, arg := range args { - if arg == "-force" || strings.HasPrefix(arg, "-force=") { + fs.Visit(func(f *flag.Flag) { + if f.Name == "force" { forceIsSet = true - break } - } + }) + if forceIsSet { 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 860513363..f219d2d06 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, args, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, fsMetaChangeVolumeIdCommand, 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 9d9ef6d24..88058807f 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, args, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, balanceCommand, 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 a8cc8502a..2abfc288c 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, args, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, fsckCommand, 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 45df626cf..9cf5f99ac 100644 --- a/weed/shell/command_volume_delete_empty.go +++ b/weed/shell/command_volume_delete_empty.go @@ -43,12 +43,12 @@ func (c *commandVolumeDeleteEmpty) Do(args []string, commandEnv *CommandEnv, wri quietPeriod := volDeleteCommand.Duration("quietFor", 24*time.Hour, "select empty volumes with no recent writes, avoid newly created ones") applyBalancing := volDeleteCommand.Bool("apply", false, "apply to delete empty volumes") // TODO: remove this alias - applyBalancingAlias := volDeleteCommand.Bool("force", false, "apply the balancing plan (alias for -apply)") + applyBalancingAlias := volDeleteCommand.Bool("force", false, "apply to delete empty volumes (alias for -apply)") if err = volDeleteCommand.Parse(args); err != nil { return nil } - handleDeprecatedForceFlag(writer, args, applyBalancingAlias, applyBalancing) + handleDeprecatedForceFlag(writer, volDeleteCommand, 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 3e3429908..29bfe3f76 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, args, applyChangesAlias, applyChanges) + handleDeprecatedForceFlag(writer, volFixReplicationCommand, 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 095ad6d5c..5c1805c89 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, args, applyChangeAlias, applyChange) + handleDeprecatedForceFlag(writer, vsEvacuateCommand, 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 9a676f134..3f8d2fc2e 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, args, applyChangeAlias, applyChange) + handleDeprecatedForceFlag(writer, tierCommand, applyChangeAlias, applyChange) infoAboutSimulationMode(writer, *applyChange, "-apply") if err = commandEnv.confirmIsLocked(args); err != nil {