Skip to content

Commit

Permalink
config-environments: make non-experimental (#1153)
Browse files Browse the repository at this point in the history
* config-environments: make non-experimental

* config-environments: make non-experimental
  • Loading branch information
jdx authored Dec 13, 2023
1 parent c2623f7 commit 8019ce1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ v20.0.0
- [`~/.cache/rtx`](#cachertx)
- [`~/.local/share/rtx`](#localsharertx)
- [Templates](#templates)
- [[experimental] Config Environments](#experimental-config-environments)
- [Config Environments](#config-environments)
- [IDE Integration](#ide-integration)
- [Core Plugins](#core-plugins)
- [FAQs](#faqs)
Expand Down Expand Up @@ -611,7 +611,7 @@ Then when inside of `~/src/myproj/backend`, `node` will be `18`, `python` will b
will be `3.1`. You can check the active versions with `rtx ls --current`.

You can also have environment specific config files like `.rtx.production.toml`, see
[Config Environments](#experimental-config-environments) for more details.
[Config Environments](#config-environments) for more details.

#### `[env]` - Arbitrary Environment Variables

Expand Down Expand Up @@ -835,12 +835,12 @@ a different name.

Set to something other than `.rtx.toml` to have rtx look for `.rtx.toml` config files with a different name.

#### [experimental] `RTX_ENV`
#### `RTX_ENV`

Enables environment-specific config files such as `.rtx.development.toml`.
Use this for different env vars or different tool versions in
development/staging/production environments. See
[Config Environments](#experimental-config-environments) for more on how
[Config Environments](#config-environments) for more on how
to use this feature.

#### `RTX_USE_VERSIONS_HOST`
Expand Down Expand Up @@ -1123,10 +1123,6 @@ does not work for some reason.

## Templates

> **Warning**
>
> This functionality is experimental and may change in the future.
Templates are used in the following locations:

- `.tool-versions` files
Expand Down Expand Up @@ -1157,11 +1153,10 @@ Here's another using `exec()`:
current = "{{exec(command='node --version')}}"
```

## [experimental] Config Environments
## Config Environments

It's possible to have separate `.rtx.toml` files in the same directory for different
environments like `development` and `production`. To enable, set
`experimental = true` in `~/.config/rtx/config.toml`, then set `RTX_ENV` to an environment like
environments like `development` and `production`. To enable, set `RTX_ENV` to an environment like
`development` or `production`. rtx will then look for a `.rtx.{RTX_ENV}.toml` file in the current directory.

rtx will also look for "local" files like `.rtx.local.toml` and `.rtx.{RTX_ENV}.local.toml` in
Expand Down Expand Up @@ -2709,7 +2704,7 @@ Options:
Use the global config file (~/.config/rtx/config.toml) instead of the local one
-e, --env <ENV>
[experimental] Modify an environment-specific config file like .rtx.<env>.toml
Modify an environment-specific config file like .rtx.<env>.toml
-p, --path <PATH>
Specify a path to a config file or directory If a directory is specified, it will look for .rtx.toml (default) or .tool-versions
Expand Down
2 changes: 1 addition & 1 deletion completions/_rtx
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ __rtx_use_cmd() {
'--fuzzy[Save fuzzy version to config file]' \
'*--remove=[Remove the tool(s) from config file]:remove:' \
'(-g --global)'{-g,--global}'[Use the global config file (~/.config/rtx/config.toml) instead of the local one]' \
'(-e --env)'{-e,--env}'=[\[experimental\] Modify an environment-specific config file like .rtx.<env>.toml]:env:' \
'(-e --env)'{-e,--env}'=[Modify an environment-specific config file like .rtx.<env>.toml]:env:' \
'(-p --path)'{-p,--path}'=[Specify a path to a config file or directory If a directory is specified, it will look for .rtx.toml (default) or .tool-versions]:path:_files' \
'(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \
'(-q --quiet)'{-q,--quiet}'[Suppress output]' \
Expand Down
2 changes: 1 addition & 1 deletion completions/rtx.fish
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ complete -xc rtx -n "$fssf upgrade" -s n -l dry-run -d 'Just print what would be
complete -xc rtx -n "$fssf upgrade" -a "(__rtx_tool_versions)" -d 'Tool(s) to upgrade'
# use
complete -xc rtx -n "$fssf use" -s e -l env -d '[experimental] Modify an environment-specific config file like .rtx.<env>.toml'
complete -xc rtx -n "$fssf use" -s e -l env -d 'Modify an environment-specific config file like .rtx.<env>.toml'
complete -xc rtx -n "$fssf use" -l fuzzy -d 'Save fuzzy version to config file'
complete -xc rtx -n "$fssf use" -s g -l global -d 'Use the global config file (~/.config/rtx/config.toml) instead of the local one'
complete -xc rtx -n "$fssf use" -s p -l path -a "(__fish_complete_path)" -d 'Specify a path to a config file or directory If a directory is specified, it will look for .rtx.toml (default) or .tool-versions'
Expand Down
2 changes: 1 addition & 1 deletion src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Use {
#[clap(short, long, overrides_with_all = &["path", "env"])]
global: bool,

/// [experimental] Modify an environment-specific config file like .rtx.<env>.toml
/// Modify an environment-specific config file like .rtx.<env>.toml
#[clap(long, short, overrides_with_all = &["global", "path"])]
env: Option<String>,

Expand Down
15 changes: 4 additions & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ pub struct Config {
impl Config {
pub fn load() -> Result<Self> {
let global_config = load_rtxrc()?;
let config_filenames = load_config_filenames(&BTreeMap::new());
let settings = Settings::default_builder()
.preloaded(global_config.settings()?)
.load()?;
let config_filenames = load_config_filenames(&settings, &BTreeMap::new());
let plugins = load_plugins(&settings)?;
let config_files = load_all_config_files(
&settings,
Expand All @@ -72,7 +72,7 @@ impl Config {
trace!("Settings: {:#?}", settings);

let legacy_files = load_legacy_files(&settings, &plugins);
let config_filenames = load_config_filenames(&settings, &legacy_files);
let config_filenames = load_config_filenames(&legacy_files);
let config_track = track_config_files(&config_filenames);

let config_files = load_all_config_files(
Expand All @@ -99,10 +99,6 @@ impl Config {

let (env, env_sources) = load_env(&config_files);

if !settings.experimental && env::RTX_ENV.is_some() {
warn!("RTX_ENV is set but RTX_EXPERIMENTAL is not. Ignoring RTX_ENV.");
}

let config = Self {
env,
env_sources,
Expand Down Expand Up @@ -330,14 +326,11 @@ fn load_legacy_files(settings: &Settings, tools: &PluginMap) -> BTreeMap<String,
legacy_filenames
}

fn load_config_filenames(
settings: &Settings,
legacy_filenames: &BTreeMap<String, Vec<PluginName>>,
) -> Vec<PathBuf> {
fn load_config_filenames(legacy_filenames: &BTreeMap<String, Vec<PluginName>>) -> Vec<PathBuf> {
let mut filenames = legacy_filenames.keys().cloned().collect_vec();
filenames.push(env::RTX_DEFAULT_TOOL_VERSIONS_FILENAME.clone());
filenames.push(env::RTX_DEFAULT_CONFIG_FILENAME.clone());
if settings.experimental && *env::RTX_DEFAULT_CONFIG_FILENAME == ".rtx.toml" {
if *env::RTX_DEFAULT_CONFIG_FILENAME == ".rtx.toml" {
filenames.push(".rtx.local.toml".to_string());
if let Some(env) = &*env::RTX_ENV {
filenames.push(format!(".rtx.{}.toml", env));
Expand Down

0 comments on commit 8019ce1

Please sign in to comment.