Skip to content

Commit 8d3bd73

Browse files
committed
update
1 parent a455ce5 commit 8d3bd73

5 files changed

Lines changed: 291 additions & 172 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ sqlx = { version = "0.8.6", features = ["runtime-tokio", "postgres", "chrono"]}
4141
comfy-table = "7.1.1"
4242
path-clean = "1.0.1"
4343
sqlparser = "0.49"
44+
pep440_rs = "0.7"
4445

4546
[dev-dependencies]
4647
hoox = "0.3.0"

example/qop.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version = ">=0.0.0,<1.0.0"
12
[backend.postgres]
23
table = "__qop"
34
schema = "public"

src/config.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
use serde::{Deserialize, Serialize};
22
use serde::de::DeserializeOwned;
3+
use pep440_rs::{Version, VersionSpecifiers};
4+
use std::str::FromStr;
5+
6+
#[derive(Debug, Serialize, Deserialize)]
7+
#[serde(rename_all = "snake_case")]
8+
pub struct WithVersion {
9+
pub version: String,
10+
}
11+
12+
impl WithVersion {
13+
pub fn validate(&self, cli: &str) -> Result<(), anyhow::Error> {
14+
if cli == "0.0.0" {
15+
return Ok(());
16+
}
17+
18+
// Parse CLI version
19+
let cli_version = Version::from_str(cli)
20+
.map_err(|e| anyhow::anyhow!("Invalid CLI version '{}': {}", cli, e))?;
21+
22+
// Parse version specification from config
23+
let version_specifier = VersionSpecifiers::from_str(&self.version)
24+
.map_err(|e| anyhow::anyhow!("Invalid version specification '{}': {}", self.version, e))?;
25+
26+
// Check if CLI version matches the specification
27+
if !version_specifier.contains(&cli_version) {
28+
return Err(anyhow::anyhow!(
29+
"Version mismatch: Config requires '{}', but CLI version is '{}'",
30+
self.version,
31+
cli
32+
));
33+
}
34+
35+
Ok(())
36+
}
37+
}
338

439
#[derive(Debug, Serialize, Deserialize)]
540
#[serde(rename_all = "snake_case")]
641
pub struct Config {
42+
pub version: String,
743
pub backend: Backend,
844
}
945

0 commit comments

Comments
 (0)