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

enhance: display disconnect result for pouch network disconnect #1590

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
25 changes: 18 additions & 7 deletions cli/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,7 @@ var networkDisconnectDescription = "Disconnect a container from a network"
// NetworkDisconnectCommand use to implement 'network disconnect' command, it disconnects given container from given network.
type NetworkDisconnectCommand struct {
baseCommand
network string
container string
force bool
force bool
}

// Init initializes 'network disconnect' command.
Expand All @@ -497,17 +495,30 @@ func (nd *NetworkDisconnectCommand) addFlags() {

// runNetworkDisconnect is the entry of 'disconnect' command.
func (nd *NetworkDisconnectCommand) runNetworkDisconnect(args []string) error {
nd.network = args[0]
nd.container = args[1]
network := args[0]
container := args[1]

if network == "" {
return fmt.Errorf("network name cannot be empty")
}
if container == "" {
return fmt.Errorf("container name cannot be empty")
}

ctx := context.Background()
apiClient := nd.cli.Client()

return apiClient.NetworkDisconnect(ctx, nd.network, nd.container, nd.force)
err := apiClient.NetworkDisconnect(ctx, network, container, nd.force)
if err != nil {
return err
}
fmt.Printf("container %s is disconnected from network %s\n successfully", container, network)

return nil
}

// networkDisconnectExample shows examples in 'disconnect' command, and is used in auto-generated cli docs.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need change the example command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine. I have updated it. PTAL, thanks

func (nd *NetworkDisconnectCommand) networkDisconnectExample() string {
return `$ pouch network disconnect bridge test
`
container test is disconnected from network bridge successfully`
}