Skip to content

Commit 4ad9552

Browse files
committed
chore: support new and old env var names
1 parent 85baf89 commit 4ad9552

File tree

8 files changed

+124
-43
lines changed

8 files changed

+124
-43
lines changed

crates/pgt_cli/src/commands/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::commands::daemon::default_pgt_log_path;
22
use crate::{CliDiagnostic, CliSession};
3-
use pgt_env::pgt_env;
3+
use pgt_env::pgls_env;
44
use std::fs::{create_dir, remove_dir_all};
55
use std::path::PathBuf;
66

77
/// Runs the clean command
88
pub fn clean(_cli_session: CliSession) -> Result<(), CliDiagnostic> {
9-
let logs_path = pgt_env()
9+
let logs_path = pgls_env()
1010
.pgt_log_path
1111
.value()
1212
.map_or(default_pgt_log_path(), PathBuf::from);

crates/pgt_cli/src/commands/daemon.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
use pgt_console::{ConsoleExt, markup};
66
use pgt_lsp::ServerFactory;
77
use pgt_workspace::{TransportError, WorkspaceError, workspace::WorkspaceClient};
8-
use std::{env, path::PathBuf};
8+
use std::path::PathBuf;
99
use tokio::io;
1010
use tokio::runtime::Runtime;
1111
use tracing::subscriber::Interest;
@@ -234,7 +234,12 @@ fn setup_tracing_subscriber(
234234
}
235235

236236
pub fn default_pgt_log_path() -> PathBuf {
237-
match env::var_os("PGT_LOG_PATH") {
237+
let env = pgt_env::pgls_env();
238+
match env
239+
.pgls_log_path
240+
.value()
241+
.or_else(|| env.pgt_log_path.value())
242+
{
238243
Some(directory) => PathBuf::from(directory),
239244
None => pgt_fs::ensure_cache_dir().join("pgt-logs"),
240245
}

crates/pgt_cli/src/commands/mod.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub enum PgtCommand {
7373
/// Allows to change the prefix applied to the file name of the logs.
7474
#[bpaf(
7575
env("PGT_LOG_PREFIX_NAME"),
76+
env("PGLS_LOG_PREFIX_NAME"),
7677
long("log-prefix-name"),
7778
argument("STRING"),
7879
hide_usage,
@@ -84,6 +85,7 @@ pub enum PgtCommand {
8485
/// Allows to change the folder where logs are stored.
8586
#[bpaf(
8687
env("PGT_LOG_PATH"),
88+
env("PGLS_LOG_PATH"),
8789
long("log-path"),
8890
argument("PATH"),
8991
hide_usage,
@@ -92,7 +94,12 @@ pub enum PgtCommand {
9294
log_path: PathBuf,
9395
/// Allows to set a custom file path to the configuration file,
9496
/// or a custom directory path to find `postgrestools.jsonc`
95-
#[bpaf(env("PGT_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))]
97+
#[bpaf(
98+
env("PGT_LOG_PREFIX_NAME"),
99+
env("PGLS_LOG_PREFIX_NAME"),
100+
long("config-path"),
101+
argument("PATH")
102+
)]
96103
config_path: Option<PathBuf>,
97104
},
98105

@@ -110,6 +117,7 @@ pub enum PgtCommand {
110117
/// Allows to change the prefix applied to the file name of the logs.
111118
#[bpaf(
112119
env("PGT_LOG_PREFIX_NAME"),
120+
env("PGLS_LOG_PREFIX_NAME"),
113121
long("log-prefix-name"),
114122
argument("STRING"),
115123
hide_usage,
@@ -120,6 +128,7 @@ pub enum PgtCommand {
120128
/// Allows to change the folder where logs are stored.
121129
#[bpaf(
122130
env("PGT_LOG_PATH"),
131+
env("PGLS_LOG_PATH"),
123132
long("log-path"),
124133
argument("PATH"),
125134
hide_usage,
@@ -128,7 +137,12 @@ pub enum PgtCommand {
128137
log_path: PathBuf,
129138
/// Allows to set a custom file path to the configuration file,
130139
/// or a custom directory path to find `postgrestools.jsonc`
131-
#[bpaf(env("PGT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
140+
#[bpaf(
141+
env("PGT_CONFIG_PATH"),
142+
env("PGLS_CONFIG_PATH"),
143+
long("config-path"),
144+
argument("PATH")
145+
)]
132146
config_path: Option<PathBuf>,
133147
/// Bogus argument to make the command work with vscode-languageclient
134148
#[bpaf(long("stdio"), hide, hide_usage, switch)]
@@ -144,6 +158,7 @@ pub enum PgtCommand {
144158
/// Allows to change the prefix applied to the file name of the logs.
145159
#[bpaf(
146160
env("PGT_LOG_PREFIX_NAME"),
161+
env("PGLS_LOG_PREFIX_NAME"),
147162
long("log-prefix-name"),
148163
argument("STRING"),
149164
hide_usage,
@@ -155,6 +170,7 @@ pub enum PgtCommand {
155170
/// Allows to change the folder where logs are stored.
156171
#[bpaf(
157172
env("PGT_LOG_PATH"),
173+
env("PGLS_LOG_PATH"),
158174
long("log-path"),
159175
argument("PATH"),
160176
hide_usage,
@@ -165,6 +181,7 @@ pub enum PgtCommand {
165181
/// Allows to change the log level. Default is debug. This will only affect "pgt*" crates. All others are logged with info level.
166182
#[bpaf(
167183
env("PGT_LOG_LEVEL"),
184+
env("PGLS_LOG_LEVEL"),
168185
long("log-level"),
169186
argument("trace|debug|info|warn|error|none"),
170187
fallback(String::from("debug"))
@@ -174,6 +191,7 @@ pub enum PgtCommand {
174191
/// Allows to change the logging format kind. Default is hierarchical.
175192
#[bpaf(
176193
env("PGT_LOG_KIND"),
194+
env("PGLS_LOG_KIND"),
177195
long("log-kind"),
178196
argument("hierarchical|bunyan"),
179197
fallback(String::from("hierarchical"))
@@ -184,7 +202,12 @@ pub enum PgtCommand {
184202
stop_on_disconnect: bool,
185203
/// Allows to set a custom file path to the configuration file,
186204
/// or a custom directory path to find `postgrestools.jsonc`
187-
#[bpaf(env("PGT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
205+
#[bpaf(
206+
env("PGT_CONFIG_PATH"),
207+
env("PGLS_CONFIG_PATH"),
208+
long("config-path"),
209+
argument("PATH")
210+
)]
188211
config_path: Option<PathBuf>,
189212
},
190213
#[bpaf(command("__print_socket"), hide)]

crates/pgt_configuration/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use files::{FilesConfiguration, PartialFilesConfiguration, partial_files_configu
3333
use migrations::{
3434
MigrationsConfiguration, PartialMigrationsConfiguration, partial_migrations_configuration,
3535
};
36-
use pgt_env::PGT_WEBSITE;
36+
use pgt_env::PGLS_WEBSITE;
3737
use plpgsql_check::{
3838
PartialPlPgSqlCheckConfiguration, PlPgSqlCheckConfiguration,
3939
partial_pl_pg_sql_check_configuration,
@@ -103,7 +103,7 @@ impl PartialConfiguration {
103103
/// Returns the initial configuration.
104104
pub fn init() -> Self {
105105
Self {
106-
schema: Some(format!("{}/schemas/{VERSION}/schema.json", PGT_WEBSITE)),
106+
schema: Some(format!("{}/schemas/{VERSION}/schema.json", PGLS_WEBSITE)),
107107
extends: Some(StringSet::default()),
108108
files: Some(PartialFilesConfiguration {
109109
ignore: Some(Default::default()),

crates/pgt_env/src/lib.rs

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Environment variables and configuration constants for Postgres Tools.
1+
//! Environment variables and configuration constants for Postgres Language Server.
22
//!
33
//! This module provides:
44
//! - Environment variable definitions for runtime configuration
@@ -10,13 +10,14 @@ use pgt_console::{DebugDisplay, KeyValuePair, markup};
1010
use std::env;
1111
use std::sync::{LazyLock, OnceLock};
1212

13-
/// Returns `true` if this is an unstable build of Postgres Tools
13+
/// Returns `true` if this is an unstable build of Postgres Language Server
1414
pub fn is_unstable() -> bool {
1515
VERSION == "0.0.0"
1616
}
1717

18-
/// The internal version of Postgres Tools. This is usually supplied during the CI build
19-
pub static PGT_VERSION: LazyLock<Option<&str>> = LazyLock::new(|| option_env!("PGT_VERSION"));
18+
/// The internal version of Postgres Language Server. This is usually supplied during the CI build
19+
pub static PGLS_VERSION: LazyLock<Option<&str>> =
20+
LazyLock::new(|| option_env!("PGLS_VERSION").or(option_env!("PGT_VERSION")));
2021

2122
/// The version of Postgres Tools with fallback logic
2223
pub const VERSION: &str = match option_env!("PGT_VERSION") {
@@ -27,44 +28,67 @@ pub const VERSION: &str = match option_env!("PGT_VERSION") {
2728
},
2829
};
2930

30-
pub static PGT_WEBSITE: &str = "https://pgtools.dev";
31+
pub static PGLS_WEBSITE: &str = "https://pgtools.dev";
3132

32-
pub struct PgTEnv {
33-
pub pgt_log_path: PgTEnvVariable,
34-
pub pgt_log_prefix: PgTEnvVariable,
35-
pub pgt_config_path: PgTEnvVariable,
33+
pub struct PgLSEnv {
34+
pub pgls_log_path: PgLSEnvVariable,
35+
pub pgls_log_level: PgLSEnvVariable,
36+
pub pgls_log_prefix: PgLSEnvVariable,
37+
pub pgls_config_path: PgLSEnvVariable,
38+
39+
// DEPRECATED
40+
pub pgt_log_path: PgLSEnvVariable,
41+
pub pgt_log_prefix: PgLSEnvVariable,
42+
pub pgt_config_path: PgLSEnvVariable,
3643
}
3744

38-
pub static PGT_ENV: OnceLock<PgTEnv> = OnceLock::new();
45+
pub static PGT_ENV: OnceLock<PgLSEnv> = OnceLock::new();
3946

40-
impl PgTEnv {
47+
impl PgLSEnv {
4148
fn new() -> Self {
4249
Self {
43-
pgt_log_path: PgTEnvVariable::new(
44-
"PGT_LOG_PATH",
50+
pgls_log_path: PgLSEnvVariable::new(
51+
"PGLS_LOG_PATH",
4552
"The directory where the Daemon logs will be saved.",
4653
),
47-
pgt_log_prefix: PgTEnvVariable::new(
48-
"PGT_LOG_PREFIX_NAME",
54+
pgls_log_level: PgLSEnvVariable::new(
55+
"PGLS_LOG_LEVEL",
56+
"Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level.",
57+
),
58+
pgls_log_prefix: PgLSEnvVariable::new(
59+
"PGLS_LOG_PREFIX_NAME",
4960
"A prefix that's added to the name of the log. Default: `server.log.`",
5061
),
51-
pgt_config_path: PgTEnvVariable::new(
52-
"PGT_CONFIG_PATH",
62+
pgls_config_path: PgLSEnvVariable::new(
63+
"PGLS_CONFIG_PATH",
5364
"A path to the configuration file",
5465
),
66+
67+
pgt_log_path: PgLSEnvVariable::new(
68+
"PGT_LOG_PATH",
69+
"The directory where the Daemon logs will be saved. Deprecated, use PGLS_LOG_PATH instead.",
70+
),
71+
pgt_log_prefix: PgLSEnvVariable::new(
72+
"PGT_LOG_PREFIX_NAME",
73+
"A prefix that's added to the name of the log. Default: `server.log`. Deprecated, use PGLS_LOG_PREFIX_NAME instead.",
74+
),
75+
pgt_config_path: PgLSEnvVariable::new(
76+
"PGT_CONFIG_PATH",
77+
"A path to the configuration file. Deprecated, use PGLS_CONFIG_PATH instead.",
78+
),
5579
}
5680
}
5781
}
5882

59-
pub struct PgTEnvVariable {
83+
pub struct PgLSEnvVariable {
6084
/// The name of the environment variable
6185
name: &'static str,
6286
/// The description of the variable.
6387
// This field will be used in the website to automate its generation
6488
description: &'static str,
6589
}
6690

67-
impl PgTEnvVariable {
91+
impl PgLSEnvVariable {
6892
fn new(name: &'static str, description: &'static str) -> Self {
6993
Self { name, description }
7094
}
@@ -85,12 +109,41 @@ impl PgTEnvVariable {
85109
}
86110
}
87111

88-
pub fn pgt_env() -> &'static PgTEnv {
89-
PGT_ENV.get_or_init(PgTEnv::new)
112+
pub fn pgls_env() -> &'static PgLSEnv {
113+
PGT_ENV.get_or_init(PgLSEnv::new)
90114
}
91115

92-
impl Display for PgTEnv {
116+
impl Display for PgLSEnv {
93117
fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
118+
match self.pgls_log_path.value() {
119+
None => {
120+
KeyValuePair(self.pgls_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
121+
}
122+
Some(value) => {
123+
KeyValuePair(self.pgls_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
124+
}
125+
};
126+
match self.pgls_log_prefix.value() {
127+
None => {
128+
KeyValuePair(self.pgls_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
129+
}
130+
Some(value) => {
131+
KeyValuePair(self.pgls_log_prefix.name, markup! {{DebugDisplay(value)}})
132+
.fmt(fmt)?;
133+
}
134+
};
135+
136+
match self.pgls_config_path.value() {
137+
None => {
138+
KeyValuePair(self.pgls_config_path.name, markup! { <Dim>"unset"</Dim> })
139+
.fmt(fmt)?;
140+
}
141+
Some(value) => {
142+
KeyValuePair(self.pgls_config_path.name, markup! {{DebugDisplay(value)}})
143+
.fmt(fmt)?;
144+
}
145+
};
146+
94147
match self.pgt_log_path.value() {
95148
None => {
96149
KeyValuePair(self.pgt_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;

crates/pgt_workspace/src/configuration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use pgt_configuration::{
1212
VERSION, diagnostics::CantLoadExtendFile, push_to_analyser_rules,
1313
};
1414
use pgt_console::markup;
15-
use pgt_env::PGT_WEBSITE;
15+
use pgt_env::PGLS_WEBSITE;
1616
use pgt_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions};
1717

1818
use crate::{DynRef, WorkspaceError, settings::Settings};
@@ -187,9 +187,9 @@ pub fn create_config(
187187
configuration.schema = node_schema_path.to_str().map(String::from);
188188
} else if VERSION == "0.0.0" {
189189
// VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback)
190-
configuration.schema = Some(format!("{}/latest/schema.json", PGT_WEBSITE));
190+
configuration.schema = Some(format!("{}/latest/schema.json", PGLS_WEBSITE));
191191
} else {
192-
configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGT_WEBSITE));
192+
configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGLS_WEBSITE));
193193
}
194194

195195
let contents = serde_json::to_string_pretty(&configuration)

docs/codegen/src/env_variables.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ pub fn generate_env_variables(docs_dir: &Path) -> Result<()> {
1010

1111
let mut content = vec![];
1212

13-
let env = pgt_env::pgt_env();
13+
let env = pgt_env::pgls_env();
1414

1515
writeln!(content, "\n",)?;
1616

1717
writeln!(
1818
content,
1919
"### `{}`\n\n {}\n",
20-
env.pgt_log_path.name(),
21-
env.pgt_log_path.description()
20+
env.pgls_log_path.name(),
21+
env.pgls_log_path.description()
2222
)?;
2323
writeln!(
2424
content,
2525
"### `{}`\n\n {}\n",
26-
env.pgt_log_prefix.name(),
27-
env.pgt_log_prefix.description()
26+
env.pgls_log_prefix.name(),
27+
env.pgls_log_prefix.description()
2828
)?;
2929
writeln!(
3030
content,
3131
"### `{}`\n\n {}\n",
32-
env.pgt_config_path.name(),
33-
env.pgt_config_path.description()
32+
env.pgls_config_path.name(),
33+
env.pgls_config_path.description()
3434
)?;
3535

3636
let data = fs::read_to_string(&file_path)?;

xtask/codegen/src/generate_new_analyser_rule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use biome_string_case::Case;
22
use bpaf::Bpaf;
33
use pgt_diagnostics::Severity;
4-
use pgt_env::PGT_WEBSITE;
4+
use pgt_env::PGLS_WEBSITE;
55
use std::str::FromStr;
66
use xtask::project_root;
77

@@ -130,7 +130,7 @@ pub fn generate_new_analyser_rule(
130130
let rule_line = match category {
131131
Category::Lint => format!(
132132
r#" "lint/{group}/{rule_name_camel}": "{}/latest/rules/{kebab_case_rule}","#,
133-
PGT_WEBSITE
133+
PGLS_WEBSITE
134134
),
135135
};
136136
let lint_start = match category {

0 commit comments

Comments
 (0)