Æsh (Another Extendable SHell) 技术文档
2024-12-24 11:08:50作者:伍希望
1. 安装指南
1.1 Maven 依赖
要使用 Æsh 库,首先需要在项目的 pom.xml 文件中添加以下依赖:
<dependency>
<groupId>org.aesh</groupId>
<artifactId>aesh</artifactId>
<version>1.7</version>
</dependency>
1.2 Gradle 依赖
如果你使用的是 Gradle,可以在 build.gradle 文件中添加以下依赖:
dependencies {
compile group: 'org.aesh', name: 'aesh', version: '1.0-SNAPSHOT'
}
2. 项目使用说明
Æsh 是一个用于轻松创建命令的 Java 库。它通过一个定义良好的 API 来处理命令的解析和注入。Æsh 使用 aesh-readline 项目来实现终端/readline 集成。
2.1 创建简单命令
以下是一个简单的示例,展示了如何使用 Æsh 创建一个退出命令:
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
import org.aesh.command.CommandResult;
import org.aesh.command.impl.registry.AeshCommandRegistryBuilder;
import org.aesh.command.invocation.CommandInvocation;
import org.aesh.command.parser.CommandLineParserException;
import org.aesh.command.registry.CommandRegistry;
import org.aesh.console.settings.Settings;
import org.aesh.console.settings.SettingsBuilder;
import org.aesh.readline.ReadlineConsole;
import java.io.IOException;
public class SimpleExample {
public static void main(String[] args) throws CommandLineParserException, IOException {
CommandRegistry registry = new AeshCommandRegistryBuilder()
.command(ExitCommand.class)
.create();
Settings settings = SettingsBuilder
.builder()
.commandRegistry(registry)
.build();
ReadlineConsole console = new ReadlineConsole(settings);
console.setPrompt("[simple@aesh]$ ");
console.start();
}
@CommandDefinition(name = "exit", description = "exit the program", aliases = {"quit"})
public static class ExitCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.stop();
return CommandResult.SUCCESS;
}
}
}
2.2 功能特性
Æsh 提供了以下主要功能:
- 易于使用的 API:从简单到复杂的命令都可以轻松创建。
- 支持多种选项和参数:包括列表、组、单个选项等。
- 内置完成器:支持默认值、布尔值和文件的自动完成。
- 支持多级子命令:例如
git rebase/pull等。 - 自动注入:所有选项值和参数在执行时自动注入。
- 自定义验证器、激活器、完成器、转换器、渲染器和解析器。
- 自动生成帮助/信息文本:基于提供的元数据。
- 运行时添加和删除命令。
3. 项目 API 使用文档
3.1 命令注册
使用 AeshCommandRegistryBuilder 来注册命令:
CommandRegistry registry = new AeshCommandRegistryBuilder()
.command(ExitCommand.class)
.create();
3.2 设置配置
使用 SettingsBuilder 来配置终端设置:
Settings settings = SettingsBuilder
.builder()
.commandRegistry(registry)
.build();
3.3 启动终端
使用 ReadlineConsole 启动终端并设置提示符:
ReadlineConsole console = new ReadlineConsole(settings);
console.setPrompt("[simple@aesh]$ ");
console.start();
4. 项目安装方式
Æsh 使用 Maven 作为构建工具。你可以通过以下步骤来构建项目:
- 克隆项目仓库。
- 在项目根目录下运行
mvn clean install命令。
通过以上步骤,你可以在本地构建并安装 Æsh 库。
登录后查看全文
热门项目推荐
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00- QQwen3-Coder-Next2026年2月4日,正式发布的Qwen3-Coder-Next,一款专为编码智能体和本地开发场景设计的开源语言模型。Python00
xw-cli实现国产算力大模型零门槛部署,一键跑通 Qwen、GLM-4.7、Minimax-2.1、DeepSeek-OCR 等模型Go06
PaddleOCR-VL-1.5PaddleOCR-VL-1.5 是 PaddleOCR-VL 的新一代进阶模型,在 OmniDocBench v1.5 上实现了 94.5% 的全新 state-of-the-art 准确率。 为了严格评估模型在真实物理畸变下的鲁棒性——包括扫描伪影、倾斜、扭曲、屏幕拍摄和光照变化——我们提出了 Real5-OmniDocBench 基准测试集。实验结果表明,该增强模型在新构建的基准测试集上达到了 SOTA 性能。此外,我们通过整合印章识别和文本检测识别(text spotting)任务扩展了模型的能力,同时保持 0.9B 的超紧凑 VLM 规模,具备高效率特性。Python00
KuiklyUI基于KMP技术的高性能、全平台开发框架,具备统一代码库、极致易用性和动态灵活性。 Provide a high-performance, full-platform development framework with unified codebase, ultimate ease of use, and dynamic flexibility. 注意:本仓库为Github仓库镜像,PR或Issue请移步至Github发起,感谢支持!Kotlin08
VLOOKVLOOK™ 是优雅好用的 Typora/Markdown 主题包和增强插件。 VLOOK™ is an elegant and practical THEME PACKAGE × ENHANCEMENT PLUGIN for Typora/Markdown.Less00
项目优选
收起
deepin linux kernel
C
27
11
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
537
3.76 K
暂无简介
Dart
773
192
Ascend Extension for PyTorch
Python
343
405
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.34 K
755
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
1.07 K
97
React Native鸿蒙化仓库
JavaScript
303
356
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
337
180
AscendNPU-IR
C++
86
142
openJiuwen agent-studio提供零码、低码可视化开发和工作流编排,模型、知识库、插件等各资源管理能力
TSX
987
249