mirror of
https://codeberg.org/JasterV/granc.git
synced 2026-04-26 18:40:05 +00:00
fix: bugs and release granc 0.4.0
This commit is contained in:
parent
efe41e1155
commit
191120c1d4
5 changed files with 31 additions and 38 deletions
14
CHANGELOG.md
14
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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<Vec<u8>>,
|
||||
#[arg(long, help = "Path to the descriptor set (.bin)")]
|
||||
pub file_descriptor_set: Option<PathBuf>,
|
||||
|
||||
#[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<Cli> 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<Vec<u8>, 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'",)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue