MCPcopy Create free account
hub / github.com/52funny/pikpakcli / expandRemotePatternToken

Function expandRemotePatternToken

internal/shell/shell.go:873–912  ·  view source on GitHub ↗
(token string, pathValue string, currentPath string, source fileStatProvider, preferRelative bool)

Source from the content-addressed store, hash-verified

871}
872
873func expandRemotePatternToken(token string, pathValue string, currentPath string, source fileStatProvider, preferRelative bool) ([]string, error) {
874 if !hasWildcard(token) {
875 return []string{token}, nil
876 }
877
878 basePath := currentPath
879 if strings.TrimSpace(pathValue) != "" {
880 basePath = pathValue
881 }
882
883 patternPath := token
884 if !path.IsAbs(patternPath) {
885 patternPath = path.Clean(path.Join(basePath, patternPath))
886 } else {
887 patternPath = path.Clean(patternPath)
888 }
889
890 parentPath := path.Dir(patternPath)
891 if parentPath == "." {
892 parentPath = "/"
893 }
894
895 matches, err := matchRemotePattern(source, parentPath, path.Base(patternPath))
896 if err != nil {
897 return nil, err
898 }
899 if len(matches) == 0 {
900 return nil, fmt.Errorf("shell: no matches found for %s", token)
901 }
902
903 if preferRelative && !path.IsAbs(token) && strings.TrimSpace(pathValue) != "" {
904 rewritten := make([]string, 0, len(matches))
905 for _, match := range matches {
906 rewritten = append(rewritten, relativeRemotePath(pathValue, match))
907 }
908 return rewritten, nil
909 }
910
911 return matches, nil
912}
913
914func matchRemotePattern(source fileStatProvider, parentPath string, pattern string) ([]string, error) {
915 parentID := ""

Callers 3

expandOpenGlobsFunction · 0.85
rewriteDownloadLikeArgsFunction · 0.85
expandDeletePatternTokenFunction · 0.85

Calls 3

matchRemotePatternFunction · 0.85
hasWildcardFunction · 0.70
relativeRemotePathFunction · 0.70

Tested by

no test coverage detected