spiegel_podman/cmd/podman/networks/exists.go
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00

38 lines
1 KiB
Go

package network
import (
"github.com/containers/podman/v5/cmd/podman/common"
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/spf13/cobra"
)
var (
networkExistsDescription = `If the named network exists, podman network exists exits with 0, otherwise the exit code will be 1.`
networkExistsCommand = &cobra.Command{
Use: "exists NETWORK",
Short: "Check if network exists",
Long: networkExistsDescription,
RunE: networkExists,
Example: `podman network exists net1`,
Args: cobra.ExactArgs(1),
ValidArgsFunction: common.AutocompleteNetworks,
}
)
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: networkExistsCommand,
Parent: networkCmd,
})
}
func networkExists(cmd *cobra.Command, args []string) error {
response, err := registry.ContainerEngine().NetworkExists(registry.GetContext(), args[0])
if err != nil {
return err
}
if !response.Value {
registry.SetExitCode(1)
}
return nil
}