Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taplo-cli: add ENV variable support #427

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions crates/taplo-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct TaploArgs {
#[derive(Clone, Args)]
pub struct GeneralArgs {
/// Path to the Taplo configuration file.
///
/// Configuration file can be specified in $TAPLO_CONFIG
razvanazamfirei marked this conversation as resolved.
Show resolved Hide resolved
#[clap(long, short)]
razvanazamfirei marked this conversation as resolved.
Show resolved Hide resolved
pub config: Option<PathBuf>,

Expand Down
10 changes: 9 additions & 1 deletion crates/taplo-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{anyhow, Context};
use args::GeneralArgs;
use itertools::Itertools;
use std::{
env,
path::{Path, PathBuf},
sync::Arc,
};
Expand Down Expand Up @@ -47,7 +48,14 @@ impl<E: Environment> Taplo<E> {

if config_path.is_none() && !general.no_auto_config {
if let Some(cwd) = self.env.cwd_normalized() {
config_path = self.env.find_config_file_normalized(&cwd).await
config_path = self.env.find_config_file_normalized(&cwd).await;
}
}

if config_path.is_none() {
tracing::debug!("Looking for config path in the environment variable");
if let Ok(path) = env::var("TAPLO_CONFIG") {
config_path = Some(path.into());
razvanazamfirei marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions site/site/cli/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ The available log levels:
<!-- TODO: config link -->

Taplo CLI by default searches for a Taplo config file in the current working directory, this behaviour can be disabled by either supplying `--no-auto-config` or `--config <path>` flags.

If a config file is not provided and no file is found in the current working directory, Taplo CLI will try to retrieve the configuration file path from the `TAPLO_CONFIG` environment variable.
razvanazamfirei marked this conversation as resolved.
Show resolved Hide resolved