소스 검색

Add options.DeleteByPrefix

DarthSim 1 주 전
부모
커밋
ffd1f5b13d
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      options/options.go

+ 9 - 0
options/options.go

@@ -145,6 +145,15 @@ func (o *Options) Delete(key string) {
 	delete(o.m, key)
 }
 
+// DeleteByPrefix removes all options that start with the given prefix.
+func (o *Options) DeleteByPrefix(prefix string) {
+	for k := range o.m {
+		if strings.HasPrefix(k, prefix) {
+			delete(o.m, k)
+		}
+	}
+}
+
 // DeleteFromChildren removes an option by its key from the child Options if any.
 func (o *Options) DeleteFromChildren(key string) {
 	if o.child == nil {