mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-09 17:17:53 +00:00
[NO TESTS NEEDED] This commit cleans up two issues: * Most commands support all EngineModes so default to that. Let outlayers declare their intent. * Use cobra.Annotations to set supported EngineMode. This simplies instantiating commands as there is now one method to communicate a commands requirements rather than two. * Combined aliased commands into one file * Fixed aliased commands where Args field did not match * Updated examples in README.md for writing commands * Remove redundant flag DisableFlagsInUseLine in cobra.Command initialization. Signed-off-by: Jhon Honce <jhonce@redhat.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package network
|
|
|
|
import (
|
|
"github.com/containers/podman/v3/cmd/podman/common"
|
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
|
"github.com/containers/podman/v3/pkg/domain/entities"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var (
|
|
networkDisconnectDescription = `Remove container from a network`
|
|
networkDisconnectCommand = &cobra.Command{
|
|
Use: "disconnect [options] NETWORK CONTAINER",
|
|
Short: "network rm",
|
|
Long: networkDisconnectDescription,
|
|
RunE: networkDisconnect,
|
|
Example: `podman network disconnect web secondary`,
|
|
Args: cobra.ExactArgs(2),
|
|
ValidArgsFunction: common.AutocompleteNetworkConnectCmd,
|
|
}
|
|
)
|
|
|
|
var (
|
|
networkDisconnectOptions entities.NetworkDisconnectOptions
|
|
)
|
|
|
|
func networkDisconnectFlags(flags *pflag.FlagSet) {
|
|
flags.BoolVarP(&networkDisconnectOptions.Force, "force", "f", false, "force removal of container from network")
|
|
}
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: networkDisconnectCommand,
|
|
Parent: networkCmd,
|
|
})
|
|
flags := networkDisconnectCommand.Flags()
|
|
networkDisconnectFlags(flags)
|
|
}
|
|
|
|
func networkDisconnect(cmd *cobra.Command, args []string) error {
|
|
networkDisconnectOptions.Container = args[1]
|
|
return registry.ContainerEngine().NetworkDisconnect(registry.Context(), args[0], networkDisconnectOptions)
|
|
}
|