diff --git a/Cargo.lock b/Cargo.lock index 7bd7ce5..1473900 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,14 +92,14 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.5.1" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +checksum = "2c1da3ae8dabd9c00f453a329dfe1fb28da3c0a72e2478cdcd93171740c20499" dependencies = [ "async-lock", "async-task", "concurrent-queue", - "fastrand", + "fastrand 2.0.1", "futures-lite", "slab", ] @@ -115,9 +115,9 @@ dependencies = [ [[package]] name = "async-task" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" +checksum = "b9441c6b2fe128a7c2bf680a44c34d0df31ce09e5b7e401fcca3faa483dbc921" [[package]] name = "autocfg" @@ -151,18 +151,18 @@ dependencies = [ [[package]] name = "bevy" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e71a9143ac21bed247c30129399af8be170309e7ff5983a1bd37e87d3da520" +checksum = "91c6d3ec4f89e85294dc97334c5b271ddc301fdf67ac9bb994fe44d9273e6ed7" dependencies = [ "bevy_internal", ] [[package]] name = "bevy_a11y" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d87d5753cefaeb5f5c5d5e937844f5386eabaf9ab95f3013e86d8fb438d424e" +checksum = "132c9e35a77c5395951f6d25fa2c52ee92296353426df4f961e60f3ff47e2e42" dependencies = [ "accesskit", "bevy_app", @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "bevy_app" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb660188d5d4ceaead6d5861ce22ecedc08b68c385cc8edf0a3c0c0285560bf" +checksum = "f557a7d59e1e16892d7544fc37316506ee598cb5310ef0365125a30783c11531" dependencies = [ "bevy_derive", "bevy_ecs", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "bevy_core" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d47b435bdebeefedda95de98a419c4d3b4c160ed8ce3470ea358a16aad6038" +checksum = "3d5272321be5fcf5ce2fb16023bc825bb10dfcb71611117296537181ce950f48" dependencies = [ "bevy_app", "bevy_ecs", @@ -203,9 +203,9 @@ dependencies = [ [[package]] name = "bevy_derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5cc78985f4d0ad1fd7b8ead06dcfaa192685775a7b1be158191c788c7d52298" +checksum = "a44e4e2784a81430199e4157e02903a987a32127c773985506f020e7d501b62e" dependencies = [ "bevy_macro_utils", "quote", @@ -214,9 +214,9 @@ dependencies = [ [[package]] name = "bevy_diagnostic" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4e366724d233fdc7e282e1415f4cd570e97fbb8443e5a8ff3f8cc5ae253ffd" +checksum = "6babb230dc383c98fdfc9603e3a7a2a49e1e2879dbe8291059ef37dca897932e" dependencies = [ "bevy_app", "bevy_core", @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "bevy_ecs" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb6fd0ec64cd32b8fcf16157173431ba0e675b29c4643a8d6c9a9eeef6f93c32" +checksum = "266144b36df7e834d5198049e037ecdf2a2310a76ce39ed937d1b0a6a2c4e8c6" dependencies = [ "async-channel", "bevy_ecs_macros", @@ -250,9 +250,9 @@ dependencies = [ [[package]] name = "bevy_ecs_macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13b0fd864433db6ff825efd0eb86b2690e208151905b184cc9bfd2c3ac66c3b" +checksum = "7157a9c3be038d5008ee3f114feb6cf6b39c1d3d32ee21a7cacb8f81fccdfa80" dependencies = [ "bevy_macro_utils", "proc-macro2", @@ -262,9 +262,9 @@ dependencies = [ [[package]] name = "bevy_hierarchy" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402789ee53acf345243cf2c86a895d6cf8631e533780ed261c6ecf891eb050b8" +checksum = "103f8f58416ac6799b8c7f0b418f1fac9eba44fa924df3b0e16b09256b897e3d" dependencies = [ "bevy_app", "bevy_core", @@ -277,9 +277,9 @@ dependencies = [ [[package]] name = "bevy_input" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9dfd9c768cf153f3fc807661996b2db44b824299860ba198fb3b92dd731bdd8" +checksum = "ffbd935401101ac8003f3c3aea70788c65ad03f7a32716a10608bedda7a648bc" dependencies = [ "bevy_app", "bevy_ecs", @@ -291,9 +291,9 @@ dependencies = [ [[package]] name = "bevy_internal" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1006f2c501bceb1aef5cc18ed07eb822f295763227b83ba6887e6743698af9f8" +checksum = "e0e35a9b2bd29aa784b3cc416bcbf2a298f69f00ca51fd042ea39d9af7fad37e" dependencies = [ "bevy_a11y", "bevy_app", @@ -316,9 +316,9 @@ dependencies = [ [[package]] name = "bevy_log" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b1e5ca5b217dd384a3bf9186df0d0da757035f9f06d8eec0ebe62cffc05c34" +checksum = "07dcc615ff4f617b06c3f9522fca3c55d56f9644db293318f8ab68fcdea5d4fe" dependencies = [ "android_log-sys", "bevy_app", @@ -332,9 +332,9 @@ dependencies = [ [[package]] name = "bevy_macro_utils" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd460205fe05634d58b32d9bb752b1b4eaf32b2d29cbd4161ba35eb44a2f8c" +checksum = "23ddc18d489b4e57832d4958cde7cd2f349f0ad91e5892ac9e2f2ee16546b981" dependencies = [ "quote", "rustc-hash", @@ -344,9 +344,9 @@ dependencies = [ [[package]] name = "bevy_math" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267f2ec44aa948051768b1320c2dbff0871799e0a3b746f5fe5b6ee7258fbaf5" +checksum = "78286a81fead796dc4b45ab14f4f02fe29a94423d3587bcfef872b2a8e0a474b" dependencies = [ "glam", "serde", @@ -354,15 +354,15 @@ dependencies = [ [[package]] name = "bevy_ptr" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15702dff420fac72c2ab92428a8600e079ae89c5845401c4e39b843665a3d2d0" +checksum = "72c7586401a46f7d8e436028225c1df5288f2e0082d066b247a82466fea155c6" [[package]] name = "bevy_reflect" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac66cccbf1457c5cfc004a0e83569bd4ddc5d6310701f4af6aa81001fe2964a" +checksum = "0778197a1eb3e095a71417c74b7152ede02975cdc95b5ea4ddc5251ed00a2eb5" dependencies = [ "bevy_math", "bevy_ptr", @@ -381,9 +381,9 @@ dependencies = [ [[package]] name = "bevy_reflect_derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a2a1fa784e9a22560b9de350246a159cd59239eb61c7b66824031b3b28abb0" +checksum = "342a4b2d09db22c48607d23ad59a056aff1ee004549050a51d490d375ba29528" dependencies = [ "bevy_macro_utils", "bit-set", @@ -395,9 +395,9 @@ dependencies = [ [[package]] name = "bevy_tasks" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9200e7b42d49c787d9a08675c425d8bd6393ba3beed2eac64be6027a44a01870" +checksum = "c73bbb847c83990d3927005090df52f8ac49332e1643d2ad9aac3cd2974e66bf" dependencies = [ "async-channel", "async-executor", @@ -409,9 +409,9 @@ dependencies = [ [[package]] name = "bevy_time" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ba50bf25c4dc40296b744f77de10d39c8981b710d8dce609da9de5e54ef164b" +checksum = "3d58d6dbae9c8225d8c0e0f04d2c5dbb71d22adc01ecd5ab3cebc364139e4a6d" dependencies = [ "bevy_app", "bevy_ecs", @@ -423,9 +423,9 @@ dependencies = [ [[package]] name = "bevy_transform" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86043ec5cc3cf406d33c0e4d6920171601e186b1288e9b4f5ae54682a0564032" +checksum = "3b9b0ac0149a57cd846cb357a35fc99286f9848e53d4481954608ac9552ed2d4" dependencies = [ "bevy_app", "bevy_ecs", @@ -436,9 +436,9 @@ dependencies = [ [[package]] name = "bevy_utils" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829eb8d0d06a0baeabc2e8bad74136ed3329b055aa1e11c5d9df09ebb9be3d85" +checksum = "08d9484e32434ea84dc548cff246ce0c6f756c1336f5ea03f24ac120a48595c7" dependencies = [ "ahash", "bevy_utils_proc_macros", @@ -453,9 +453,9 @@ dependencies = [ [[package]] name = "bevy_utils_proc_macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d104f29e231123c703e8b394e2341d2425c33c5a2e9ab8cc8d0a554bdb62a41" +checksum = "5391b242c36f556db01d5891444730c83aa9dd648b6a8fd2b755d22cb3bddb57" dependencies = [ "proc-macro2", "quote", @@ -464,9 +464,9 @@ dependencies = [ [[package]] name = "bevy_window" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a66f9963152093220fc5ffd2244cadcc7f79cf2c23dd02076f4d0cbb7f5162f" +checksum = "bd584c0da7c4ada6557b09f57f30fb7cff21ccedc641473fc391574b4c9b7944" dependencies = [ "bevy_app", "bevy_ecs", @@ -561,9 +561,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils", ] @@ -699,6 +699,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fixedbitset" version = "0.4.2" @@ -741,7 +747,7 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.9.0", "futures-core", "futures-io", "memchr", @@ -814,9 +820,9 @@ checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e" dependencies = [ "equivalent", "hashbrown", @@ -1072,6 +1078,7 @@ name = "oxcr_cli" version = "0.1.0" dependencies = [ "oxcr_protocol", + "tracing-subscriber", ] [[package]] @@ -1109,9 +1116,9 @@ dependencies = [ [[package]] name = "parking" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" +checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" [[package]] name = "parking_lot" @@ -1373,9 +1380,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "c1b21f559e07218024e7e9f90f96f601825397de0e25420135f7f952453fed0b" dependencies = [ "lazy_static", ] @@ -1543,18 +1550,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -1740,9 +1747,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waker-fn" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[package]] name = "wasi" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 6d2a458..c4b9a15 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] oxcr_protocol.workspace = true +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 04f7a79..9bb8ca7 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1,11 +1,15 @@ //! Spanned-clap, lol -use std::{marker::PhantomData, path::PathBuf}; +use std::{marker::PhantomData, path::PathBuf, str::FromStr}; use aott::prelude::*; use oxcr_protocol::{ - aott::{self, pfn_type}, + aott::{ + self, pfn_type, + text::{ascii::ident, inline_whitespace, int, whitespace}, + }, bytes::{BufMut, Bytes, BytesMut}, + tracing::{level_filters::LevelFilter, Level}, }; use crate::error::{Expectation, ParseError, ParseErrorKind}; @@ -16,12 +20,6 @@ impl<'a, C> ParserExtras<&'a str> for Extra { type Error = crate::error::ParseError; } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum CliSerOp { - Encode, - Decode, -} - #[derive(Debug, Clone)] pub enum ByteInput { File(PathBuf), @@ -29,18 +27,32 @@ pub enum ByteInput { } #[derive(Debug, Clone)] -pub struct CliSer { - pub operation: CliSerOp, - pub inp: ByteInput, +pub enum CliCommand { + Decode(ByteInput), + Help, } #[derive(Debug, Clone)] -pub enum Cli { - Serialization(CliSer), +pub struct Cli { + pub level: LevelFilter, + pub command: CliCommand, +} + +#[derive(Debug, Clone)] +pub enum Flag { + Level(Level), + Help, + Decode(ByteInput), +} + +#[derive(Debug)] +enum FlagName<'a> { + Short(&'a str), + Long(&'a str), } fn numbah<'a>(radix: u32, cha: char) -> pfn_type!(&'a str, Bytes, Extra) { - |input| { + move |input| { just(['0', cha]) .ignore_then(text::int(radix)) .try_map_with_span(|x: &str, span| { @@ -48,7 +60,7 @@ fn numbah<'a>(radix: u32, cha: char) -> pfn_type!(&'a str, Bytes, Extra) { .map(|c| { c.to_digit(radix) .ok_or_else(|| ParseError { - span: span.into(), + span: span.clone().into(), kind: ParseErrorKind::Expected { expected: Expectation::Digit(8), found: c, @@ -75,7 +87,7 @@ fn byte_input(input: &str) -> ByteInput { .map(|c| { c.to_digit(16) .ok_or_else(|| ParseError { - span: span.into(), + span: span.clone().into(), kind: ParseErrorKind::Expected { expected: Expectation::Digit(8), found: c, @@ -90,4 +102,96 @@ fn byte_input(input: &str) -> ByteInput { } #[parser(extras = Extra)] -pub fn yay(input: &str) -> Cli {} +fn from_str(input: &str) -> T +where + ParseErrorKind: From, +{ + T::from_str(input.input.slice_from(input.offset..)).map_err(|error| ParseError { + span: (input.offset, input.offset + 1).into(), + kind: error.into(), + }) +} + +#[parser(extras = Extra)] +fn flag_list(input: &str) -> Vec> { + just("-") + .ignore_then(choice(( + slice(filter(|thing: &char| *thing != ' ')) + .map(FlagName::Short) + .repeated(), + just("-") + .ignore_then(ident) + .map(|name| vec![FlagName::Long(name)]), + ))) + .parse_with(input) +} + +#[parser(extras = Extra)] +fn flags(input: &str) -> Vec { + let before = input.offset; + + let flag_list = dbg!(flag_list(input)?); + flag_list + .into_iter() + .map(|flag| -> Result { + try { + match flag { + FlagName::Short("l") | FlagName::Long("level") => { + one_of(" =")(input)?; + let before_ = input.offset; + Flag::Level( + Level::from_str(ident.or(slice(int(10))).parse_with(input)?).map_err( + |error| ParseError { + span: (before_, input.offset).into(), + kind: error.into(), + }, + )?, + ) + } + FlagName::Short("D") | FlagName::Long("debug") => Flag::Level(Level::DEBUG), + FlagName::Short("d") + | FlagName::Long("decode") + | FlagName::Long("deserialize") => { + one_of(" =")(input)?; + + Flag::Decode(byte_input(input)?) + } + FlagName::Short("h") | FlagName::Long("help") => Flag::Help, + FlagName::Short(flag) | FlagName::Long(flag) => Err(ParseError { + span: input.span_since(before).into(), + kind: ParseErrorKind::UnknownFlag(flag.to_owned()), + })?, + } + } + }) + .try_collect() +} + +fn flags_handle<'a>( + cli: &mut Cli, + input: &mut Input<&'a str, Extra>, +) -> PResult<&'a str, (), Extra> { + fn handle(cli: &mut Cli, flag: Flag) { + match flag { + Flag::Level(level) => cli.level = LevelFilter::from(level), + Flag::Help => cli.command = CliCommand::Help, + Flag::Decode(input) => cli.command = CliCommand::Decode(input), + } + } + + try { flags(input)?.into_iter().for_each(|flag| handle(cli, flag)) } +} + +#[parser(extras = Extra)] +pub fn yay(input: &str) -> Cli { + try { + let mut cli = Cli { + level: LevelFilter::OFF, + command: CliCommand::Help, + }; + + flags_handle(&mut cli, input)?; + + cli + } +} diff --git a/cli/src/error.rs b/cli/src/error.rs index 3d9edfd..22aa712 100644 --- a/cli/src/error.rs +++ b/cli/src/error.rs @@ -1,10 +1,11 @@ -use std::ops::Range; +use std::{ops::Range, str::FromStr}; use oxcr_protocol::{ aott, miette::{self, SourceSpan}, ser::any_of, thiserror, + tracing::{metadata::ParseLevelError, Level}, }; #[derive(miette::Diagnostic, thiserror::Error, Debug)] @@ -13,6 +14,10 @@ pub enum ParseErrorKind { Expected { expected: Expectation, found: char }, #[error("unexpected end of input")] UnexpectedEof, + #[error("parsing a Level failed: {_0}")] + ParseLevel(#[from] ParseLevelError), + #[error("unknown flag encountered: {_0}")] + UnknownFlag(String), } #[derive(Debug, thiserror::Error)] diff --git a/cli/src/main.rs b/cli/src/main.rs index 7386646..2c9fc35 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,28 +1,78 @@ -#![feature(iterator_try_collect)] +#![feature(iterator_try_collect, try_blocks)] use oxcr_protocol::{ - miette::{self, bail, Report}, - nsfr::when_the_miette, + aott::prelude::Parser, + error::Error, + miette::{self, bail, IntoDiagnostic, Report}, + model::packets::{play::LoginPlay, Packet, PacketContext, SerializedPacket}, + ser::{BytesSource, Deserialize, Serialize, WithSource}, + tracing::debug, }; +use tracing_subscriber::{util::SubscriberInitExt, EnvFilter}; + +use crate::cli::{ByteInput, Cli, CliCommand}; mod cli; mod error; -fn run() -> Result<(), Report> { +fn run(path: String, args: &str) -> Result<(), Report> { + let tsub_guard = tracing_subscriber::fmt() + .pretty() + .with_env_filter(EnvFilter::from_env("OXCR_LOG")) + .finish() + .set_default(); + + let cli = cli::yay + .parse(args) + .map_err(|parse_error| Report::new(parse_error).with_source_code(args.to_owned()))?; + + drop(tsub_guard); + + let tsub_guard = tracing_subscriber::fmt() + .with_env_filter(cli.level.to_string()) + .pretty() + .set_default(); + + debug!("{:?}", cli); + + match cli.command { + CliCommand::Help => help(), + CliCommand::Decode(inp) => { + let bytes = match inp { + ByteInput::Data(data) => data, + ByteInput::File(file) => { + std::fs::read(std::env::current_dir().into_diagnostic()?.join(file)) + .into_diagnostic()? + .into() + } + }; + let spack = SerializedPacket { + length: LoginPlay::ID.length_of() + bytes.len(), + data: bytes, + id: LoginPlay::ID, + }; + let deserialized: LoginPlay = spack.try_deserialize(LoginPlay::STATE)?; + + debug!("{:#?}", deserialized); + } + } + + Ok(()) +} + +fn main() -> Result<(), Report> { let mut args = std::env::args(); match args.next() { None => bail!("the"), Some(path) => { - let arguments: String = args.collect(); + dbg!(&path); + let args = args.collect::>().join(" "); + run(path, &args)?; + Ok(()) } } } -fn main() { - match when_the_miette(run()) { - Ok(()) => {} - Err(_) => {} - } -} +fn help() {} diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 3cd6022..92bdd6d 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -29,6 +29,7 @@ pub mod serde { } pub use indexmap; pub use miette; +pub use tracing; pub async fn rwlock_set(rwlock: &RwLock, value: T) { rwlock.set(value).await