Skip to content

Commit 8d8076c

Browse files
authored
chore: rename env vars (#558)
1 parent f113ec7 commit 8d8076c

File tree

9 files changed

+174
-37
lines changed

9 files changed

+174
-37
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: 8 additions & 0 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,
@@ -115,6 +117,7 @@ pub enum PgtCommand {
115117
/// Allows to change the prefix applied to the file name of the logs.
116118
#[bpaf(
117119
env("PGT_LOG_PREFIX_NAME"),
120+
env("PGLS_LOG_PREFIX_NAME"),
118121
long("log-prefix-name"),
119122
argument("STRING"),
120123
hide_usage,
@@ -125,6 +128,7 @@ pub enum PgtCommand {
125128
/// Allows to change the folder where logs are stored.
126129
#[bpaf(
127130
env("PGT_LOG_PATH"),
131+
env("PGLS_LOG_PATH"),
128132
long("log-path"),
129133
argument("PATH"),
130134
hide_usage,
@@ -154,6 +158,7 @@ pub enum PgtCommand {
154158
/// Allows to change the prefix applied to the file name of the logs.
155159
#[bpaf(
156160
env("PGT_LOG_PREFIX_NAME"),
161+
env("PGLS_LOG_PREFIX_NAME"),
157162
long("log-prefix-name"),
158163
argument("STRING"),
159164
hide_usage,
@@ -165,6 +170,7 @@ pub enum PgtCommand {
165170
/// Allows to change the folder where logs are stored.
166171
#[bpaf(
167172
env("PGT_LOG_PATH"),
173+
env("PGLS_LOG_PATH"),
168174
long("log-path"),
169175
argument("PATH"),
170176
hide_usage,
@@ -175,6 +181,7 @@ pub enum PgtCommand {
175181
/// Allows to change the log level. Default is debug. This will only affect "pgt*" crates. All others are logged with info level.
176182
#[bpaf(
177183
env("PGT_LOG_LEVEL"),
184+
env("PGLS_LOG_LEVEL"),
178185
long("log-level"),
179186
argument("trace|debug|info|warn|error|none"),
180187
fallback(String::from("debug"))
@@ -184,6 +191,7 @@ pub enum PgtCommand {
184191
/// Allows to change the logging format kind. Default is hierarchical.
185192
#[bpaf(
186193
env("PGT_LOG_KIND"),
194+
env("PGLS_LOG_KIND"),
187195
long("log-kind"),
188196
argument("hierarchical|bunyan"),
189197
fallback(String::from("hierarchical"))

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: 96 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,72 @@ 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_level: PgLSEnvVariable,
42+
pub pgt_log_prefix: PgLSEnvVariable,
43+
pub pgt_config_path: PgLSEnvVariable,
3644
}
3745

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

40-
impl PgTEnv {
48+
impl PgLSEnv {
4149
fn new() -> Self {
4250
Self {
43-
pgt_log_path: PgTEnvVariable::new(
44-
"PGT_LOG_PATH",
51+
pgls_log_path: PgLSEnvVariable::new(
52+
"PGLS_LOG_PATH",
4553
"The directory where the Daemon logs will be saved.",
4654
),
47-
pgt_log_prefix: PgTEnvVariable::new(
48-
"PGT_LOG_PREFIX_NAME",
55+
pgls_log_level: PgLSEnvVariable::new(
56+
"PGLS_LOG_LEVEL",
57+
"Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level.",
58+
),
59+
pgls_log_prefix: PgLSEnvVariable::new(
60+
"PGLS_LOG_PREFIX_NAME",
4961
"A prefix that's added to the name of the log. Default: `server.log.`",
5062
),
51-
pgt_config_path: PgTEnvVariable::new(
52-
"PGT_CONFIG_PATH",
63+
pgls_config_path: PgLSEnvVariable::new(
64+
"PGLS_CONFIG_PATH",
5365
"A path to the configuration file",
5466
),
67+
68+
pgt_log_path: PgLSEnvVariable::new(
69+
"PGT_LOG_PATH",
70+
"The directory where the Daemon logs will be saved. Deprecated, use PGLS_LOG_PATH instead.",
71+
),
72+
pgt_log_level: PgLSEnvVariable::new(
73+
"PGT_LOG_LEVEL",
74+
"Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level. Deprecated, use PGLS_LOG_LEVEL instead.",
75+
),
76+
pgt_log_prefix: PgLSEnvVariable::new(
77+
"PGT_LOG_PREFIX_NAME",
78+
"A prefix that's added to the name of the log. Default: `server.log`. Deprecated, use PGLS_LOG_PREFIX_NAME instead.",
79+
),
80+
pgt_config_path: PgLSEnvVariable::new(
81+
"PGT_CONFIG_PATH",
82+
"A path to the configuration file. Deprecated, use PGLS_CONFIG_PATH instead.",
83+
),
5584
}
5685
}
5786
}
5887

59-
pub struct PgTEnvVariable {
88+
pub struct PgLSEnvVariable {
6089
/// The name of the environment variable
6190
name: &'static str,
6291
/// The description of the variable.
6392
// This field will be used in the website to automate its generation
6493
description: &'static str,
6594
}
6695

67-
impl PgTEnvVariable {
96+
impl PgLSEnvVariable {
6897
fn new(name: &'static str, description: &'static str) -> Self {
6998
Self { name, description }
7099
}
@@ -85,12 +114,49 @@ impl PgTEnvVariable {
85114
}
86115
}
87116

88-
pub fn pgt_env() -> &'static PgTEnv {
89-
PGT_ENV.get_or_init(PgTEnv::new)
117+
pub fn pgls_env() -> &'static PgLSEnv {
118+
PGT_ENV.get_or_init(PgLSEnv::new)
90119
}
91120

92-
impl Display for PgTEnv {
121+
impl Display for PgLSEnv {
93122
fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
123+
match self.pgls_log_path.value() {
124+
None => {
125+
KeyValuePair(self.pgls_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
126+
}
127+
Some(value) => {
128+
KeyValuePair(self.pgls_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
129+
}
130+
};
131+
match self.pgls_log_level.value() {
132+
None => {
133+
KeyValuePair(self.pgls_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
134+
}
135+
Some(value) => {
136+
KeyValuePair(self.pgls_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
137+
}
138+
};
139+
match self.pgls_log_prefix.value() {
140+
None => {
141+
KeyValuePair(self.pgls_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
142+
}
143+
Some(value) => {
144+
KeyValuePair(self.pgls_log_prefix.name, markup! {{DebugDisplay(value)}})
145+
.fmt(fmt)?;
146+
}
147+
};
148+
149+
match self.pgls_config_path.value() {
150+
None => {
151+
KeyValuePair(self.pgls_config_path.name, markup! { <Dim>"unset"</Dim> })
152+
.fmt(fmt)?;
153+
}
154+
Some(value) => {
155+
KeyValuePair(self.pgls_config_path.name, markup! {{DebugDisplay(value)}})
156+
.fmt(fmt)?;
157+
}
158+
};
159+
94160
match self.pgt_log_path.value() {
95161
None => {
96162
KeyValuePair(self.pgt_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
@@ -99,6 +165,14 @@ impl Display for PgTEnv {
99165
KeyValuePair(self.pgt_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
100166
}
101167
};
168+
match self.pgt_log_level.value() {
169+
None => {
170+
KeyValuePair(self.pgt_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
171+
}
172+
Some(value) => {
173+
KeyValuePair(self.pgt_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
174+
}
175+
};
102176
match self.pgt_log_prefix.value() {
103177
None => {
104178
KeyValuePair(self.pgt_log_prefix.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};
@@ -200,9 +200,9 @@ pub fn create_config(
200200
configuration.schema = postgrestools_node_schema_path.to_str().map(String::from);
201201
} else if VERSION == "0.0.0" {
202202
// VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback)
203-
configuration.schema = Some(format!("{}/latest/schema.json", PGT_WEBSITE));
203+
configuration.schema = Some(format!("{}/latest/schema.json", PGLS_WEBSITE));
204204
} else {
205-
configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGT_WEBSITE));
205+
configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGLS_WEBSITE));
206206
}
207207

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

docs/codegen/src/env_variables.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,46 @@ 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

17+
writeln!(
18+
content,
19+
"### `{}`\n\n {}\n",
20+
env.pgls_log_path.name(),
21+
env.pgls_log_path.description()
22+
)?;
23+
writeln!(
24+
content,
25+
"### `{}`\n\n {}\n",
26+
env.pgls_log_level.name(),
27+
env.pgls_log_level.description()
28+
)?;
29+
writeln!(
30+
content,
31+
"### `{}`\n\n {}\n",
32+
env.pgls_log_prefix.name(),
33+
env.pgls_log_prefix.description()
34+
)?;
35+
writeln!(
36+
content,
37+
"### `{}`\n\n {}\n",
38+
env.pgls_config_path.name(),
39+
env.pgls_config_path.description()
40+
)?;
1741
writeln!(
1842
content,
1943
"### `{}`\n\n {}\n",
2044
env.pgt_log_path.name(),
2145
env.pgt_log_path.description()
2246
)?;
47+
writeln!(
48+
content,
49+
"### `{}`\n\n {}\n",
50+
env.pgt_log_level.name(),
51+
env.pgt_log_level.description()
52+
)?;
2353
writeln!(
2454
content,
2555
"### `{}`\n\n {}\n",

0 commit comments

Comments
 (0)