@@ -49,24 +49,24 @@ type InspectResult struct {
49
49
Debug bool `mapstructure:"debug"`
50
50
}
51
51
52
- func checkValueSize (value string , min int , max int ) bool {
53
- if min == 0 && max == 0 {
52
+ func checkValueSize (value string , minValue int , maxValue int ) bool {
53
+ if minValue == 0 && maxValue == 0 {
54
54
return true
55
55
}
56
56
57
- if len (value ) < min {
58
- fmt .Printf (NL ("Has to be more than %d character long" , "Has to be more than %d characters long" , min ), min )
57
+ if len (value ) < minValue {
58
+ fmt .Printf (NL ("Has to be more than %d character long" , "Has to be more than %d characters long" , minValue ), minValue )
59
59
return false
60
60
}
61
- if len (value ) > max {
62
- fmt .Printf (NL ("Has to be less than %d character long" , "Has to be less than %d characters long" , max ), max )
61
+ if len (value ) > maxValue {
62
+ fmt .Printf (NL ("Has to be less than %d character long" , "Has to be less than %d characters long" , maxValue ), maxValue )
63
63
return false
64
64
}
65
65
return true
66
66
}
67
67
68
68
// CheckValidPassword performs check to a given password.
69
- func CheckValidPassword (value * string , prompt string , min int , max int ) string {
69
+ func CheckValidPassword (value * string , prompt string , minValue int , maxValue int ) string {
70
70
fmt .Print (prompt + promptEnd )
71
71
bytePassword , err := term .ReadPassword (int (syscall .Stdin ))
72
72
if err != nil {
@@ -88,7 +88,7 @@ func CheckValidPassword(value *string, prompt string, min int, max int) string {
88
88
return ""
89
89
}
90
90
91
- if ! checkValueSize (tmpValue , min , max ) {
91
+ if ! checkValueSize (tmpValue , minValue , maxValue ) {
92
92
fmt .Println ()
93
93
return ""
94
94
}
@@ -99,18 +99,18 @@ func CheckValidPassword(value *string, prompt string, min int, max int) string {
99
99
100
100
// AskPasswordIfMissing asks for password if missing.
101
101
// Don't perform any check if min and max are set to 0.
102
- func AskPasswordIfMissing (value * string , prompt string , min int , max int ) {
102
+ func AskPasswordIfMissing (value * string , prompt string , minValue int , maxValue int ) {
103
103
if * value == "" && ! term .IsTerminal (int (os .Stdin .Fd ())) {
104
104
log .Warn ().Msgf (L ("not an interactive device, not asking for missing value" ))
105
105
return
106
106
}
107
107
108
108
for * value == "" {
109
- firstRound := CheckValidPassword (value , prompt , min , max )
109
+ firstRound := CheckValidPassword (value , prompt , minValue , maxValue )
110
110
if firstRound == "" {
111
111
continue
112
112
}
113
- secondRound := CheckValidPassword (value , L ("Confirm the password" ), min , max )
113
+ secondRound := CheckValidPassword (value , L ("Confirm the password" ), minValue , maxValue )
114
114
if secondRound != firstRound {
115
115
fmt .Println (L ("Two different passwords have been provided" ))
116
116
* value = ""
@@ -122,20 +122,20 @@ func AskPasswordIfMissing(value *string, prompt string, min int, max int) {
122
122
123
123
// AskPasswordIfMissingOnce asks for password if missing only once
124
124
// Don't perform any check if min and max are set to 0.
125
- func AskPasswordIfMissingOnce (value * string , prompt string , min int , max int ) {
125
+ func AskPasswordIfMissingOnce (value * string , prompt string , minValue int , maxValue int ) {
126
126
if * value == "" && ! term .IsTerminal (int (os .Stdin .Fd ())) {
127
127
log .Warn ().Msgf (L ("not an interactive device, not asking for missing value" ))
128
128
return
129
129
}
130
130
131
131
for * value == "" {
132
- * value = CheckValidPassword (value , prompt , min , max )
132
+ * value = CheckValidPassword (value , prompt , minValue , maxValue )
133
133
}
134
134
}
135
135
136
136
// AskIfMissing asks for a value if missing.
137
- // Don't perform any check if min and max are set to 0.
138
- func AskIfMissing (value * string , prompt string , min int , max int , checker func (string ) bool ) {
137
+ // Don't perform any check if minValue and maxValue are set to 0.
138
+ func AskIfMissing (value * string , prompt string , minValue int , maxValue int , checker func (string ) bool ) {
139
139
if * value == "" && ! term .IsTerminal (int (os .Stdin .Fd ())) {
140
140
log .Warn ().Msgf (L ("not an interactive device, not asking for missing value" ))
141
141
return
@@ -149,7 +149,7 @@ func AskIfMissing(value *string, prompt string, min int, max int, checker func(s
149
149
log .Fatal ().Err (err ).Msg (L ("failed to read input" ))
150
150
}
151
151
tmpValue := strings .TrimSpace (newValue )
152
- if checkValueSize (tmpValue , min , max ) && (checker == nil || checker (tmpValue )) {
152
+ if checkValueSize (tmpValue , minValue , maxValue ) && (checker == nil || checker (tmpValue )) {
153
153
* value = tmpValue
154
154
}
155
155
fmt .Println ()
0 commit comments