Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system connection remove: use Args function to validate #23326

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions cmd/podman/system/connection/remove.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package connection

import (
"errors"
"slices"

"github.com/containers/common/pkg/config"
Expand All @@ -14,10 +13,16 @@ import (
var (
// Skip creating engines since this command will obtain connection information to said engines.
rmCmd = &cobra.Command{
Use: "remove [options] NAME",
Aliases: []string{"rm"},
Long: `Delete named destination from podman configuration`,
Short: "Delete named destination",
Use: "remove [options] NAME",
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
Expand Down Expand Up @@ -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 = ""
Expand Down