MCPcopy Create free account
hub / github.com/docopt/docopt.go / fixRepeatingArguments

Method fixRepeatingArguments

docopt.go:886–915  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

884}
885
886func (p *pattern) fixRepeatingArguments() {
887 // Fix elements that should accumulate/increment values.
888 var either []patternList
889
890 for _, child := range p.transform().children {
891 either = append(either, child.children)
892 }
893 for _, cas := range either {
894 casMultiple := patternList{}
895 for _, e := range cas {
896 if cas.count(e) > 1 {
897 casMultiple = append(casMultiple, e)
898 }
899 }
900 for _, e := range casMultiple {
901 if e.t == patternArgument || e.t == patternOption && e.argcount > 0 {
902 switch e.value.(type) {
903 case string:
904 e.value = strings.Fields(e.value.(string))
905 case []string:
906 default:
907 e.value = []string{}
908 }
909 }
910 if e.t == patternCommand || e.t == patternOption && e.argcount == 0 {
911 e.value = 0
912 }
913 }
914 }
915}
916
917func (p *pattern) match(left *patternList, collected *patternList) (bool, *patternList, *patternList) {
918 if collected == nil {

Callers 2

fixMethod · 0.95

Calls 2

transformMethod · 0.95
countMethod · 0.80

Tested by 1