Exemple #1
0
        private static Version GetVersion(string repoOrWorkDir, string tagPrefix, MajorMinor minMajorMinor, string buildMeta, Verbosity verbosity)
        {
            var log = new Logger(verbosity);

            if (log.IsDebugEnabled)
            {
                log.Debug($"MinVer {informationalVersion}.");
            }

            if (!RepositoryEx.TryCreateRepo(repoOrWorkDir, out var repo))
            {
                var version = new Version(minMajorMinor?.Major ?? 0, minMajorMinor?.Minor ?? 0, buildMeta);

                log.WarnIsNotAValidRepositoryOrWorkDirUsingDefaultVersion(repoOrWorkDir, version);

                return(version);
            }

            try
            {
                return(Versioner.GetVersion(repo, tagPrefix, minMajorMinor, buildMeta, log));
            }
            finally
            {
                repo.Dispose();
            }
        }
Exemple #2
0
        private static int Main(string[] args)
        {
            if (args.Contains("--major-minor", StringComparer.OrdinalIgnoreCase))
            {
                Console.Out.WriteLine("--major-minor has been renamed to --minimum-major-minor");
                return(2);
            }

            var app = new CommandLineApplication {
                Name = "minver", FullName = $"MinVer CLI {informationalVersion}"
            };

            app.HelpOption();

            var buildMetaOption     = app.Option("-b|--build-metadata <BUILD_METADATA>", "", CommandOptionType.SingleValue);
            var minMajorMinorOption = app.Option("-m|--minimum-major-minor <MINIMUM_MAJOR_MINOR>", MajorMinor.ValidValues, CommandOptionType.SingleValue);
            var repoOrWorkDirOption = app.Option("-r|--repo <REPO>", "Repository or working directory.", CommandOptionType.SingleValue);
            var tagPrefixOption     = app.Option("-t|--tag-prefix <TAG_PREFIX>", "", CommandOptionType.SingleValue);
            var verbosityOption     = app.Option("-v|--verbosity <VERBOSITY>", VerbosityMap.ValidValue, CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                if (!TryParse(repoOrWorkDirOption.Value(), minMajorMinorOption.Value(), verbosityOption.Value(), out var repoOrWorkDir, out var minMajorMinor, out var verbosity))
                {
                    return(2);
                }

                var log = new Logger(verbosity);

                if (log.IsDebugEnabled)
                {
                    log.Debug($"MinVer {informationalVersion}.");
                }

                var version = Versioner.GetVersion(repoOrWorkDir, tagPrefixOption.Value(), minMajorMinor, buildMetaOption.Value(), log);

                Console.Out.WriteLine(version);

                return(0);
            });

            return(app.Execute(args));
        }
Exemple #3
0
        private static int Main(string[] args)
        {
            using (var app = new CommandLineApplication {
                Name = "minver", FullName = $"MinVer CLI {informationalVersion}"
            })
            {
                app.HelpOption();

                var autoIncrementOption          = app.Option("-a|--auto-increment <VERSION_PART>", VersionPartEx.ValidValues, CommandOptionType.SingleValue);
                var buildMetaOption              = app.Option("-b|--build-metadata <BUILD_METADATA>", "", CommandOptionType.SingleValue);
                var defaultPreReleasePhaseOption = app.Option("-d|--default-pre-release-phase <PHASE>", "alpha (default), preview, etc.", CommandOptionType.SingleValue);
                var minMajorMinorOption          = app.Option("-m|--minimum-major-minor <MINIMUM_MAJOR_MINOR>", MajorMinor.ValidValues, CommandOptionType.SingleValue);
                var workDirOption   = app.Option("-r|--repo <REPO>", "Working directory.", CommandOptionType.SingleValue);
                var tagPrefixOption = app.Option("-t|--tag-prefix <TAG_PREFIX>", "", CommandOptionType.SingleValue);
                var verbosityOption = app.Option("-v|--verbosity <VERBOSITY>", VerbosityMap.ValidValue, CommandOptionType.SingleValue);
#if MINVER
                var versionOverrideOption = app.Option("-o|--version-override <VERSION>", "", CommandOptionType.SingleValue);
#endif

                app.OnExecute(() =>
                {
                    if (!TryParse(workDirOption.Value(), minMajorMinorOption.Value(), verbosityOption.Value(), autoIncrementOption.Value(), out var workDir, out var minMajorMinor, out var verbosity, out var autoIncrement))
                    {
                        return(2);
                    }

                    var log = new Logger(verbosity);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug($"MinVer {informationalVersion}.");
                    }

#if MINVER
                    Lib.Version version;
                    if (!string.IsNullOrEmpty(versionOverrideOption.Value()))
                    {
                        if (!Lib.Version.TryParse(versionOverrideOption.Value(), out version))
                        {
                            Logger.ErrorInvalidVersionOverride(versionOverrideOption.Value());
                            return(2);
                        }

                        log.Info($"Using version override {version}.");
                    }
                    else
                    {
                        version = Versioner.GetVersion(workDir, tagPrefixOption.Value(), minMajorMinor, buildMetaOption.Value(), autoIncrement, defaultPreReleasePhaseOption.Value(), log);
                    }
#else
                    var version = Versioner.GetVersion(workDir, tagPrefixOption.Value(), minMajorMinor, buildMetaOption.Value(), autoIncrement, defaultPreReleasePhaseOption.Value(), log);
#endif

                    Console.Out.WriteLine(version);

                    return(0);
                });

                return(app.Execute(args));
            }
        }
