AllCommands returns a list of all cmd entries for a given API, regardless of whether they are free functions, class methods or pseudonym methods.
(api interface{})
| 119 | // AllCommands returns a list of all cmd entries for a given API, regardless |
| 120 | // of whether they are free functions, class methods or pseudonym methods. |
| 121 | func (f *Functions) AllCommands(api interface{}) ([]*semantic.Function, error) { |
| 122 | switch api := api.(type) { |
| 123 | case *semantic.API: |
| 124 | var commands []*semantic.Function |
| 125 | for _, function := range api.Functions { |
| 126 | commands = append(commands, function) |
| 127 | } |
| 128 | for _, class := range api.Classes { |
| 129 | for _, method := range class.Methods { |
| 130 | commands = append(commands, method) |
| 131 | } |
| 132 | } |
| 133 | for _, pseudonym := range api.Pseudonyms { |
| 134 | for _, method := range pseudonym.Methods { |
| 135 | commands = append(commands, method) |
| 136 | } |
| 137 | } |
| 138 | return commands, nil |
| 139 | default: |
| 140 | return nil, fmt.Errorf("first argument must be of type *semantic.API, was %T", api) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // AllCommandsSorted returns the list of commands retuned by AllCommands, sorted |
| 145 | // lexicographically. |