Skip to content

Make config overwriteable via CLI arg#191

Open
matthiasbeyer wants to merge 1 commit intojdrouet:mainfrom
matthiasbeyer:overwriteable-config
Open

Make config overwriteable via CLI arg#191
matthiasbeyer wants to merge 1 commit intojdrouet:mainfrom
matthiasbeyer:overwriteable-config

Conversation

@matthiasbeyer
Copy link

Hi,

found this wonderful tool and figured that I want to be able to pass alternative configuration files to it, but found that there's no CLI arg for that yet, so I hacked something.

This is not tested at all, because I wanted to get your opinion first!

Have a great weekend!

@jdrouet
Copy link
Owner

jdrouet commented Jul 10, 2025

Hey,
Thanks for reaching me!
What kind of configuration do you want to pass? What's the purpose?

@matthiasbeyer
Copy link
Author

To point it to another configuration file.

@matthiasbeyer
Copy link
Author

Can we merge this?

@jdrouet
Copy link
Owner

jdrouet commented Oct 5, 2025

Sorry to take that much time to review this PR.

I think the configuration (config: Option<PathBuf>) should be global = true so that it can be caught by the different subcommand.

Then, you can update open_config as follow

    pub(crate) fn open_config(&self, path: &Option<std::path::PathBuf>) -> Result<Config, Error> {
        match path {
            Some(path) => Config::from_path(path).map_err(Error::from),
            None => {
                let root = self.backend.root_path()?;
                Config::from_root_path(&root).map_err(Error::from)
            }
        }
    }

That way, you don't need to update the trait, you just have to catch the global attribute in every command and call it like let config = svc.open_config(&self.config)?;

@matthiasbeyer
Copy link
Author

That does not work, because in the command implementation we do not have access to the config member from the global CLI implementation!

For example, in the execute() impl of CommandShow, we only get an instance of CommandShow, which does not have a config!

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
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.

2 participants