From 8b76fcb659116e8a7f87aac1f91e9bcf3bb38b54 Mon Sep 17 00:00:00 2001 From: Markus Scully Date: Mon, 4 Aug 2025 21:36:25 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=E2=9E=95=E2=99=BB=EF=B8=8F?= =?UTF-8?q?=F0=9F=92=A9=20cli,=20vanth,=20Cargo.toml,=20Cargo.lock:=20Add?= =?UTF-8?q?=20CLI=20framework=20and=20refactor=20vanth=20crate=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added a new `vanth_cli` crate with `clap` command structure for `vanth fs open/save` commands. - Removed `main.rs` from `vanth` crate as it is now a library without a binary target. - Added `fs.rs` module and new structs `HashedValue`, `Value`, `Ty` with `Vanth` trait to support serialization. - Updated `Cargo.toml` to include `clap` as a workspace dependency and added `vanth_cli` as a new crate. - Added multiple dependencies (`anstream`, `anstyle`, `clap`, `heck`, etc.) in `Cargo.lock` to support the CLI. - Created placeholder test files `tests/fs/mod.rs` and `tests/main.rs` in `vanth` crate for future use. - Marked CLI command implementations with TODOs as functionality is not yet implemented. --- Cargo.lock | 134 +++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + crates/cli/Cargo.toml | 8 +++ crates/cli/src/cli.rs | 47 ++++++++++++ crates/cli/src/main.rs | 10 +++ crates/vanth/src/fs.rs | 0 crates/vanth/src/lib.rs | 27 ++++--- crates/vanth/src/main.rs | 6 -- crates/vanth/tests/fs/mod.rs | 0 crates/vanth/tests/main.rs | 0 10 files changed, 218 insertions(+), 15 deletions(-) create mode 100644 crates/cli/Cargo.toml create mode 100644 crates/cli/src/cli.rs create mode 100644 crates/cli/src/main.rs create mode 100644 crates/vanth/src/fs.rs delete mode 100644 crates/vanth/src/main.rs create mode 100644 crates/vanth/tests/fs/mod.rs create mode 100644 crates/vanth/tests/main.rs diff --git a/Cargo.lock b/Cargo.lock index 888bf24..5e91d72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,56 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anstream" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -300,6 +350,52 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "clap" +version = "4.5.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -521,6 +617,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "indexmap" version = "2.10.0" @@ -531,6 +633,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.15" @@ -599,6 +707,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + [[package]] name = "parking" version = "2.2.1" @@ -774,6 +888,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" @@ -861,6 +981,12 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.17.0" @@ -885,6 +1011,14 @@ dependencies = [ "serde_json", ] +[[package]] +name = "vanth_cli" +version = "0.1.0" +dependencies = [ + "clap", + "vanth", +] + [[package]] name = "variadics_please" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index b1be115..693ea0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ version = "0.1.0" edition = "2024" [workspace.dependencies] +clap = { version = "4.5.42", features = ["derive"] } bevy_app = "0.16.1" bevy_ecs = "0.16.1" bitcode = "0.6.6" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml new file mode 100644 index 0000000..69a33d1 --- /dev/null +++ b/crates/cli/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vanth_cli" +version.workspace = true +edition.workspace = true + +[dependencies] +clap.workspace = true +vanth = { path = "../vanth" } diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs new file mode 100644 index 0000000..49c23d3 --- /dev/null +++ b/crates/cli/src/cli.rs @@ -0,0 +1,47 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser, Debug)] +#[command(name = "vanth")] +#[command(about = "Vanth CLI tool")] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + #[command(about = "File system operations")] + Fs { + #[command(subcommand)] + command: FsCommands, + }, +} + +#[derive(Subcommand, Debug)] +pub enum FsCommands { + #[command(about = "Read from path and print JSON to stdout")] + Open { + #[arg(help = "Path to read from")] + path: String, + }, + #[command(about = "Take JSON from stdin and write to path")] + Save { + #[arg(help = "Path to write to")] + path: String, + }, +} + +pub fn execute(cli: Cli) { + match cli.command { + Commands::Fs { command } => match command { + FsCommands::Open { path } => { + // TODO: implement fs open functionality + println!("fs open: {}", path); + } + FsCommands::Save { path } => { + // TODO: implement fs save functionality + println!("fs save: {}", path); + } + }, + } +} \ No newline at end of file diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs new file mode 100644 index 0000000..a973166 --- /dev/null +++ b/crates/cli/src/main.rs @@ -0,0 +1,10 @@ +use clap::Parser; + +mod cli; + +use cli::Cli; + +fn main() { + let cli = Cli::parse(); + cli::execute(cli); +} \ No newline at end of file diff --git a/crates/vanth/src/fs.rs b/crates/vanth/src/fs.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/vanth/src/lib.rs b/crates/vanth/src/lib.rs index 2b302c3..9e08e6f 100644 --- a/crates/vanth/src/lib.rs +++ b/crates/vanth/src/lib.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; /// Library crate for the `vanth` ECS-based database node. use bevy_app::{App, Plugin}; use bevy_ecs::{prelude::*, query::QueryData}; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use crate::entity::EntityId; @@ -54,16 +54,25 @@ impl Node { } } -#[derive(Debug, Deserialize, Component, Serialize)] -pub struct Vanth { - id: crate::entity::Id, - _marker: PhantomData, +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct HashedValue { + content_hash: ContentHash, + inner: Value } -impl Vanth { - fn save_system(query: Query) { - - } +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Value { + ty: Ty, + data: Vec, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Ty { + path: Vec, +} + +pub trait Vanth: Serialize + DeserializeOwned { + fn ty() -> Ty; } // TODO: Impl for different tuple sizes diff --git a/crates/vanth/src/main.rs b/crates/vanth/src/main.rs deleted file mode 100644 index e549b26..0000000 --- a/crates/vanth/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod util; -mod vanth; - -fn main() { - println!("Hello, world!"); -} diff --git a/crates/vanth/tests/fs/mod.rs b/crates/vanth/tests/fs/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/vanth/tests/main.rs b/crates/vanth/tests/main.rs new file mode 100644 index 0000000..e69de29