File: deprecated.go

package info (click to toggle)
golang-github-mgutz-minimist 0.0~git20151219.39eb8cf-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 104 kB
  • sloc: makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package minimist

import "github.com/mgutz/to"

// Leftover is an alias for Other and is deprecated. USE Others() instead.
func (am ArgMap) Leftover() []string {
	return am["_"].([]string)
}

//// USE As* functions instead. eg AsBool, AsInt

// ZeroBool tries to convert any of related aliases to bool
func (am ArgMap) ZeroBool(aliases ...string) bool {
	for _, key := range aliases {
		b, err := to.Bool(am[key])
		if err == nil {
			return b
		}
	}
	return false
}

// ZeroString should get value from path or return val.
func (am ArgMap) ZeroString(aliases ...string) string {
	if len(aliases) == 0 {
		panic("Alias key(s) required")
	}
	for _, key := range aliases {
		s := to.String(am[key])
		if len(s) > 0 {
			return s
		}
	}
	return ""
}

// ZeroInt should get value from path or return val.
func (am ArgMap) ZeroInt(aliases ...string) int {
	for _, key := range aliases {
		i, err := to.Int64(am[key])
		if err == nil {
			return int(i)
		}
	}
	return 0
}

// ZeroFloat should get value from path or return val.
func (am ArgMap) ZeroFloat(aliases ...string) float64 {
	for _, key := range aliases {
		f, err := to.Float64(am[key])
		if err == nil {
			return f
		}
	}
	return 0
}