()
| 12 | ) |
| 13 | |
| 14 | func 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 | } |
nothing calls this directly
no test coverage detected