click_config_file icon indicating copy to clipboard operation
click_config_file copied to clipboard

Use nested commands

Open jochman opened this issue 3 years ago • 5 comments

Can use nested commands and provide a custom directory of the config file.

jochman avatar May 10 '21 16:05 jochman

Hi and thank you for your contribution.

It's already possible to set a default path like this:

configuration_option(default="/foo/bar")

Adding another option for basically the same purpose seems inconsistent. What happens if both options are set? Do you have a specific use case in mind that is not covered by simply setting default?

phha avatar May 15 '21 13:05 phha

The default is just to explicit the name of the file joined with click.get_app_dir(cmd_name). I've added the ability to specify in which directory it will be.

jochman avatar May 16 '21 08:05 jochman

I've also added the ability to use nested commands configuration for a multi-command app. lets say we have two commands, cmd-app cmd1 cmd-app cmd2

now we can create the next ini file:

[ cmd1 ]
option-1=True
option-2="./"

[ cmd2]
option-1=False

jochman avatar May 16 '21 08:05 jochman

@phha I'm pinging you :)

jochman avatar May 20 '21 06:05 jochman

Hi, sorry for the late reply. I've been a little busy.

I yet have to verify whether the default does indeed only set the file name and not the full path. If this is the case then this would be a bug which needs to be fixed. The default parameter should actually do what you wanted to accomplish by adding the new parameter.

As for multi-command apps, this should already be possible by adding a section parameter to the provider. The rationale behind this is that configuration_option should be agnostic with regards to the config file structure.

You can achieve this by doing something like this: @configuration_option(provider=configobj_provider(section="cmd2")).

phha avatar May 20 '21 07:05 phha