summaryrefslogtreecommitdiff
path: root/cmd/podman/cliconfig/commands.go
blob: 00b66e32a16c8a8237d48e4776e737799869c7e7 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package cliconfig

import (
	"github.com/sirupsen/logrus"
)

// GlobalIsSet is a compatibility method for urfave
func (p *PodmanCommand) GlobalIsSet(opt string) bool {
	flag := p.PersistentFlags().Lookup(opt)
	if flag == nil {
		return false
	}
	return flag.Changed
}

// IsSet is a compatibility method for urfave
func (p *PodmanCommand) IsSet(opt string) bool {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		return false
	}
	return flag.Changed
}

// Bool is a compatibility method for urfave
func (p *PodmanCommand) Bool(opt string) bool {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return false
	}
	val, err := p.Flags().GetBool(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// String is a compatibility method for urfave
func (p *PodmanCommand) String(opt string) string {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return ""
	}
	val, err := p.Flags().GetString(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// StringArray is a compatibility method for urfave
func (p *PodmanCommand) StringArray(opt string) []string {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return []string{}
	}
	val, err := p.Flags().GetStringArray(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// StringSlice is a compatibility method for urfave
func (p *PodmanCommand) StringSlice(opt string) []string {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return []string{}
	}
	val, err := p.Flags().GetStringSlice(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// Int is a compatibility method for urfave
func (p *PodmanCommand) Int(opt string) int {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return 0
	}
	val, err := p.Flags().GetInt(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// Unt is a compatibility method for urfave
func (p *PodmanCommand) Uint(opt string) uint {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return 0
	}
	val, err := p.Flags().GetUint(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// Int64 is a compatibility method for urfave
func (p *PodmanCommand) Int64(opt string) int64 {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return 0
	}
	val, err := p.Flags().GetInt64(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// Unt64 is a compatibility method for urfave
func (p *PodmanCommand) Uint64(opt string) uint64 {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return 0
	}
	val, err := p.Flags().GetUint64(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}

// Float64 is a compatibility method for urfave
func (p *PodmanCommand) Float64(opt string) float64 {
	flag := p.Flags().Lookup(opt)
	if flag == nil {
		logrus.Errorf("Could not find flag %s", opt)
		return 0
	}
	val, err := p.Flags().GetFloat64(opt)
	if err != nil {
		logrus.Errorf("Error getting flag %s: %v", opt, err)
	}
	return val
}