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

Function Start

internal/shell/shell.go:39–155  ·  view source on GitHub ↗

Start starts the interactive shell

(rootCmd *cobra.Command)

Source from the content-addressed store, hash-verified

37
38// Start starts the interactive shell
39func Start(rootCmd *cobra.Command) {
40 fmt.Println("PikPak CLI Interactive Shell")
41 fmt.Println("Type 'help' for available commands, 'exit' or Ctrl-D to quit")
42 fmt.Println()
43
44 currentPath := "/"
45
46 p := api.NewPikPak(conf.Config.Username, conf.Config.Password)
47 if err := p.Login(); err != nil {
48 fmt.Println("Login failed")
49 logx.Error(err)
50 return
51 }
52
53 l, err := readline.NewEx(&readline.Config{
54 Prompt: promptForPath(currentPath),
55 AutoComplete: &shellAutoCompleter{
56 rootCmd: rootCmd,
57 fileStatSource: &p,
58 currentPath: func() string {
59 return currentPath
60 },
61 },
62 })
63 if err != nil {
64 fmt.Println("Initialize readline failed")
65 logx.Error(err)
66 return
67 }
68 defer l.Close()
69
70 for {
71 input, err := l.Readline()
72
73 if isReadlineInterrupt(err) {
74 fmt.Println()
75 l.SetPrompt(promptForPath(currentPath))
76 continue
77 }
78
79 if shouldExitOnReadlineError(err) {
80 fmt.Println("\nBye~!")
81 return
82 }
83
84 if err != nil {
85 fmt.Println("\nBye~!")
86 break
87 }
88
89 input = strings.TrimSpace(input)
90 if input == "" {
91 continue
92 }
93
94 args := parseShellArgs(input)
95 if len(args) == 0 {
96 continue

Callers

nothing calls this directly

Calls 15

LoginMethod · 0.95
WithContextMethod · 0.95
NewPikPakFunction · 0.92
ErrorFunction · 0.92
promptForPathFunction · 0.85
isReadlineInterruptFunction · 0.85
parseShellArgsFunction · 0.85
clearScreenFunction · 0.85
changeDirectoryFunction · 0.85
expandOpenGlobsFunction · 0.85
handleOpenCommandFunction · 0.85

Tested by

no test coverage detected