File: args.go

package info (click to toggle)
incus 6.21.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 27,496 kB
  • sloc: sh: 17,280; ansic: 3,201; python: 458; makefile: 340; ruby: 51; sql: 50; lisp: 6
file content (25 lines) | stat: -rw-r--r-- 570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package cmd

import (
	"errors"

	"github.com/spf13/cobra"
)

// ErrBadArgs is returned when the incorrect number of arguments was passed.
var ErrBadArgs = errors.New("incorrect number of arguments")

// CheckArgs validates the number of arguments for a command.
func CheckArgs(cmd *cobra.Command, args []string, minArgs int, maxArgs int) (bool, error) {
	if len(args) < minArgs || (maxArgs != -1 && len(args) > maxArgs) {
		_ = cmd.Help()

		if len(args) == 0 {
			return true, nil
		}

		return true, errors.New("Invalid number of arguments")
	}

	return false, nil
}