(prefix string)
| 148 | type PathWithAt string |
| 149 | |
| 150 | func (PathWithAt) Complete(prefix string) []flags.Completion { |
| 151 | if prefix == "" || prefix[0] != '@' { |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | prefix = prefix[1:] |
| 156 | |
| 157 | var homeDir string |
| 158 | if strings.HasPrefix(prefix, fmt.Sprintf("~%c", os.PathSeparator)) { |
| 159 | // when $HOME is empty this will complete on /, however this is not tested |
| 160 | homeDir = os.Getenv("HOME") |
| 161 | prefix = fmt.Sprintf("%s%s", homeDir, prefix[1:]) |
| 162 | } |
| 163 | |
| 164 | return findMatches( |
| 165 | fmt.Sprintf("%s*", prefix), |
| 166 | func(path string) string { |
| 167 | if homeDir != "" { |
| 168 | newPath, err := filepath.Rel(homeDir, path) |
| 169 | if err == nil { |
| 170 | path = filepath.Join("~", newPath) |
| 171 | } |
| 172 | } |
| 173 | return fmt.Sprintf("@%s", path) |
| 174 | }) |
| 175 | } |
| 176 | |
| 177 | type PathWithBool string |
| 178 |
nothing calls this directly
no test coverage detected