Exemple #1
0
    public static bool TryParse(
        string?autoIncrementOption,
        string?buildMetaOption,
        string?defaultPreReleasePhaseOption,
        bool?ignoreHeight,
        string?minMajorMinorOption,
        string?tagPrefixOption,
        string?verbosityOption,
#if MINVER
        string?versionOverrideOption,
#endif
        [NotNullWhen(returnValue: true)] out Options?options)
    {
        options = null;

        VersionPart?autoIncrement = null;
        MajorMinor? minMajorMinor = null;
        Verbosity?  verbosity     = null;

        Lib.Version?versionOverride = null;

        if (!string.IsNullOrEmpty(autoIncrementOption))
        {
            if (Enum.TryParse <VersionPart>(autoIncrementOption, true, out var versionPart))
            {
                autoIncrement = versionPart;
            }
            else
            {
                Logger.ErrorInvalidAutoIncrement(autoIncrementOption);
                return(false);
            }
        }

        if (!string.IsNullOrEmpty(minMajorMinorOption) && !MajorMinor.TryParse(minMajorMinorOption, out minMajorMinor))
        {
            Logger.ErrorInvalidMinMajorMinor(minMajorMinorOption);
            return(false);
        }

        if (!string.IsNullOrEmpty(verbosityOption) && !VerbosityMap.TryMap(verbosityOption, out verbosity))
        {
            Logger.ErrorInvalidVerbosity(verbosityOption);
            return(false);
        }

#if MINVER
        if (!string.IsNullOrEmpty(versionOverrideOption) && !Lib.Version.TryParse(versionOverrideOption, out versionOverride))
        {
            Logger.ErrorInvalidVersionOverride(versionOverrideOption);
            return(false);
        }
#endif

        options = new Options(autoIncrement, buildMetaOption, defaultPreReleasePhaseOption, ignoreHeight, minMajorMinor, tagPrefixOption, verbosity, versionOverride);

        return(true);
    }
Exemple #2
0
    public static bool TryParseEnvVars([NotNullWhen(returnValue: true)] out Options?options)
    {
        options = null;

        VersionPart?autoIncrement = null;
        bool?       ignoreHeight  = null;
        MajorMinor? minMajorMinor = null;
        Verbosity?  verbosity     = null;

        Lib.Version?versionOverride = null;

        var autoIncrementEnvVar = GetEnvVar("MinVerAutoIncrement");

        if (!string.IsNullOrEmpty(autoIncrementEnvVar))
        {
            if (Enum.TryParse <VersionPart>(autoIncrementEnvVar, true, out var versionPart))
            {
                autoIncrement = versionPart;
            }
            else
            {
                Logger.ErrorInvalidEnvVar("MinVerAutoIncrement", autoIncrementEnvVar, VersionPartExtensions.ValidValues);
                return(false);
            }
        }

        var buildMeta = GetEnvVar("MinVerBuildMetadata");

        var defaultPreReleasePhase = GetEnvVar("MinVerDefaultPreReleasePhase");

        var ignoreHeightEnvVar = GetEnvVar("MinVerIgnoreHeight");

        if (!string.IsNullOrEmpty(ignoreHeightEnvVar))
        {
            if (bool.TryParse(ignoreHeightEnvVar, out var value))
            {
                ignoreHeight = value;
            }
            else
            {
                Logger.ErrorInvalidEnvVar("MinVerIgnoreHeight", ignoreHeightEnvVar, "true, false (case insensitive)");
                return(false);
            }
        }

        var minMajorMinorEnvVar = GetEnvVar("MinVerMinimumMajorMinor");

        if (!string.IsNullOrEmpty(minMajorMinorEnvVar) && !MajorMinor.TryParse(minMajorMinorEnvVar, out minMajorMinor))
        {
            Logger.ErrorInvalidEnvVar("MinVerMinimumMajorMinor", minMajorMinorEnvVar, MajorMinor.ValidValues);
            return(false);
        }

        var tagPrefix = GetEnvVar("MinVerTagPrefix");

        var verbosityEnvVar = GetEnvVar("MinVerVerbosity");

        if (!string.IsNullOrEmpty(verbosityEnvVar) && !VerbosityMap.TryMap(verbosityEnvVar, out verbosity))
        {
            Logger.ErrorInvalidEnvVar("MinVerVerbosity", verbosityEnvVar, VerbosityMap.ValidValues);
            return(false);
        }

        var versionOverrideEnvVar = GetEnvVar("MinVerVersionOverride");

        if (!string.IsNullOrEmpty(versionOverrideEnvVar) && !Lib.Version.TryParse(versionOverrideEnvVar, out versionOverride))
        {
            Logger.ErrorInvalidEnvVar("MinVerVersionOverride", versionOverrideEnvVar, "");
            return(false);
        }

        options = new Options(autoIncrement, buildMeta, defaultPreReleasePhase, ignoreHeight, minMajorMinor, tagPrefix, verbosity, versionOverride);

        return(true);
    }