diff --git a/tools/cli/types.go b/tools/cli/types.go index a5b669c91..205714023 100644 --- a/tools/cli/types.go +++ b/tools/cli/types.go @@ -14,6 +14,7 @@ import ( var _ = fmt.Print +// Option {{{ type OptionType int const ( @@ -37,6 +38,16 @@ func (self *Alias) String() string { return "--" + self.NameWithoutHyphens } +type OptionSpec struct { + Name string + Type string + Dest string + Choices string + Depth int + Default string + Help string +} + type Option struct { Name string Aliases []Alias @@ -170,6 +181,9 @@ func (self *Option) add_value(val string) error { return nil } +// }}} + +// Groups {{{ type CommandGroup struct { SubCommands []*Command Title string @@ -204,17 +218,7 @@ func (self *CommandGroup) FindSubCommand(name string) *Command { return nil } -type OptionSpec struct { - Name string - Type string - Dest string - Choices string - Depth int - Default string - Help string -} - -type OptionGroup struct { // {{{ +type OptionGroup struct { Options []*Option Title string } @@ -258,7 +262,7 @@ func (self *OptionGroup) FindOption(name_with_hyphens string) *Option { // }}} -type Command struct { +type Command struct { // {{{ Name, ExeName string Usage, HelpText string Hidden bool @@ -542,3 +546,5 @@ func (self *Command) GetOptionValues(pointer_to_options_struct any) error { } return nil } + +// }}} diff --git a/tools/utils/regexp.go b/tools/utils/regexp.go index 551575665..2348a9fd4 100644 --- a/tools/utils/regexp.go +++ b/tools/utils/regexp.go @@ -17,8 +17,16 @@ type SubMatch struct { Start, End int } +func Compile(pat string) (*regexp.Regexp, error) { + return pat_cache.GetOrCreate(pat, regexp.Compile) +} + +func MustCompile(pat string) *regexp.Regexp { + return pat_cache.MustGetOrCreate(pat, regexp.MustCompile) +} + func ReplaceAll(pat, str string, repl func(full_match string, groupdict map[string]SubMatch) string) string { - cpat := pat_cache.MustGetOrCreate(pat, regexp.MustCompile) + cpat := MustCompile(pat) result := strings.Builder{} result.Grow(len(str) + 256) last_index := 0