Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: rename env vars#558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
psteinroe merged 4 commits intomainfromfeat/support-both
Oct 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionscrates/pgt_cli/src/commands/clean.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
use crate::commands::daemon::default_pgt_log_path;
use crate::{CliDiagnostic, CliSession};
use pgt_env::pgt_env;
use pgt_env::pgls_env;
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

/// Runs the clean command
pub fn clean(_cli_session: CliSession) -> Result<(), CliDiagnostic> {
let logs_path =pgt_env()
let logs_path =pgls_env()
.pgt_log_path
.value()
.map_or(default_pgt_log_path(), PathBuf::from);
Expand Down
9 changes: 7 additions & 2 deletionscrates/pgt_cli/src/commands/daemon.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ use crate::{
use pgt_console::{ConsoleExt, markup};
use pgt_lsp::ServerFactory;
use pgt_workspace::{TransportError, WorkspaceError, workspace::WorkspaceClient};
use std::{env,path::PathBuf};
use std::path::PathBuf;
use tokio::io;
use tokio::runtime::Runtime;
use tracing::subscriber::Interest;
Expand DownExpand Up@@ -234,7 +234,12 @@ fn setup_tracing_subscriber(
}

pub fn default_pgt_log_path() -> PathBuf {
match env::var_os("PGT_LOG_PATH") {
let env = pgt_env::pgls_env();
match env
.pgls_log_path
.value()
.or_else(|| env.pgt_log_path.value())
{
Some(directory) => PathBuf::from(directory),
None => pgt_fs::ensure_cache_dir().join("pgt-logs"),
}
Expand Down
8 changes: 8 additions & 0 deletionscrates/pgt_cli/src/commands/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,6 +73,7 @@ pub enum PgtCommand {
/// Allows to change the prefix applied to the file name of the logs.
#[bpaf(
env("PGT_LOG_PREFIX_NAME"),
env("PGLS_LOG_PREFIX_NAME"),
long("log-prefix-name"),
argument("STRING"),
hide_usage,
Expand All@@ -84,6 +85,7 @@ pub enum PgtCommand {
/// Allows to change the folder where logs are stored.
#[bpaf(
env("PGT_LOG_PATH"),
env("PGLS_LOG_PATH"),
long("log-path"),
argument("PATH"),
hide_usage,
Expand DownExpand Up@@ -115,6 +117,7 @@ pub enum PgtCommand {
/// Allows to change the prefix applied to the file name of the logs.
#[bpaf(
env("PGT_LOG_PREFIX_NAME"),
env("PGLS_LOG_PREFIX_NAME"),
long("log-prefix-name"),
argument("STRING"),
hide_usage,
Expand All@@ -125,6 +128,7 @@ pub enum PgtCommand {
/// Allows to change the folder where logs are stored.
#[bpaf(
env("PGT_LOG_PATH"),
env("PGLS_LOG_PATH"),
long("log-path"),
argument("PATH"),
hide_usage,
Expand DownExpand Up@@ -154,6 +158,7 @@ pub enum PgtCommand {
/// Allows to change the prefix applied to the file name of the logs.
#[bpaf(
env("PGT_LOG_PREFIX_NAME"),
env("PGLS_LOG_PREFIX_NAME"),
long("log-prefix-name"),
argument("STRING"),
hide_usage,
Expand All@@ -165,6 +170,7 @@ pub enum PgtCommand {
/// Allows to change the folder where logs are stored.
#[bpaf(
env("PGT_LOG_PATH"),
env("PGLS_LOG_PATH"),
long("log-path"),
argument("PATH"),
hide_usage,
Expand All@@ -175,6 +181,7 @@ pub enum PgtCommand {
/// Allows to change the log level. Default is debug. This will only affect "pgt*" crates. All others are logged with info level.
#[bpaf(
env("PGT_LOG_LEVEL"),
env("PGLS_LOG_LEVEL"),
long("log-level"),
argument("trace|debug|info|warn|error|none"),
fallback(String::from("debug"))
Expand All@@ -184,6 +191,7 @@ pub enum PgtCommand {
/// Allows to change the logging format kind. Default is hierarchical.
#[bpaf(
env("PGT_LOG_KIND"),
env("PGLS_LOG_KIND"),
long("log-kind"),
argument("hierarchical|bunyan"),
fallback(String::from("hierarchical"))
Expand Down
4 changes: 2 additions & 2 deletionscrates/pgt_configuration/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,7 @@ use files::{FilesConfiguration, PartialFilesConfiguration, partial_files_configu
use migrations::{
MigrationsConfiguration, PartialMigrationsConfiguration, partial_migrations_configuration,
};
use pgt_env::PGT_WEBSITE;
use pgt_env::PGLS_WEBSITE;
use plpgsql_check::{
PartialPlPgSqlCheckConfiguration, PlPgSqlCheckConfiguration,
partial_pl_pg_sql_check_configuration,
Expand DownExpand Up@@ -103,7 +103,7 @@ impl PartialConfiguration {
/// Returns the initial configuration.
pub fn init() -> Self {
Self {
schema: Some(format!("{}/schemas/{VERSION}/schema.json",PGT_WEBSITE)),
schema: Some(format!("{}/schemas/{VERSION}/schema.json",PGLS_WEBSITE)),
extends: Some(StringSet::default()),
files: Some(PartialFilesConfiguration {
ignore: Some(Default::default()),
Expand Down
118 changes: 96 additions & 22 deletionscrates/pgt_env/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
//! Environment variables and configuration constants for PostgresTools.
//! Environment variables and configuration constants for PostgresLanguage Server.
//!
//! This module provides:
//! - Environment variable definitions for runtime configuration
Expand All@@ -10,13 +10,14 @@ use pgt_console::{DebugDisplay, KeyValuePair, markup};
use std::env;
use std::sync::{LazyLock, OnceLock};

/// Returns `true` if this is an unstable build of PostgresTools
/// Returns `true` if this is an unstable build of PostgresLanguage Server
pub fn is_unstable() -> bool {
VERSION == "0.0.0"
}

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

/// The version of Postgres Tools with fallback logic
pub const VERSION: &str = match option_env!("PGT_VERSION") {
Expand All@@ -27,44 +28,72 @@ pub const VERSION: &str = match option_env!("PGT_VERSION") {
},
};

pub staticPGT_WEBSITE: &str = "https://pgtools.dev";
pub staticPGLS_WEBSITE: &str = "https://pgtools.dev";

pub struct PgTEnv {
pub pgt_log_path: PgTEnvVariable,
pub pgt_log_prefix: PgTEnvVariable,
pub pgt_config_path: PgTEnvVariable,
pub struct PgLSEnv {
pub pgls_log_path: PgLSEnvVariable,
pub pgls_log_level: PgLSEnvVariable,
pub pgls_log_prefix: PgLSEnvVariable,
pub pgls_config_path: PgLSEnvVariable,

// DEPRECATED
pub pgt_log_path: PgLSEnvVariable,
pub pgt_log_level: PgLSEnvVariable,
pub pgt_log_prefix: PgLSEnvVariable,
pub pgt_config_path: PgLSEnvVariable,
}

pub static PGT_ENV: OnceLock<PgTEnv> = OnceLock::new();
pub static PGT_ENV: OnceLock<PgLSEnv> = OnceLock::new();

implPgTEnv {
implPgLSEnv {
fn new() -> Self {
Self {
pgt_log_path: PgTEnvVariable::new(
"PGT_LOG_PATH",
pgls_log_path: PgLSEnvVariable::new(
"PGLS_LOG_PATH",
"The directory where the Daemon logs will be saved.",
),
pgt_log_prefix: PgTEnvVariable::new(
"PGT_LOG_PREFIX_NAME",
pgls_log_level: PgLSEnvVariable::new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think thepgt log level is missing, was that intended? not sure if anybody except for me uses it 😆

psteinroe reacted with laugh emoji
"PGLS_LOG_LEVEL",
"Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level.",
),
pgls_log_prefix: PgLSEnvVariable::new(
"PGLS_LOG_PREFIX_NAME",
"A prefix that's added to the name of the log. Default: `server.log.`",
),
pgt_config_path: PgTEnvVariable::new(
"PGT_CONFIG_PATH",
pgls_config_path: PgLSEnvVariable::new(
"PGLS_CONFIG_PATH",
"A path to the configuration file",
),

pgt_log_path: PgLSEnvVariable::new(
"PGT_LOG_PATH",
"The directory where the Daemon logs will be saved. Deprecated, use PGLS_LOG_PATH instead.",
),
pgt_log_level: PgLSEnvVariable::new(
"PGT_LOG_LEVEL",
"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.",
),
pgt_log_prefix: PgLSEnvVariable::new(
"PGT_LOG_PREFIX_NAME",
"A prefix that's added to the name of the log. Default: `server.log`. Deprecated, use PGLS_LOG_PREFIX_NAME instead.",
),
pgt_config_path: PgLSEnvVariable::new(
"PGT_CONFIG_PATH",
"A path to the configuration file. Deprecated, use PGLS_CONFIG_PATH instead.",
),
}
}
}

pub structPgTEnvVariable {
pub structPgLSEnvVariable {
/// The name of the environment variable
name: &'static str,
/// The description of the variable.
// This field will be used in the website to automate its generation
description: &'static str,
}

implPgTEnvVariable {
implPgLSEnvVariable {
fn new(name: &'static str, description: &'static str) -> Self {
Self { name, description }
}
Expand All@@ -85,12 +114,49 @@ impl PgTEnvVariable {
}
}

pub fnpgt_env() -> &'staticPgTEnv {
PGT_ENV.get_or_init(PgTEnv::new)
pub fnpgls_env() -> &'staticPgLSEnv {
PGT_ENV.get_or_init(PgLSEnv::new)
}

impl Display forPgTEnv {
impl Display forPgLSEnv {
fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
match self.pgls_log_path.value() {
None => {
KeyValuePair(self.pgls_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
}
Some(value) => {
KeyValuePair(self.pgls_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
}
};
match self.pgls_log_level.value() {
None => {
KeyValuePair(self.pgls_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
}
Some(value) => {
KeyValuePair(self.pgls_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
}
};
match self.pgls_log_prefix.value() {
None => {
KeyValuePair(self.pgls_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
}
Some(value) => {
KeyValuePair(self.pgls_log_prefix.name, markup! {{DebugDisplay(value)}})
.fmt(fmt)?;
}
};

match self.pgls_config_path.value() {
None => {
KeyValuePair(self.pgls_config_path.name, markup! { <Dim>"unset"</Dim> })
.fmt(fmt)?;
}
Some(value) => {
KeyValuePair(self.pgls_config_path.name, markup! {{DebugDisplay(value)}})
.fmt(fmt)?;
}
};

match self.pgt_log_path.value() {
None => {
KeyValuePair(self.pgt_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
Expand All@@ -99,6 +165,14 @@ impl Display for PgTEnv {
KeyValuePair(self.pgt_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
}
};
match self.pgt_log_level.value() {
None => {
KeyValuePair(self.pgt_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
}
Some(value) => {
KeyValuePair(self.pgt_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?;
}
};
match self.pgt_log_prefix.value() {
None => {
KeyValuePair(self.pgt_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?;
Expand Down
6 changes: 3 additions & 3 deletionscrates/pgt_workspace/src/configuration.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ use pgt_configuration::{
VERSION, diagnostics::CantLoadExtendFile, push_to_analyser_rules,
};
use pgt_console::markup;
use pgt_env::PGT_WEBSITE;
use pgt_env::PGLS_WEBSITE;
use pgt_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions};

use crate::{DynRef, WorkspaceError, settings::Settings};
Expand DownExpand Up@@ -200,9 +200,9 @@ pub fn create_config(
configuration.schema = postgrestools_node_schema_path.to_str().map(String::from);
} else if VERSION == "0.0.0" {
// VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback)
configuration.schema = Some(format!("{}/latest/schema.json",PGT_WEBSITE));
configuration.schema = Some(format!("{}/latest/schema.json",PGLS_WEBSITE));
} else {
configuration.schema = Some(format!("{}/{VERSION}/schema.json",PGT_WEBSITE));
configuration.schema = Some(format!("{}/{VERSION}/schema.json",PGLS_WEBSITE));
}

let contents = serde_json::to_string_pretty(&configuration)
Expand Down
32 changes: 31 additions & 1 deletiondocs/codegen/src/env_variables.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,16 +10,46 @@ pub fn generate_env_variables(docs_dir: &Path) -> Result<()> {

let mut content = vec![];

let env = pgt_env::pgt_env();
let env = pgt_env::pgls_env();

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

writeln!(
content,
"### `{}`\n\n {}\n",
env.pgls_log_path.name(),
env.pgls_log_path.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
env.pgls_log_level.name(),
env.pgls_log_level.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
env.pgls_log_prefix.name(),
env.pgls_log_prefix.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
env.pgls_config_path.name(),
env.pgls_config_path.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
env.pgt_log_path.name(),
env.pgt_log_path.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
env.pgt_log_level.name(),
env.pgt_log_level.description()
)?;
writeln!(
content,
"### `{}`\n\n {}\n",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp