MCPcopy
hub / github.com/abiosoft/ishell / main

Function main

example/main.go:14–244  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func main() {
15 shell := ishell.New()
16
17 // display info.
18 shell.Println("Sample Interactive Shell")
19
20 // Consider the unicode characters supported by the users font
21 // shell.SetMultiChoicePrompt(" >>"," - ")
22 // shell.SetChecklistOptions("[ ] ","[X] ")
23
24 // handle login.
25 shell.AddCmd(&ishell.Cmd{
26 Name: "login",
27 Func: func(c *ishell.Context) {
28 c.ShowPrompt(false)
29 defer c.ShowPrompt(true)
30
31 c.Println("Let's simulate login")
32
33 // prompt for input
34 c.Print("Username: ")
35 username := c.ReadLine()
36 c.Print("Password: ")
37 password := c.ReadPassword()
38
39 // do something with username and password
40 c.Println("Your inputs were", username, "and", password+".")
41
42 },
43 Help: "simulate a login",
44 })
45
46 // handle "greet".
47 shell.AddCmd(&ishell.Cmd{
48 Name: "greet",
49 Aliases: []string{"hello", "welcome"},
50 Help: "greet user",
51 Func: func(c *ishell.Context) {
52 name := "Stranger"
53 if len(c.Args) > 0 {
54 name = strings.Join(c.Args, " ")
55 }
56 c.Println("Hello", name)
57 },
58 })
59
60 // handle "default".
61 shell.AddCmd(&ishell.Cmd{
62 Name: "default",
63 Help: "readline with default input",
64 Func: func(c *ishell.Context) {
65 c.ShowPrompt(false)
66 defer c.ShowPrompt(true)
67
68 defaultInput := "default input, you can edit this"
69 if len(c.Args) > 0 {
70 defaultInput = strings.Join(c.Args, " ")
71 }

Callers

nothing calls this directly

Calls 15

AddCmdMethod · 0.95
ErrMethod · 0.80
ProcessMethod · 0.80
RunMethod · 0.80
CloseMethod · 0.80
PrintlnMethod · 0.65
ShowPromptMethod · 0.65
PrintMethod · 0.65
ReadLineMethod · 0.65
ReadPasswordMethod · 0.65
ReadLineWithDefaultMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected