예제 #1
0
    public Context(ICakeContext context)
        : base(context)
    {
        BuildConfiguration = context.Argument("configuration", "Release");
        Runtime            = context.Argument("runtime", RuntimeEnvironment.GetRuntimeIdentifier());
        VersionSuffix      = context.Argument("version-suffix", string.Empty);

        var distFormat = context.Argument("dist-format", "zip").ToLowerInvariant();

        switch (distFormat)
        {
        case "bz":
        case "bz2":
        case "bzip":
        case "bzip2":
            DistributeFormat = DistributeFormat.BZip2;
            break;

        case "gz":
        case "gzip":
            DistributeFormat = DistributeFormat.GZip;
            break;

        // "z"
        // "zip"
        default:
            if (!string.IsNullOrEmpty(distFormat) && !new[] { "z", "zip" }.Contains(distFormat))
            {
                context.Log.Warning($"Invalid \"dist-format\" parameter. Assuming the default value \"{DistributeFormat.Zip}\"");
            }
            DistributeFormat = DistributeFormat.Zip;
            break;
        }

        var path = SearchBuildConfigFile();

        ConfigFile = !string.IsNullOrWhiteSpace(path)
            ? LoadBuildConfigFromFile(path)
            : ConfigFile.Default;

        ConfigFile.Ensure();

        BasePath = BasePath ?? Directory.GetCurrentDirectory();
    }