Skip to content

Commit ed2ad86

Browse files
committed
Move trim quotes logic to separate function
1 parent ea3d5e6 commit ed2ad86

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pkg/commands/edit/add/addmetadata.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ func (o *addMetadataOptions) convertToMap(arg string) (map[string]string, error)
152152
}
153153

154154
// remove quotes if value is quoted
155-
if len(result[kv[0]]) > 0 &&
156-
result[kv[0]][:1] == "\"" &&
157-
result[kv[0]][len(result[kv[0]])-1:] == "\"" {
158-
result[kv[0]] = result[kv[0]][1 : len(result[kv[0]])-1]
159-
}
155+
result[kv[0]] = trimQuotes(result[kv[0]])
160156
}
161157
return result, nil
162158
}
@@ -188,3 +184,12 @@ func (o *addMetadataOptions) writeToMap(m map[string]string, kind kindOfAdd) err
188184
func (o *addMetadataOptions) makeError(input string, message string) error {
189185
return fmt.Errorf("invalid %s: %s (%s)", o.kind, input, message)
190186
}
187+
188+
func trimQuotes(s string) string {
189+
if len(s) >= 2 {
190+
if s[0] == '"' && s[len(s)-1] == '"' {
191+
return s[1 : len(s)-1]
192+
}
193+
}
194+
return s
195+
}

0 commit comments

Comments
 (0)