3 个版本 (重大变更)

0.5.0 2023年1月9日
0.4.0 2022年12月20日
0.3.0 2022年2月27日

#153#clap

Download history 95/week @ 2024-03-15 143/week @ 2024-03-22 270/week @ 2024-03-29 137/week @ 2024-04-05 152/week @ 2024-04-12 165/week @ 2024-04-19 152/week @ 2024-04-26 119/week @ 2024-05-03 125/week @ 2024-05-10 169/week @ 2024-05-17 124/week @ 2024-05-24 123/week @ 2024-05-31 151/week @ 2024-06-07 217/week @ 2024-06-14 182/week @ 2024-06-21 90/week @ 2024-06-28

每月下载量 656
3 个crate中使用(通过 bevy_console

MIT 许可证

6KB

bevy_console

Check

一个简单的受 Half-Life 启发的控制台,支持由 clap 驱动的参数解析。

用法

添加 ConsolePlugin 和可选的资源 ConsoleConfiguration

use bevy::prelude::*;
use bevy_console::{ConsoleConfiguration, ConsolePlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(ConsolePlugin)
        .insert_resource(ConsoleConfiguration {
            // override config here
            ..Default::default()
        });
}

创建一个控制台命令结构体和系统,使用 .add_console_command 将其添加到您的应用程序中。命令类似于 clap 命令,并通过 ConsoleCommand derive 派生额外的 CommandName 特性。

为您的命令添加 文档注释 以在控制台中提供帮助信息。

use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};
use clap::Parser;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(ConsolePlugin)
        .add_console_command::<ExampleCommand, _>(example_command);
}

/// Example command
#[derive(Parser, ConsoleCommand)]
#[command(name = "example")]
struct ExampleCommand {
    /// Some message
    msg: String,
}

fn example_command(mut log: ConsoleCommand<ExampleCommand>) {
    if let Some(Ok(ExampleCommand { msg })) = log.take() {
        // handle command
    }
}

示例可以在 /examples 目录中找到。

cargo run --example log_command

wasm

应该可以在wasm中工作,但需要禁用默认功能。

依赖关系

~1.5MB
~36K SLoC