aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/script-utils/logfmt/regexflag.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/script-utils/logfmt/regexflag.go')
-rw-r--r--client/go/script-utils/logfmt/regexflag.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/go/script-utils/logfmt/regexflag.go b/client/go/script-utils/logfmt/regexflag.go
new file mode 100644
index 00000000000..8f7d2a91373
--- /dev/null
+++ b/client/go/script-utils/logfmt/regexflag.go
@@ -0,0 +1,38 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// vespa logfmt command
+// Author: arnej
+
+package logfmt
+
+import (
+ "regexp"
+)
+
+// optional regular expression filter, as a CLI flag
+
+type regexFlag struct {
+ regex *regexp.Regexp
+}
+
+func (re regexFlag) unmatched(s string) bool {
+ if re.regex == nil {
+ return false
+ }
+ return re.regex.FindStringIndex(s) == nil
+}
+
+func (v *regexFlag) Type() string {
+ return "regular expression"
+}
+
+func (v *regexFlag) String() string {
+ if v.regex == nil {
+ return "<none>"
+ }
+ return v.regex.String()
+}
+
+func (v *regexFlag) Set(val string) (r error) {
+ v.regex, r = regexp.Compile(val)
+ return
+}