mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-13 23:39:33 +01:00
* shell: return flag parse errors from every command 48 commands returned nil when their flags failed to parse, so a mistyped flag printed the flag error but the command still counted as a success: a piped weed shell run exited 0, the master maintenance loop logged no error, and admin script jobs reported the line as done. Return the parse error as s3.bucket.create (#12544) and the other shell commands already do. TestCommandsReturnFlagParseErrors runs every registered command with an unknown flag and fails for the 48 on master. Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com> * shell: don't report -h as a failure With the parse errors returned, -h on those commands now returns flag.ErrHelp, so the shell printed "error: flag: help requested" and a piped run exited 1. The flag package has already printed the usage, so processEachCmd now treats flag.ErrHelp as success for every command. Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com> * shell: keep the -h test beside the flag parse test TestProcessEachCmdTreatsHelpAsSuccess covers the same change as TestCommandsReturnFlagParseErrors, so it lives in the same new file and shell_liner_test.go stays as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com> Co-authored-by: anant <170962632+antcybersec@users.noreply.github.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandCollectionDelete{})
|
|
}
|
|
|
|
type commandCollectionDelete struct {
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Name() string {
|
|
return "collection.delete"
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Help() string {
|
|
return `delete specified collection
|
|
|
|
collection.delete -collection <collection_name> -apply
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandCollectionDelete) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandCollectionDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
colDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
collectionName := colDeleteCommand.String("collection", "", "collection to delete. Use '"+CollectionDefault+"' for the empty-named collection.")
|
|
applyBalancing := colDeleteCommand.Bool("apply", false, "apply the collection")
|
|
// TODO: remove this alias
|
|
applyBalancingAlias := colDeleteCommand.Bool("force", false, "apply the collection (alias for -apply)")
|
|
|
|
if err = colDeleteCommand.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
handleDeprecatedForceFlag(writer, colDeleteCommand, applyBalancingAlias, applyBalancing)
|
|
infoAboutSimulationMode(writer, *applyBalancing, "-apply")
|
|
|
|
if err = commandEnv.confirmIsLocked(args); err != nil {
|
|
return
|
|
}
|
|
|
|
if *collectionName == "" {
|
|
return fmt.Errorf("empty collection name is not allowed")
|
|
}
|
|
|
|
// The legacy "_default_" spelling stays accepted for compatibility;
|
|
// CollectionDefault is the shared keyword every other -collection flag
|
|
// uses for the empty-named collection.
|
|
if *collectionName == CollectionDefault+"_" {
|
|
*collectionName = ""
|
|
}
|
|
*collectionName = resolveCollectionName(*collectionName)
|
|
|
|
if !*applyBalancing {
|
|
fmt.Fprintf(writer, "collection '%s' will be deleted. Use -apply to apply the change.\n", *collectionName)
|
|
return nil
|
|
}
|
|
|
|
err = commandEnv.MasterClient.WithClient(context.Background(), false, func(client master_pb.SeaweedClient) error {
|
|
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
|
Name: *collectionName,
|
|
})
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
fmt.Fprintf(writer, "collection %s is deleted.\n", *collectionName)
|
|
|
|
return nil
|
|
}
|