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

Function handleOpenCommand

internal/shell/open.go:32–65  ·  view source on GitHub ↗
(p openFileService, currentPath string, args []string)

Source from the content-addressed store, hash-verified

30}
31
32func handleOpenCommand(p openFileService, currentPath string, args []string) error {
33 if len(args) == 0 {
34 return errors.New("usage: open <remote-file> [remote-file...]")
35 }
36
37 for _, arg := range args {
38 targetPath := resolveShellPath(currentPath, arg)
39 stat, err := p.GetFileByPath(targetPath)
40 if err != nil {
41 return fmt.Errorf("open: %s: %w", targetPath, err)
42 }
43 if stat.Kind == api.FileKindFolder {
44 return fmt.Errorf("open: %s: folders are not supported", targetPath)
45 }
46
47 file, err := p.GetFile(stat.ID)
48 if err != nil {
49 return fmt.Errorf("open: %s: get file failed: %w", targetPath, err)
50 }
51
52 openTarget, err := resolveOpenTarget(&file)
53 if err != nil {
54 return fmt.Errorf("open: %s: resolve open target failed: %w", targetPath, err)
55 }
56
57 if err := openWithLocalApp(openTarget, classifyOpenCategory(file.Name)); err != nil {
58 return fmt.Errorf("open: %s: launch local app failed: %w", targetPath, err)
59 }
60
61 fmt.Printf("Opened %s -> %s\n", targetPath, openTarget)
62 }
63
64 return nil
65}
66
67func resolveOpenTarget(file *api.File) (string, error) {
68 if classifyOpenCategory(file.Name) == openCategoryVideo {

Callers 1

StartFunction · 0.85

Calls 6

resolveShellPathFunction · 0.85
resolveOpenTargetFunction · 0.85
openWithLocalAppFunction · 0.85
classifyOpenCategoryFunction · 0.85
GetFileByPathMethod · 0.65
GetFileMethod · 0.65

Tested by

no test coverage detected