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

Support multiple configs with .erdtree.toml #201

Merged
merged 8 commits into from
Jun 26, 2023
Merged

Support multiple configs with .erdtree.toml #201

merged 8 commits into from
Jun 26, 2023

Conversation

solidiquis
Copy link
Owner

@solidiquis solidiquis commented Jun 26, 2023

Closes #159

What's new

This PR introduced the following key-value pair to the list of command-line arguments:

-c, --config <CONFIG>  Use configuration of named table rather than the top-level table in .erdtree.toml

In addition to supporting a .erdtreerc configuration file, erdtree now supports a .erdtree.toml TOML file as well. The .erdtree.toml file, unlike .erdtreerc, supports multiple configurations that you can specify using named tables. Here is an example of a valid .erdtree.toml file:

icons = true
human = true

# Compute file sizes like `du`
[du]
disk-usage = "block"
icons = true
layout = "flat"
no-ignore = true
no-git = true
hidden = true
level = 1

# Do as `ls -l`
[ls]
icons = true
human = true
level = 1
suppress-size = true
long = true

The top-level table only contains two arguments: icons = true and human = true. Without providing any arguments to -c, --config, the top-level table will get invoked which, after processing, will get transformed into erd --icons --human. To invoke configurations from a named table instead, pass the name of the table to -c, --config. Here are some examples given the above .erdtree.toml

$ erd

# equivalant to 

$ erd --human --icons

...

$ erd -c du

# equivalent to

$ erd --disk-usage block --icons --layout flat --no-ignore --no-git --hidden --level 1

User provided arguments take precedent over config

$ erd -c du --level 10

# equivalent to

$ erd --disk-usage block --icons --layout flat --no-ignore --no-git --hidden --level 10

Config rules

  • Unlike .erdtreerc, .erdtree.toml only accepts long-named arguments without the preceding --. Types are enforced, so numbers are expected to be numbers, booleans are expected to be booleans, strings are expected to be strings, and so on and so forth.

  • If you have both a .erdtreerc and a .erdtree.toml, the .erdtreerc will be prioritized and .erdtree.toml will be ignored. There is really no good reason for you to have both. Supporting .erdtreerc hence-forth will be for backwards compatibility.

  • This is the order wherein erdtree looks for the .erdtree.toml file on Unix platforms:

/// - `$ERDTREE_TOML_PATH`
/// - `$XDG_CONFIG_HOME/erdtree/.erdtree.toml`
/// - `$XDG_CONFIG_HOME/.erdtree.toml`
/// - `$HOME/.config/erdtree/.erdtree.toml`
/// - `$HOME/.erdtree.toml`

and on Windows:

/// `%APPDATA%/erdtree/.erdtree.toml`

@solidiquis solidiquis merged commit c42784f into v3.1 Jun 26, 2023
@solidiquis solidiquis mentioned this pull request Jun 26, 2023
@solidiquis solidiquis deleted the multi-config branch July 1, 2023 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant