首页
/ Æsh (Another Extendable SHell) 技术文档

Æsh (Another Extendable SHell) 技术文档

2024-12-24 09:25:53作者:伍希望

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 作为构建工具。你可以通过以下步骤来构建项目:

  1. 克隆项目仓库。
  2. 在项目根目录下运行 mvn clean install 命令。

通过以上步骤,你可以在本地构建并安装 Æsh 库。

登录后查看全文
热门项目推荐

热门内容推荐

最新内容推荐

项目优选

收起
openHiTLS-examplesopenHiTLS-examples
本仓将为广大高校开发者提供开源实践和创新开发平台,收集和展示openHiTLS示例代码及创新应用,欢迎大家投稿,让全世界看到您的精巧密码实现设计,也让更多人通过您的优秀成果,理解、喜爱上密码技术。
C
52
461
kernelkernel
deepin linux kernel
C
22
5
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
349
381
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
7
0
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
131
185
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
873
517
Cangjie-ExamplesCangjie-Examples
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
Cangjie
336
1.09 K
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
179
264
cherry-studiocherry-studio
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
607
59
note-gennote-gen
一款跨平台的 Markdown AI 笔记软件,致力于使用 AI 建立记录和写作的桥梁。
TSX
83
4