diff --git a/crates/ty/docs/environment.md b/crates/ty/docs/environment.md index 29c15b6bd0..0baf1f0ed1 100644 --- a/crates/ty/docs/environment.md +++ b/crates/ty/docs/environment.md @@ -2,6 +2,15 @@ ty defines and respects the following environment variables: +### `TY_CONFIG_FILE` + +Path to a `ty.toml` configuration file to use. + +When set, ty will use this file for configuration instead of +discovering configuration files automatically. + +Equivalent to the `--config-file` command-line argument. + ### `TY_LOG` If set, ty will use this value as the log level for its `--verbose` output. diff --git a/crates/ty/src/args.rs b/crates/ty/src/args.rs index ac334f37bf..37ae9b0bae 100644 --- a/crates/ty/src/args.rs +++ b/crates/ty/src/args.rs @@ -9,6 +9,7 @@ use ty_combine::Combine; use ty_project::metadata::options::{EnvironmentOptions, Options, SrcOptions, TerminalOptions}; use ty_project::metadata::value::{RangedValue, RelativeGlobPattern, RelativePathBuf, ValueSource}; use ty_python_semantic::lint; +use ty_static::EnvVars; // Configures Clap v3-style help menu colors const STYLES: Styles = Styles::styled() @@ -121,7 +122,7 @@ pub(crate) struct CheckCommand { /// The path to a `ty.toml` file to use for configuration. /// /// While ty configuration can be included in a `pyproject.toml` file, it is not allowed in this context. - #[arg(long, env = "TY_CONFIG_FILE", value_name = "PATH")] + #[arg(long, env = EnvVars::TY_CONFIG_FILE, value_name = "PATH")] pub(crate) config_file: Option, /// The format to use for printing diagnostic messages. diff --git a/crates/ty_static/src/env_vars.rs b/crates/ty_static/src/env_vars.rs index b15edffd7e..a31b544d23 100644 --- a/crates/ty_static/src/env_vars.rs +++ b/crates/ty_static/src/env_vars.rs @@ -39,6 +39,14 @@ impl EnvVars { /// when necessary, e.g. to watch for file system changes or a dedicated UI thread. pub const TY_MAX_PARALLELISM: &'static str = "TY_MAX_PARALLELISM"; + /// Path to a `ty.toml` configuration file to use. + /// + /// When set, ty will use this file for configuration instead of + /// discovering configuration files automatically. + /// + /// Equivalent to the `--config-file` command-line argument. + pub const TY_CONFIG_FILE: &'static str = "TY_CONFIG_FILE"; + /// Used to detect an activated virtual environment. pub const VIRTUAL_ENV: &'static str = "VIRTUAL_ENV";