https://github.com/abiosoft/ishell
常见的cli包有:flag、cli、os…都可以实现
但是上面有一个问题,就是执行完以后,就会给出结果,并退出,不是进入一个shell中,执行所有结果都是不同的。
import “strings”
import “github.com/abiosoft/ishell”
func main(){
// create new shell.
// by default, new shell includes ‘exit’, ‘help’ and ‘clear’ commands.
shell := ishell.New()
// display welcome info.
shell.Println("Sample Interactive Shell")
// register a function for "greet" command.
shell.AddCmd(&ishell.Cmd{
Name: "greet",
Help: "greet user",
Func: func(c *ishell.Context) {
c.Println("Hello", strings.Join(c.Args, " "))
},
})
// run shell
shell.Run() } 上面代码很简单就是先实例化ishell.New()一个 Shell对象,使用方法AddCmd添加命令
https://studygolang.com/articles/18019