Browse Source

Refactoring]: Using flag.FlagSet.Visit()

pull/7450/head
chrislu 2 months ago
parent
commit
c267c216a0
  1. 2
      weed/shell/command_collection_delete.go
  2. 2
      weed/shell/command_ec_balance.go
  3. 2
      weed/shell/command_ec_rebuild.go
  4. 15
      weed/shell/command_fs_configure.go
  5. 2
      weed/shell/command_fs_meta_change_volume_id.go
  6. 2
      weed/shell/command_volume_balance.go
  7. 2
      weed/shell/command_volume_check_disk.go
  8. 4
      weed/shell/command_volume_delete_empty.go
  9. 2
      weed/shell/command_volume_fix_replication.go
  10. 2
      weed/shell/command_volume_server_evacuate.go
  11. 2
      weed/shell/command_volume_tier_move.go

2
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 {

2
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 {

2
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 {

15
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
}

2
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)

2
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

2
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 {

4
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 {

2
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

2
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 {

2
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 {

Loading…
Cancel
Save