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
feat: allow setting config file path through env var #344
base: main
Are you sure you want to change the base?
Conversation
✔️ 81b68d3 - Conventional commits check succeeded. |
Hey @tlegrave, I am not a big fan of doing this via env var while all the other configs are done with the CLI. |
Hey @oknozor, thanks for taking time to respond. I went back to the code, with your suggestion in mind. Adding a CLI arg was my first thought, but there is an issue I cannot solve, which is that the lazy Adding some println!("Starting main");
let cli = Cli::parse();
println!("Cli parsed"); impl TryFrom<&Repository> for Settings {
type Error = SettingError;
fn try_from(repo: &Repository) -> Result<Self, Self::Error> {
println!("Loading settings");
[...]
}
} And the result of the execution:
I was quite surprise at that point. I suppose this is due to the CLI subcommands, that need the Maybe I'm missing something (I'm still quite new to rust !). Hope this helps. |
Exactly, some of the args needs to preload settings in order to dynamically load the args possible values. InstallHook {
/// Type of hook to install
#[arg(value_parser = git_hook_types(), group = "git-hooks")]
hook_type: Vec<String>,
// etc needs: fn git_hook_types() -> PossibleValuesParser {
let hooks = SETTINGS
.git_hooks
.keys()
.map(|hook_type| hook_type.to_string());
hooks.into()
} A possible trick here, would be to parse the config flag first without |
Good idea yes, I was also thinking about some kind of " Waiting for more inputs (the env var at least works for the stuff I had to do, so no need to hurry...). |
Just posted a question on clap discussion space, clap-rs/clap#5232 |
This PRs brings the ability to define
cog.toml
file path throughCOG_CONFIG_PATH
environment variable (related to #343).The issue was first proposing to add an argument to the CLI but with the actual architecture this goal would require lots of changes in the code.
If
COG_CONFIG_PATH
is not specified, the previous value (i.e.cog.toml
) will be used.