Exemple #4
0
        private static int Main(string[] args)
        {
            if (args.Contains("--major-minor", StringComparer.OrdinalIgnoreCase))
            {
                Console.Out.WriteLine("--major-minor has been renamed to --minimum-major-minor");
                return(2);
            }

            var app = new CommandLineApplication {
                Name = "minver", FullName = $"MinVer CLI {informationalVersion}"
            };

            app.HelpOption();

            var autoIncrementOption = app.Option("-a|--auto-increment <VERSION_PART>", VersionPart.Patch.GetValidValues(), CommandOptionType.SingleValue);
            var buildMetaOption     = app.Option("-b|--build-metadata <BUILD_METADATA>", "", CommandOptionType.SingleValue);
            var minMajorMinorOption = app.Option("-m|--minimum-major-minor <MINIMUM_MAJOR_MINOR>", MajorMinor.ValidValues, CommandOptionType.SingleValue);
            var repoOrWorkDirOption = app.Option("-r|--repo <REPO>", "Repository or working directory.", CommandOptionType.SingleValue);
            var tagPrefixOption     = app.Option("-t|--tag-prefix <TAG_PREFIX>", "", CommandOptionType.SingleValue);
            var verbosityOption     = app.Option("-v|--verbosity <VERBOSITY>", VerbosityMap.ValidValue, CommandOptionType.SingleValue);

#if MINVER
            var versionOverrideOption = app.Option("-o|--version-override <VERSION>", "", CommandOptionType.SingleValue);
#endif

            app.OnExecute(() =>
            {
                if (!TryParse(repoOrWorkDirOption.Value(), minMajorMinorOption.Value(), verbosityOption.Value(), autoIncrementOption.Value(), out var repoOrWorkDir, out var minMajorMinor, out var verbosity, out var autoIncrement))
                {
                    return(2);
                }

                var log = new Logger(verbosity);

                if (log.IsDebugEnabled)
                {
                    log.Debug($"MinVer {informationalVersion}.");
                }

#if MINVER
                Lib.Version version;
                if (!string.IsNullOrEmpty(versionOverrideOption.Value()))
                {
                    if (!Lib.Version.TryParse(versionOverrideOption.Value(), out version))
                    {
                        Logger.ErrorInvalidVersionOverride(versionOverrideOption.Value());
                        return(2);
                    }

                    log.Info($"Using version override {version}.");
                }
                else
                {
                    version = Versioner.GetVersion(repoOrWorkDir, tagPrefixOption.Value(), minMajorMinor, buildMetaOption.Value(), autoIncrement, log);
                }
#else
                var version = Versioner.GetVersion(repoOrWorkDir, tagPrefixOption.Value(), minMajorMinor, buildMetaOption.Value(), autoIncrement, log);
#endif

                Console.Out.WriteLine(version);

                return(0);
            });

            return(app.Execute(args));
        }
