private static bool TryParse(string workDirOption, string minMajorMinorOption, string verbosityOption, string autoIncrementOption, out string workDir, out MajorMinor minMajorMinor, out Verbosity verbosity, out VersionPart autoIncrement) { workDir = "."; minMajorMinor = null; verbosity = default; autoIncrement = default; if (!string.IsNullOrEmpty(workDirOption) && !Directory.Exists(workDir = workDirOption)) { Logger.ErrorWorkDirDoesNotExist(workDirOption); 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 (!string.IsNullOrEmpty(autoIncrementOption) && !Enum.TryParse(autoIncrementOption, true, out autoIncrement)) { Logger.ErrorInvalidAutoIncrement(autoIncrementOption); return(false); } return(true); }
private static bool TryParse(string repoOrWorkDirOption, string minMajorMinorOption, string verbosityOption, out string repoOrWorkDir, out MajorMinor minMajorMinor, out Verbosity verbosity) { repoOrWorkDir = "."; minMajorMinor = default; verbosity = default; if (!string.IsNullOrEmpty(repoOrWorkDirOption) && !Directory.Exists(repoOrWorkDir = repoOrWorkDirOption)) { Logger.ErrorRepoOrWorkDirDoesNotExist(repoOrWorkDirOption); 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); } return(true); }
public static bool TryParseEnvVars([NotNullWhen(returnValue: true)] out Options?options) { options = null; VersionPart?autoIncrement = 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 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, minMajorMinor, tagPrefix, verbosity, versionOverride); return(true); }
public static bool TryParse( string?autoIncrementOption, string?buildMetaOption, string?defaultPreReleasePhaseOption, 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, minMajorMinor, tagPrefixOption, verbosity, versionOverride); return(true); }
public static bool TryParse( string autoIncrementOption, string buildMetaOption, string defaultPreReleasePhaseOption, string minMajorMinorOption, string tagPrefixOption, string verbosityOption, #if MINVER string versionOverrideOption, #endif out Options options) { options = new Options(); if (!string.IsNullOrEmpty(autoIncrementOption)) { if (!Enum.TryParse <VersionPart>(autoIncrementOption, true, out var autoIncrement)) { Logger.ErrorInvalidAutoIncrement(autoIncrementOption); return(false); } options.AutoIncrement = autoIncrement; } options.BuildMeta = buildMetaOption; options.DefaultPreReleasePhase = defaultPreReleasePhaseOption; if (!string.IsNullOrEmpty(minMajorMinorOption)) { if (!MajorMinor.TryParse(minMajorMinorOption, out var minMajorMinor)) { Logger.ErrorInvalidMinMajorMinor(minMajorMinorOption); return(false); } options.MinMajorMinor = minMajorMinor; } options.TagPrefix = tagPrefixOption; if (!string.IsNullOrEmpty(verbosityOption)) { if (!VerbosityMap.TryMap(verbosityOption, out var verbosity)) { Logger.ErrorInvalidVerbosity(verbosityOption); return(false); } options.Verbosity = verbosity; } #if MINVER if (!string.IsNullOrEmpty(versionOverrideOption)) { if (!Lib.Version.TryParse(versionOverrideOption, out var versionOverride)) { Logger.ErrorInvalidVersionOverride(versionOverrideOption); return(false); } options.VersionOverride = versionOverride; } #endif return(true); }
public static bool TryParseEnvVars(out Options options) { options = new Options(); var autoIncrementEnvVar = GetEnvVar("MinVerAutoIncrement"); if (!string.IsNullOrEmpty(autoIncrementEnvVar)) { if (!Enum.TryParse <VersionPart>(autoIncrementEnvVar, true, out var autoIncrement)) { Logger.ErrorInvalidEnvVar("MinVerAutoIncrement", autoIncrementEnvVar, VersionPartEx.ValidValues); return(false); } options.AutoIncrement = autoIncrement; } options.BuildMeta = GetEnvVar("MinVerBuildMetadata"); options.DefaultPreReleasePhase = GetEnvVar("MinVerDefaultPreReleasePhase"); var minMajorMinorEnvVar = GetEnvVar("MinVerMinimumMajorMinor"); if (!string.IsNullOrEmpty(minMajorMinorEnvVar)) { if (!MajorMinor.TryParse(minMajorMinorEnvVar, out var minMajorMinor)) { Logger.ErrorInvalidEnvVar("MinVerMinimumMajorMinor", minMajorMinorEnvVar, MajorMinor.ValidValues); return(false); } options.MinMajorMinor = minMajorMinor; } options.TagPrefix = GetEnvVar("MinVerTagPrefix"); var verbosityEnvVar = GetEnvVar("MinVerVerbosity"); if (!string.IsNullOrEmpty(verbosityEnvVar)) { if (!VerbosityMap.TryMap(verbosityEnvVar, out var verbosity)) { Logger.ErrorInvalidEnvVar("MinVerVerbosity", verbosityEnvVar, VerbosityMap.ValidValues); return(false); } options.Verbosity = verbosity; } var versionOverrideEnvVar = GetEnvVar("MinVerVersionOverride"); if (!string.IsNullOrEmpty(versionOverrideEnvVar)) { if (!Lib.Version.TryParse(versionOverrideEnvVar, out var versionOverride)) { Logger.ErrorInvalidEnvVar("MinVerVersionOverride", versionOverrideEnvVar, null); return(false); } options.VersionOverride = versionOverride; } return(true); }