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

add support for TOML config #209

Merged
merged 2 commits into from
Aug 17, 2022
Merged

add support for TOML config #209

merged 2 commits into from
Aug 17, 2022

Conversation

rumpelsepp
Copy link
Member

@rumpelsepp rumpelsepp commented Jul 6, 2022

Depends on #9

An optional config file can be created in the following locations; the first one which is found will be used. It is searched in these locations in this particular order.

  • $PWD/gallia.toml
  • $current_git_root/gallia.toml
  • ~/.config/gallia/gallia.toml ($XDG_CONFIG_HOME is recognized according to the XDG standard)
  • /etc/xdg/gallia/gallia.toml

A path can be enforced by setting the environment variable GALLIA_CONFIG (the env variable avoids a chicken and egg problem with the ArgumentParser).

The config is used only for setting the defaults for the cli args. The cli flags have the highest priority, all config values have a corresponding flag. The argparse.Namespace object will stay as the source of truth for all configuration values. I suggest namespacing the configuration values.

A config template can be created like this:

$ gallia --template

@rumpelsepp rumpelsepp added the enhancement New feature or request label Jul 6, 2022
@rumpelsepp rumpelsepp added this to the v1.1.0 milestone Jul 6, 2022
@rumpelsepp rumpelsepp changed the base branch from master to cli July 6, 2022 16:07
src/gallia/command.py Outdated Show resolved Hide resolved
@rumpelsepp rumpelsepp force-pushed the cli branch 10 times, most recently from 30a94c2 to a329b52 Compare July 7, 2022 10:44
@rumpelsepp rumpelsepp marked this pull request as ready for review July 7, 2022 15:59
@rumpelsepp
Copy link
Member Author

rumpelsepp commented Jul 7, 2022

@peckto It is done.

here you can see it in action: 735ff48

Show all defaults for all commands:

$ gallia --show-defaults

Print a template with all config settings, commented.

$ gallia --template

If you create a config file and set a value there, you should see the default value changing.

Example:

$ cat gallia.toml
[gallia]
[gallia.scan]
target = "foo"
$ gallia --show-defaults | grep "foo"

@rumpelsepp rumpelsepp force-pushed the config-file branch 4 times, most recently from 755f4f7 to f69fa12 Compare July 8, 2022 06:23
@rumpelsepp rumpelsepp force-pushed the cli branch 2 times, most recently from 67ecdb5 to 265ca48 Compare July 8, 2022 06:31
@rumpelsepp rumpelsepp force-pushed the cli branch 3 times, most recently from 68ab86f to 0b6d17a Compare August 17, 2022 10:40
Base automatically changed from cli to master August 17, 2022 10:44
@rumpelsepp rumpelsepp merged commit bc9cdfe into master Aug 17, 2022
@rumpelsepp rumpelsepp deleted the config-file branch August 17, 2022 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants