mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00
system connection remove: use Args function to validate
Using the ExactArgs(1) function is better because we have less duplication of the error text and the ValidArgsFunction uses that to suggest shell completion. The command before this commit would suggest connection names even if there was already one arg on the cli set. However because there is the --all option we still must exclude that first. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package connection
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
"github.com/containers/common/pkg/config"
|
||||
@ -18,6 +17,12 @@ var (
|
||||
Aliases: []string{"rm"},
|
||||
Long: `Delete named destination from podman configuration`,
|
||||
Short: "Delete named destination",
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if rmOpts.All {
|
||||
return nil
|
||||
}
|
||||
return cobra.ExactArgs(1)(cmd, args)
|
||||
},
|
||||
ValidArgsFunction: common.AutocompleteSystemConnections,
|
||||
RunE: rm,
|
||||
Example: `podman system connection remove devl
|
||||
@ -60,10 +65,6 @@ func rm(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) != 1 {
|
||||
return errors.New("accepts 1 arg(s), received 0")
|
||||
}
|
||||
|
||||
delete(cfg.Connection.Connections, args[0])
|
||||
if cfg.Connection.Default == args[0] {
|
||||
cfg.Connection.Default = ""
|
||||
|
Reference in New Issue
Block a user