Skip to content

Commit

Permalink
system connection remove: use Args function to validate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Luap99 committed Jul 18, 2024
1 parent eecdba4 commit 85f4f89
Showing 1 changed file with 10 additions and 9 deletions.
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

0 comments on commit 85f4f89

Please sign in to comment.