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 configuration file for Cake. #833

Closed
patriksvensson opened this issue Apr 19, 2016 · 12 comments
Closed

Add configuration file for Cake. #833

patriksvensson opened this issue Apr 19, 2016 · 12 comments
Assignees
Labels
Milestone

Comments

@patriksvensson
Copy link
Member

patriksvensson commented Apr 19, 2016

Sometimes we want to be able to configure internals of Cake so I propose that we add support for this. My proposal is that we add ICakeConfiguration that will fetch values in the following order:

  1. Environment
  2. Configuration file
  3. Arguments
public interface ICakeConfiguration
{
  string GetValue(string key);
}
  • Configuration keys are case insensitive.

Environment variables:

Environment variables are named like the following convention:

CAKE_[KEY]

The CAKE_ part will be completely removed from the key name.

Example
PS> $env:CAKE_RUNTESTS=true
PS> $env:CAKE_TOOLS_PATH=D:/tools

Configuration file:

; Cake configuration file

; Global settings
RunTests=true

[Tools]
Path=D:/tools

Arguments:

Arguments are passed in the following format:

--[key]=[value]
Example:
Cake.exe --tools_path=D:/tools --runtests=true

Using the configuration

public void DoMagic(ICakeConfiguration config)
{
  var runTests = config.Get("RunTests");
  var toolPath2 = config.Get("Tools_Path");
}
@RLittlesII
Copy link
Contributor

@patriksvensson would there be a way for me to explicitly choose one of the configuration mechanisms? I can see myself attempting to send in configuration from a file unaware that someone has setup environment variables. Maybe on the -Verbosity diagnostic it can tell me which configuration is being respected.

@patriksvensson
Copy link
Member Author

@RLittlesII Different ways of getting configuration values will have different precedence.

  1. Arguments
  2. Configuration file
  3. Environment

So an environment variable can be overridden by a configuration file which in turn can be overridden by an argument.

@gitfool
Copy link
Contributor

gitfool commented Apr 26, 2016

Nice. FWIW, sounds a lot like aspnet/Configuration.

@patriksvensson patriksvensson added this to the v0.11.0 milestone Apr 27, 2016
@patriksvensson patriksvensson changed the title Add configuration file for Cake Add configuration file for Cake. Apr 27, 2016
@gep13
Copy link
Member

gep13 commented Apr 29, 2016

@gitfool said...
Nice. FWIW, sounds a lot like aspnet/Configuration.

Thanks, we are aware of the potential cross over. However, since that package is still pre-release, and also due to the fact that we don't want to pull in another dependency for Cake at this time, we decided to roll our own for now.

ChrisMaddock pushed a commit to ChrisMaddock/cake that referenced this issue May 5, 2016
@bspinner
Copy link
Contributor

Shouldn't the config-file also be respected by the build.ps1 and build.sh scripts?

@patriksvensson
Copy link
Member Author

No, the bootstrapper script are optional and more of a convenience thing. Each person will need to update their bootstrappers to fit their need.

@Meir017
Copy link

Meir017 commented Dec 28, 2016

any plans on migrating to Microsoft.Extensions.Configuration? we could use their Ini provider

@devlead
Copy link
Member

devlead commented Dec 28, 2016

@Meir017 no, but you could probably reference it as an addin if you want to utilize it in your build scripts.

@gep13
Copy link
Member

gep13 commented Dec 28, 2016

@Meir017 just to add a little more to this...

no, but you could probably reference it as an addin if you want to utilize it in your build scripts.

Cake has deliberately not taken dependencies on 3rd Party Libraries. This has aided us to continue to work seamlessly across all the target operating system and environments. Granted, libraries such as the one you mention are starting to work everywhere, but in all likelihood Cake will continue with the same premise, i.e. only take a dependency when there is literally no other way to achieve the desired outcome.

@khiemnd777
Copy link

khiemnd777 commented Jun 1, 2021

How do i use the CakeConfigration in build.cake file?

@pitermarx
Copy link
Contributor

I actually did exactly this manually. I have a JSON file with the defaults, then arguments override that and env vars override that. Would be nice to have it OOB

@pitermarx
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants