mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-09-27 03:36:09 +08:00
refactor: optimize cmd disconnect (#641)
This commit is contained in:
@@ -35,8 +35,12 @@ func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
|
|||||||
after disconnect it will also cleanup DNS and host
|
after disconnect it will also cleanup DNS and host
|
||||||
`)),
|
`)),
|
||||||
Example: templates.Examples(i18n.T(`
|
Example: templates.Examples(i18n.T(`
|
||||||
# disconnect from cluster network and restore proxy resource
|
# disconnect from first cluster
|
||||||
kubevpn disconnect
|
kubevpn disconnect 0
|
||||||
|
# disconnect from second cluster
|
||||||
|
kubevpn disconnect 1
|
||||||
|
# disconnect from all cluster
|
||||||
|
kubevpn disconnect --all
|
||||||
`)),
|
`)),
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
plog.InitLoggerForClient()
|
plog.InitLoggerForClient()
|
||||||
@@ -45,14 +49,8 @@ func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
|
|||||||
},
|
},
|
||||||
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) > 0 && all {
|
|
||||||
return fmt.Errorf("either specify --all or ID, not both")
|
|
||||||
}
|
|
||||||
if len(clusterIDs) > 0 && all {
|
|
||||||
return fmt.Errorf("either specify --all or cluster-id, not both")
|
|
||||||
}
|
|
||||||
if len(args) == 0 && !all && len(clusterIDs) == 0 {
|
if len(args) == 0 && !all && len(clusterIDs) == 0 {
|
||||||
return fmt.Errorf("either specify --all or ID or cluster-id")
|
return fmt.Errorf("either specify --all or ID")
|
||||||
}
|
}
|
||||||
var ids *int32
|
var ids *int32
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@@ -92,5 +90,6 @@ func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
|
|||||||
}
|
}
|
||||||
cmd.Flags().BoolVar(&all, "all", all, "Disconnect all cluster, disconnect from all cluster network")
|
cmd.Flags().BoolVar(&all, "all", all, "Disconnect all cluster, disconnect from all cluster network")
|
||||||
cmd.Flags().StringArrayVar(&clusterIDs, "cluster-id", []string{}, "Cluster id, command status -o yaml/json will show cluster-id")
|
cmd.Flags().StringArrayVar(&clusterIDs, "cluster-id", []string{}, "Cluster id, command status -o yaml/json will show cluster-id")
|
||||||
|
_ = cmd.Flags().MarkHidden("cluster-id")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user