tConsole 介绍
tConsole 是一个 Telnet Console 框架,提供一个 Telnet 环境支持,给予没有界面类的应用一个可以通过命令行进行交互的工具。
特性
样例
实现一个控制台命令。
**public** **class** **HelloWordExecutor** **implements** **TelExecutor** { /** 命令的帮助信息,在 help <command> 时候输出这个信息 */ **public** **String** **helpInfo** () { **return** "hello help."; } /** 执行命令体 */ **public** **String** **doCommand** ( **TelCommand** telCommand) **throws** **Throwable** { **return** "you say ->" + telCommand.getCommandName(); } }
利用 telnet 命令来交互
**public** **static** **void** **main** ( **String** [] args) { **AppContext** appContext = **Hasor**.create().build(( **TelModule** ) apiBinder -> { **TelnetBuilder** telnetBuild = apiBinder.asTelnet("127.0.0.1", 2180); telnetBuild.addExecutor("hello").to( **HelloWordExecutor**.class); } appContext.joinSignal(); }
输入 telnet 127.0.0.1 2180 之后
>telnet 127.0.0.1 2180 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. -------------------------------------------- Welcome to tConsole! login : Tue Jan 07 14:26:29 CST 2020 Now. form /127.0.0.1:60023 workAt : /127.0.0.1:2180 Tips: You can enter a 'help' or 'help -a' for more @R_668_4045@ion. use the 'exit' or 'quit' out of the console. -------------------------------------------- tConsole>
充当命令工具包,建议利用 Spring Boot 的 fat jar 打包能力整合使用。
**public** **static** **void** **main** ( **String** [] args) { **AppContext** appContext = **Hasor**.create().build(( **TelModule** ) apiBinder -> { **HostBuilder** hostBuild = apiBinder.asHostWithSTDO().preCommand(args); hostBuild.addExecutor("hello").to( **HelloWordExecutor**.class); } }
输入 java xxx.jar hello 执行 hello 命令。
tConsole 官网
https://gitee.com/zycgit/hasor/tree/master/hasor-tconsole
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。