From f82b72882b75410af96c5c959d7493f9aa3190e3 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 6 May 2025 08:06:41 -0500 Subject: [PATCH] Display `ty version` for `ty --version` and `ty -V` (#17888) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e.g., ``` ❯ uv run -q -- ty -V ty 0.0.0-alpha.4 (08881edba 2025-05-05) ❯ uv run -q -- ty --version ty 0.0.0-alpha.4 (08881edba 2025-05-05) ``` Previously, this just displayed `ty 0.0.0` because it didn't use our custom version implementation. We no longer have a short version — matching the interface in uv. We could add a variant for it, if it seems important to people. However, I think we found it more confusing than not over there and didn't get any complaints about the change. Closes https://github.com/astral-sh/ty/issues/54 --- crates/ty/Cargo.toml | 2 +- crates/ty/src/args.rs | 2 +- crates/ty/src/version.rs | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ty/Cargo.toml b/crates/ty/Cargo.toml index 9ce23eb648..813cbdb30d 100644 --- a/crates/ty/Cargo.toml +++ b/crates/ty/Cargo.toml @@ -20,7 +20,7 @@ ty_server = { workspace = true } anyhow = { workspace = true } argfile = { workspace = true } -clap = { workspace = true, features = ["wrap_help"] } +clap = { workspace = true, features = ["wrap_help", "string"] } colored = { workspace = true } countme = { workspace = true, features = ["enable"] } crossbeam = { workspace = true } diff --git a/crates/ty/src/args.rs b/crates/ty/src/args.rs index 5049bd1551..c9969d0f9c 100644 --- a/crates/ty/src/args.rs +++ b/crates/ty/src/args.rs @@ -8,7 +8,7 @@ use ty_python_semantic::lint; #[derive(Debug, Parser)] #[command(author, name = "ty", about = "An extremely fast Python type checker.")] -#[command(version)] +#[command(long_version = crate::version::version())] pub(crate) struct Args { #[command(subcommand)] pub(crate) command: Command, diff --git a/crates/ty/src/version.rs b/crates/ty/src/version.rs index a851afc8c7..d063de5277 100644 --- a/crates/ty/src/version.rs +++ b/crates/ty/src/version.rs @@ -35,6 +35,12 @@ impl fmt::Display for VersionInfo { } } +impl From for clap::builder::Str { + fn from(val: VersionInfo) -> Self { + val.to_string().into() + } +} + /// Returns information about ty's version. pub(crate) fn version() -> VersionInfo { // Environment variables are only read at compile-time