Display ty version for ty --version and ty -V (#17888)

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
This commit is contained in:
Zanie Blue 2025-05-06 08:06:41 -05:00 committed by GitHub
parent d07eefc408
commit f82b72882b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -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,

View file

@ -35,6 +35,12 @@ impl fmt::Display for VersionInfo {
}
}
impl From<VersionInfo> 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