Use ExactArgs(1) to check for exactly one positional argument.
<
https://github.com/spf13/cobra#positional-and-custom-arguments>
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
cmd/virtconsoleresolveradm/cmd/disable.go | 6 +-----
cmd/virtconsoleresolveradm/cmd/enable.go | 6 +-----
2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/cmd/virtconsoleresolveradm/cmd/disable.go
b/cmd/virtconsoleresolveradm/cmd/disable.go
index 2d41874..aab3047 100644
--- a/cmd/virtconsoleresolveradm/cmd/disable.go
+++ b/cmd/virtconsoleresolveradm/cmd/disable.go
@@ -40,14 +40,10 @@ var disableCmd = &cobra.Command{
Short: "Disable consoles for a domain",
Long: "Disable access to consoles for a domain",
Run: doDisable,
+ Args: cobra.ExactArgs(1),
}
func doDisable(cmd *cobra.Command, args []string) {
- if len(args) != 1 {
- fmt.Fprintln(os.Stderr, "Missing domain name/uuid")
- os.Exit(1)
- }
-
conn, err := libvirt.NewConnect(connect)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot connect to hypervisor '%s': %s\n",
diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go
b/cmd/virtconsoleresolveradm/cmd/enable.go
index ebad497..49897ef 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -43,6 +43,7 @@ var (
Short: "Enable consoles for a domain",
Long: "Enable consoles for a domain",
Run: doEnable,
+ Args: cobra.ExactArgs(1),
}
insecure *bool
host *string
@@ -99,11 +100,6 @@ func createConsole(ctype string, index int, conn *libvirt.Connect,
domname, domu
}
func doEnable(cmd *cobra.Command, args []string) {
- if len(args) != 1 {
- fmt.Fprintln(os.Stderr, "Missing domain name/uuid")
- os.Exit(1)
- }
-
conn, err := libvirt.NewConnect(connect)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot connect to hypervisor '%s': %s\n",
--
2.20.1