diff --git a/CHANGELOG.md b/CHANGELOG.md index 27c567d..70829a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,23 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## `granc` - [0.3.1](https://github.com/JasterV/granc/compare/granc-v0.3.0...granc-v0.3.1) - 2026-01-22 +## `granc` - [0.4.0](https://github.com/JasterV/granc/compare/granc-v0.2.4...granc-v0.4.0) - 2026-01-22 -### Other -- update Cargo.lock dependencies +- Made a mistake publishing `granc 0.3` and introduced bugs, `granc 0.4` fixes them and its the first working version after `0.2.4`. ## `granc_core` - [0.3.1](https://github.com/JasterV/granc/compare/granc_core-v0.3.0...granc_core-v0.3.1) - 2026-01-22 ### Other -- update granc-core documentation + +- Update granc-core documentation ## `granc_core` - [0.3.0](https://github.com/JasterV/granc/compare/granc_core-v0.2.4...granc_core-v0.3.0) - 2026-01-22 -- Separate reflection generation binary to not be published ([#20](https://github.com/JasterV/granc/pull/20)) - -## `granc` - [0.3.0](https://github.com/JasterV/granc/compare/granc_core-v0.2.4...granc_core-v0.3.0) - 2026-01-22 - -- Separate reflection generation binary to not be published ([#20](https://github.com/JasterV/granc/pull/20)) +- Fix: separate reflection generation binary to not be published ([#20](https://github.com/JasterV/granc/pull/20)) ## `granc` - [0.2.4](https://github.com/JasterV/granc/compare/granc-v0.2.3...granc-v0.2.4) - 2026-01-22 diff --git a/granc-core/Cargo.toml b/granc-core/Cargo.toml index fda4d0a..0421196 100644 --- a/granc-core/Cargo.toml +++ b/granc-core/Cargo.toml @@ -11,7 +11,7 @@ publish = true readme = "README.md" repository = { workspace = true } rust-version = { workspace = true } -version = { workspace = true } +version = "0.3.2" [lib] name = "granc_core" diff --git a/granc/Cargo.toml b/granc/Cargo.toml index 0133fdb..c3bbe5a 100644 --- a/granc/Cargo.toml +++ b/granc/Cargo.toml @@ -11,11 +11,11 @@ publish = true readme = "../README.md" repository = { workspace = true } rust-version = { workspace = true } -version = { workspace = true } +version = "0.4.0" [dependencies] clap = { version = "4.5.54", features = ["derive"] } -granc_core = "0.2.4" +granc_core = "0.3.2" serde_json = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } tonic = { workspace = true } diff --git a/granc/src/cli.rs b/granc/src/cli.rs index cf6123f..08b7905 100644 --- a/granc/src/cli.rs +++ b/granc/src/cli.rs @@ -3,14 +3,15 @@ //! This module defines the command-line interface of `granc` using `clap`. //! //! It is responsible for parsing user input and performing validation (e.g., ensuring headers are `key:value`); +use std::path::PathBuf; + use clap::Parser; -use granc_core::client::DynamicRequest; #[derive(Parser)] #[command(name = "granc", version, about = "Dynamic gRPC CLI")] pub struct Cli { - #[arg(long, help = "Path to the descriptor set (.bin)", value_parser = parse_file_descriptor_set)] - pub file_descriptor_set: Option>, + #[arg(long, help = "Path to the descriptor set (.bin)")] + pub file_descriptor_set: Option, #[arg(long, help = "JSON body (Object for Unary, Array for Streaming)", value_parser = parse_body)] pub body: serde_json::Value, @@ -25,28 +26,6 @@ pub struct Cli { pub endpoint: (String, String), } -impl From for DynamicRequest { - /// Converts the raw CLI arguments into the internal `Input` representation. - fn from(value: Cli) -> Self { - let (service, method) = value.endpoint; - - Self { - file_descriptor_set: value.file_descriptor_set, - body: value.body, - headers: value.headers, - service, - method, - } - } -} - -fn parse_file_descriptor_set(path: &str) -> Result, String> { - let path = path.trim(); - - std::fs::read(path) - .map_err(|err| format!("Failed to read file descriptor set at path '{path}': '{err}'")) -} - fn parse_endpoint(value: &str) -> Result<(String, String), String> { let (service, method) = value.split_once('/').ok_or_else(|| { format!("Invalid endpoint format: '{value}'. Expected 'package.Service/Method'",) diff --git a/granc/src/main.rs b/granc/src/main.rs index eaee61a..8aa6afa 100644 --- a/granc/src/main.rs +++ b/granc/src/main.rs @@ -18,6 +18,24 @@ use std::process; async fn main() { let args = Cli::parse(); + let file_descriptor_set = match args.file_descriptor_set.map(std::fs::read).transpose() { + Ok(fd) => fd, + Err(err) => { + eprintln!("Error reading file descriptor set: '{err}'"); + process::exit(1); + } + }; + + let (service, method) = args.endpoint; + + let request = DynamicRequest { + file_descriptor_set, + body: args.body, + headers: args.headers, + service, + method, + }; + let mut client = match GrancClient::connect(&args.url).await { Ok(client) => client, Err(err) => { @@ -26,7 +44,7 @@ async fn main() { } }; - match client.dynamic(DynamicRequest::from(args)).await { + match client.dynamic(request).await { Ok(DynamicResponse::Unary(Ok(value))) => print_json(&value), Ok(DynamicResponse::Unary(Err(status))) => print_status(&status), Ok(DynamicResponse::Streaming(Ok(values))) => print_stream(&values),