Exemple #5
0
        private static int Main(string[] args)
        {
            using (var app = new CommandLineApplication {
                Name = "minver", FullName = $"MinVer CLI {informationalVersion}"
            })
            {
                app.HelpOption();

                var workDirArg = app.Argument("workingDirectory", "Working directory (optional)");

                var autoIncrementOption          = app.Option("-a|--auto-increment <VERSION_PART>", VersionPartEx.ValidValues, CommandOptionType.SingleValue);
                var buildMetaOption              = app.Option("-b|--build-metadata <BUILD_METADATA>", "", CommandOptionType.SingleValue);
                var defaultPreReleasePhaseOption = app.Option("-d|--default-pre-release-phase <PHASE>", "alpha (default), preview, etc.", CommandOptionType.SingleValue);
                var minMajorMinorOption          = app.Option("-m|--minimum-major-minor <MINIMUM_MAJOR_MINOR>", MajorMinor.ValidValues, CommandOptionType.SingleValue);
#if MINVER_CLI
                var workDirOption = app.Option("-r|--repo <REPO>", "DEPRECATED — use the workingDirectory argument instead", CommandOptionType.SingleValue);
#endif
                var tagPrefixOption = app.Option("-t|--tag-prefix <TAG_PREFIX>", "", CommandOptionType.SingleValue);
                var verbosityOption = app.Option("-v|--verbosity <VERBOSITY>", VerbosityMap.ValidValues, CommandOptionType.SingleValue);
#if MINVER
                var versionOverrideOption = app.Option("-o|--version-override <VERSION>", "", CommandOptionType.SingleValue);
#endif

                app.OnExecute(() =>
                {
                    // optional argument — https://github.com/adamralph/minver/issues/436
                    var workDir = ".";

#if MINVER_CLI
                    if (!string.IsNullOrEmpty(workDirOption.Value()))
                    {
                        Logger.Warn("-r|--repo <REPO> is DEPRECATED — use the workingDirectory argument instead");
                    }
#endif

                    if (!string.IsNullOrEmpty(workDirArg.Value))
                    {
                        if (!Directory.Exists(workDir = workDirArg.Value))
                        {
                            Logger.ErrorWorkDirDoesNotExist(workDirArg.Value);
                            return(2);
                        }
                    }
#if MINVER_CLI
                    else if (!string.IsNullOrEmpty(workDirOption.Value()) && !Directory.Exists(workDir = workDirOption.Value()))
                    {
                        Logger.ErrorWorkDirDoesNotExist(workDirOption.Value());
                        return(2);
                    }
#endif

                    if (!Options.TryParse(
                            autoIncrementOption.Value(),
                            buildMetaOption.Value(),
                            defaultPreReleasePhaseOption.Value(),
                            minMajorMinorOption.Value(),
                            tagPrefixOption.Value(),
                            verbosityOption.Value(),
#if MINVER
                            versionOverrideOption.Value(),
#endif
                            out var options))
                    {
                        return(2);
                    }

#if MINVER_CLI
                    if (!Options.TryParseEnvVars(out var envOptions))
                    {
                        return(2);
                    }

                    options = options.Mask(envOptions);
#endif

                    var log = new Logger(options.Verbosity);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug($"MinVer {informationalVersion}.");
                    }

                    if (options.VersionOverride != null)
                    {
                        log.Info($"Using version override {options.VersionOverride}.");

                        Console.Out.WriteLine(options.VersionOverride);

                        return(0);
                    }

                    var version = Versioner.GetVersion(workDir, options.TagPrefix, options.MinMajorMinor, options.BuildMeta, options.AutoIncrement, options.DefaultPreReleasePhase, log);

                    Console.Out.WriteLine(version);

                    return(0);
                });

                return(app.Execute(args));
            }
        }
Exemple #6
0
        private static int Main(string[] args)
        {
            using var app = new CommandLineApplication { Name = "minver", FullName = $"MinVer CLI {informationalVersion}" };

            app.HelpOption();

            var workDirArg = app.Argument("workingDirectory", "Working directory (optional)");

            var autoIncrementOption          = app.Option("-a|--auto-increment <VERSION_PART>", VersionPartExtensions.ValidValues, CommandOptionType.SingleValue);
            var buildMetaOption              = app.Option("-b|--build-metadata <BUILD_METADATA>", "", CommandOptionType.SingleValue);
            var defaultPreReleasePhaseOption = app.Option("-d|--default-pre-release-phase <PHASE>", "alpha (default), preview, etc.", CommandOptionType.SingleValue);
            var minMajorMinorOption          = app.Option("-m|--minimum-major-minor <MINIMUM_MAJOR_MINOR>", MajorMinor.ValidValues, CommandOptionType.SingleValue);
            var tagPrefixOption              = app.Option("-t|--tag-prefix <TAG_PREFIX>", "", CommandOptionType.SingleValue);
            var verbosityOption              = app.Option("-v|--verbosity <VERBOSITY>", VerbosityMap.ValidValues, CommandOptionType.SingleValue);

#if MINVER
            var versionOverrideOption = app.Option("-o|--version-override <VERSION>", "", CommandOptionType.SingleValue);
#endif

            app.OnExecute(() =>
            {
                var workDir = workDirArg.Value ?? ".";

                if (!Directory.Exists(workDir))
                {
                    Logger.ErrorWorkDirDoesNotExist(workDir);
                    return(2);
                }

                if (!Options.TryParse(
                        autoIncrementOption.Value(),
                        buildMetaOption.Value(),
                        defaultPreReleasePhaseOption.Value(),
                        minMajorMinorOption.Value(),
                        tagPrefixOption.Value(),
                        verbosityOption.Value(),
#if MINVER
                        versionOverrideOption.Value(),
#endif
                        out var options))
                {
                    return(2);
                }

#if MINVER_CLI
                if (!Options.TryParseEnvVars(out var envOptions))
                {
                    return(2);
                }

                options = options.Mask(envOptions);
#endif

                var log = new Logger(options.Verbosity ?? default);

                _ = log.IsDebugEnabled && log.Debug($"MinVer {informationalVersion}.");

                if (options.VersionOverride != null)
                {
                    _ = log.IsInfoEnabled && log.Info($"Using version override {options.VersionOverride}.");

                    Console.Out.WriteLine(options.VersionOverride);

                    return(0);
                }

                var version = Versioner.GetVersion(workDir, options.TagPrefix ?? "", options.MinMajorMinor ?? MajorMinor.Zero, options.BuildMeta ?? "", options.AutoIncrement ?? default, options.DefaultPreReleasePhase ?? "", log);

                Console.Out.WriteLine(version);

                return(0);
            });

            return(app.Execute(args));
        }