Skip to content

Commit

Permalink
Move trim quotes logic to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
narayanan committed Mar 4, 2019
1 parent ea3d5e6 commit ed2ad86
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/commands/edit/add/addmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ func (o *addMetadataOptions) convertToMap(arg string) (map[string]string, error)
}

// remove quotes if value is quoted
if len(result[kv[0]]) > 0 &&
result[kv[0]][:1] == "\"" &&
result[kv[0]][len(result[kv[0]])-1:] == "\"" {
result[kv[0]] = result[kv[0]][1 : len(result[kv[0]])-1]
}
result[kv[0]] = trimQuotes(result[kv[0]])
}
return result, nil
}
Expand Down Expand Up @@ -188,3 +184,12 @@ func (o *addMetadataOptions) writeToMap(m map[string]string, kind kindOfAdd) err
func (o *addMetadataOptions) makeError(input string, message string) error {
return fmt.Errorf("invalid %s: %s (%s)", o.kind, input, message)
}

func trimQuotes(s string) string {
if len(s) >= 2 {
if s[0] == '"' && s[len(s)-1] == '"' {
return s[1 : len(s)-1]
}
}
return s
}

0 comments on commit ed2ad86

Please sign in to comment.