From 1d95f2ee43637df33c921ea87c3307ed70e5876e Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Fri, 21 Aug 2015 21:52:22 +0200 Subject: [PATCH 01/13] Command-style cli spike, for #428 --- .../ArgumentParserTests.cs | 27 +++++ .../GitVersionExe.Tests.csproj | 4 + src/GitVersionExe.Tests/packages.config | 1 + src/GitVersionExe/AssemblyInfo.cs | 1 + src/GitVersionExe/GitVersionExe.csproj | 12 ++ .../Options/BuildServerOptions.cs | 31 +++++ src/GitVersionExe/Options/ExecuteOptions.cs | 9 ++ src/GitVersionExe/Options/InitOptions.cs | 14 +++ .../Options/InspectRemoteRepositoryOptions.cs | 32 +++++ src/GitVersionExe/Options/LoggingOptions.cs | 15 +++ src/GitVersionExe/Options/MsBuildOptions.cs | 9 ++ src/GitVersionExe/Options/ShowOptions.cs | 18 +++ .../Options/UpdateAssemblyInfo.cs | 12 ++ src/GitVersionExe/Program.cs | 112 +++++------------- src/GitVersionExe/packages.config | 1 + 15 files changed, 213 insertions(+), 85 deletions(-) create mode 100644 src/GitVersionExe/Options/BuildServerOptions.cs create mode 100644 src/GitVersionExe/Options/ExecuteOptions.cs create mode 100644 src/GitVersionExe/Options/InitOptions.cs create mode 100644 src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs create mode 100644 src/GitVersionExe/Options/LoggingOptions.cs create mode 100644 src/GitVersionExe/Options/MsBuildOptions.cs create mode 100644 src/GitVersionExe/Options/ShowOptions.cs create mode 100644 src/GitVersionExe/Options/UpdateAssemblyInfo.cs diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 0169bd2f59..8677812b1f 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -1,12 +1,39 @@ using System; using System.Collections.Generic; +using System.Linq; +using CommandLine; +using CommandLine.Text; using GitVersion; +using GitVersion.Options; using NUnit.Framework; using Shouldly; [TestFixture] public class ArgumentParserTests { + [Explicit] + [Test] + public void PrintEntireHelp() + { + Parser.Default.ParseArguments(new[] { "help" }, AllOptionTypes().ToArray()); + foreach (var verb in new[] {"show", "init", "inspect-remote", "buildserver"}) + { + Parser.Default.ParseArguments(new[] { "help", verb }, AllOptionTypes().ToArray()); + } + + } + + IEnumerableAllOptionTypes() + { + yield return typeof(ShowOptions); + yield return typeof(InitOptions); + yield return typeof(InspectRemoteRepositoryOptions); + yield return typeof(BuildServerOptions); + yield return typeof(MsBuildOptions); + yield return typeof(ExecuteOptions); + yield return typeof(UpdateAssemblyInfo); + } + [Test] public void Empty_means_use_current_directory() { diff --git a/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj b/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj index d54c851fd4..73aa80b33b 100644 --- a/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj +++ b/src/GitVersionExe.Tests/GitVersionExe.Tests.csproj @@ -45,6 +45,10 @@ ..\packages\ApprovalUtilities.3.0.8\lib\net45\ApprovalUtilities.Net45.dll + + ..\packages\CommandLineParser.2.0.251-beta\lib\net45\CommandLine.dll + True + ..\packages\LibGit2Sharp.0.21.0.176\lib\net40\LibGit2Sharp.dll True diff --git a/src/GitVersionExe.Tests/packages.config b/src/GitVersionExe.Tests/packages.config index aa71fbaa59..32ee171c8d 100644 --- a/src/GitVersionExe.Tests/packages.config +++ b/src/GitVersionExe.Tests/packages.config @@ -2,6 +2,7 @@ + diff --git a/src/GitVersionExe/AssemblyInfo.cs b/src/GitVersionExe/AssemblyInfo.cs index 03d10be69b..30f6667c7d 100644 --- a/src/GitVersionExe/AssemblyInfo.cs +++ b/src/GitVersionExe/AssemblyInfo.cs @@ -8,3 +8,4 @@ [assembly: InternalsVisibleTo("GitVersionTask.Tests")] [assembly: InternalsVisibleTo("AcceptanceTests")] [assembly: InternalsVisibleTo("GitVersionExe.Tests")] +[assembly: AssemblyCopyrightAttribute("GitTools")] diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 95f2060c55..1db64c35fb 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -39,6 +39,10 @@ bin\Release\GitVersion.xml + + ..\packages\CommandLineParser.2.0.251-beta\lib\net40\CommandLine.dll + True + ..\packages\JetBrainsAnnotations.Fody.1.0.4.0\Lib\JetBrains.Annotations.dll False @@ -61,6 +65,14 @@ + + + + + + + + diff --git a/src/GitVersionExe/Options/BuildServerOptions.cs b/src/GitVersionExe/Options/BuildServerOptions.cs new file mode 100644 index 0000000000..a9ccd3a6ae --- /dev/null +++ b/src/GitVersionExe/Options/BuildServerOptions.cs @@ -0,0 +1,31 @@ +namespace GitVersion.Options +{ + using System.Collections.Generic; + using CommandLine; + using CommandLine.Text; + + [Verb("buildserver", + HelpText = "Inject gitversion variables as environment variables in your build server job.")] + class BuildServerOptions : LoggingOptions + { + [Option(HelpText = "Autodetect the build server, defaults to true.", Default = true)] + public bool AutoDetect { get; set; } + + [Option(HelpText = "The name of the buildserver to use in case auto-detect is false. " + + "One of TeamCity, AppVeyor, ContinuaCi, MyGet, VsoBuild, Jenkis")] + public string BuildServerName { get; set; } + + + [Usage()] + public static IEnumerable Examples + { + get + { + yield return new Example("Normal scenario, will detect build server automatically", new BuildServerOptions()); + yield return new Example("Specific build server, will run the specified build server integration", + UnParserSettings.WithGroupSwitchesOnly(), + new BuildServerOptions { AutoDetect = false, BuildServerName = "Jenkins" }); + } + } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/ExecuteOptions.cs b/src/GitVersionExe/Options/ExecuteOptions.cs new file mode 100644 index 0000000000..4386195108 --- /dev/null +++ b/src/GitVersionExe/Options/ExecuteOptions.cs @@ -0,0 +1,9 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("execute")] + class ExecuteOptions : LoggingOptions + { + } +} diff --git a/src/GitVersionExe/Options/InitOptions.cs b/src/GitVersionExe/Options/InitOptions.cs new file mode 100644 index 0000000000..bfa2858363 --- /dev/null +++ b/src/GitVersionExe/Options/InitOptions.cs @@ -0,0 +1,14 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("init", + HelpText = "Start configuration utility for gitversion.")] + class InitOptions : LoggingOptions + { + [Option('p', "path", + HelpText = "The path to inspect, defaults to current directory." + )] + public string Path { get; set; } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs new file mode 100644 index 0000000000..1d82962221 --- /dev/null +++ b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs @@ -0,0 +1,32 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("inspect-remote", + HelpText = "Inspect a remote repository.")] + class InspectRemoteRepositoryOptions : LoggingOptions + { + [Option("url", Required = true, + HelpText = "Url to remote git repository.")] + string Url { get; set; } + + [Option('b',"branch", + HelpText = "Name of the branch on the remote repository.")] + string Branch { get; set; } + + [Option('u', "username", + HelpText = "Username in case authentication is required.")] + public string UserName { get; set; } + + [Option('p', "password", + HelpText = "Password in case authentication is required.")] + public string Password { get; set; } + + [Option('c', "commit", + HelpText = "The commit id to check. If not specified, the latest available commit on the specified branch will be used.")] + public string CommitId { get; set; } + + [Option(HelpText = "Target directory to clone to.", Default = "%tmp%")] + public string DynamicRepositoryLocation { get; set; } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/LoggingOptions.cs b/src/GitVersionExe/Options/LoggingOptions.cs new file mode 100644 index 0000000000..46adcc436b --- /dev/null +++ b/src/GitVersionExe/Options/LoggingOptions.cs @@ -0,0 +1,15 @@ +namespace GitVersion.Options +{ + using CommandLine; + + class LoggingOptions + { + [Option( + HelpText = "Prints all messages to standard output.")] + public bool Verbose { get; set; } + + [Option( + HelpText = "Specify log file for system messages.")] + public string Log { get; set; } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/MsBuildOptions.cs b/src/GitVersionExe/Options/MsBuildOptions.cs new file mode 100644 index 0000000000..e156e5e554 --- /dev/null +++ b/src/GitVersionExe/Options/MsBuildOptions.cs @@ -0,0 +1,9 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("msbuild")] + class MsBuildOptions : LoggingOptions + { + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/ShowOptions.cs b/src/GitVersionExe/Options/ShowOptions.cs new file mode 100644 index 0000000000..67e8d3d1f8 --- /dev/null +++ b/src/GitVersionExe/Options/ShowOptions.cs @@ -0,0 +1,18 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("show", + HelpText = "Inspect git repository and output deduced version information.")] + class ShowOptions : LoggingOptions + { + [Option('p', "path", + HelpText = "The path to inspect, defaults to current directory." + )] + public string Path { get; set; } + + // variables to include + + // output type (plain, json, ?java properties, ?xml) + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/UpdateAssemblyInfo.cs b/src/GitVersionExe/Options/UpdateAssemblyInfo.cs new file mode 100644 index 0000000000..7890ec31c4 --- /dev/null +++ b/src/GitVersionExe/Options/UpdateAssemblyInfo.cs @@ -0,0 +1,12 @@ +namespace GitVersion.Options +{ + using CommandLine; + + [Verb("update-assembly-info")] + class UpdateAssemblyInfo : LoggingOptions + { + [Option('f', "filename", + HelpText = "Assembly information filename, defaults to 'AssemblyInfo.cs'.")] + public string AssemblyInformationFileName { get; set; } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index d6a20c44a9..20761a0192 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -6,7 +6,8 @@ namespace GitVersion using System.IO; using System.Linq; using System.Text; - using GitVersion.Helpers; + using CommandLine; + using GitVersion.Options; class Program { @@ -32,93 +33,32 @@ static void Main() static int VerifyArgumentsAndRun() { - Arguments arguments = null; - try - { - var fileSystem = new FileSystem(); - - var argumentsWithoutExeName = GetArgumentsWithoutExeName(); - try - { - arguments = ArgumentParser.ParseArguments(argumentsWithoutExeName); - } - catch (WarningException ex) - { - Console.WriteLine("Failed to parse arguments: {0}", string.Join(" ", argumentsWithoutExeName)); - if (!string.IsNullOrWhiteSpace(ex.Message)) - { - Console.WriteLine(); - Console.WriteLine(ex.Message); - Console.WriteLine(); - } - - HelpWriter.Write(); - return 1; - } - catch (Exception) - { - Console.WriteLine("Failed to parse arguments: {0}", string.Join(" ", argumentsWithoutExeName)); - - HelpWriter.Write(); - return 1; - } - if (arguments.IsHelp) - { - HelpWriter.Write(); - return 0; - } - - ConfigureLogging(arguments); - if (arguments.Init) - { - ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter()); - return 0; - } - if (arguments.ShowConfig) - { - Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(arguments.TargetPath, fileSystem)); - return 0; - } - - if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec)) - { - arguments.Output = OutputType.BuildServer; - } - - Logger.WriteInfo("Working directory: " + arguments.TargetPath); - - SpecifiedArgumentRunner.Run(arguments, fileSystem); - } - catch (WarningException exception) - { - var error = string.Format("An error occurred:\r\n{0}", exception.Message); - Logger.WriteWarning(error); - return 1; - } - catch (Exception exception) - { - var error = string.Format("An unexpected error occurred:\r\n{0}", exception); - Logger.WriteError(error); - - if (arguments != null) - { - Logger.WriteInfo(string.Empty); - Logger.WriteInfo("Here is the current git graph (please include in issue): "); - Logger.WriteInfo("Showing max of 100 commits"); - LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); - } - return 1; - } + var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); + return Parser.Default.ParseArguments(args) + .MapResult( + (ShowOptions opts) => Run(opts), + (InitOptions opts) => Run(opts), + (InspectRemoteRepositoryOptions opts) => Run(opts), + errs => 1); + } - return 0; + static int Run(object options) + { + return 1; } static void ConfigureLogging(Arguments arguments) { var writeActions = new List> - { - s => log.AppendLine(s) - }; + { + s => log.AppendLine(s) + }; if (arguments.Output == OutputType.BuildServer || arguments.LogFilePath == "console" || arguments.Init) { @@ -132,7 +72,9 @@ static void ConfigureLogging(Arguments arguments) Directory.CreateDirectory(Path.GetDirectoryName(arguments.LogFilePath)); if (File.Exists(arguments.LogFilePath)) { - using (File.CreateText(arguments.LogFilePath)) { } + using (File.CreateText(arguments.LogFilePath)) + { + } } writeActions.Add(x => WriteLogEntry(arguments, x)); @@ -158,8 +100,8 @@ static void WriteLogEntry(Arguments arguments, string s) static List GetArgumentsWithoutExeName() { return Environment.GetCommandLineArgs() - .Skip(1) - .ToList(); + .Skip(1) + .ToList(); } } } \ No newline at end of file diff --git a/src/GitVersionExe/packages.config b/src/GitVersionExe/packages.config index 7d5720e321..cd1cd28765 100644 --- a/src/GitVersionExe/packages.config +++ b/src/GitVersionExe/packages.config @@ -1,6 +1,7 @@  + From e5b6659171b165fffb8a88b61c041ea260312232 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Fri, 21 Aug 2015 22:18:46 +0200 Subject: [PATCH 02/13] Add "show" usage examples, for #428 --- .../ArgumentParserTests.cs | 8 +++++-- .../Options/BuildServerOptions.cs | 2 +- src/GitVersionExe/Options/ShowOptions.cs | 23 +++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 8677812b1f..681c4cc3fc 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using CommandLine; -using CommandLine.Text; using GitVersion; using GitVersion.Options; using NUnit.Framework; @@ -16,13 +15,18 @@ public class ArgumentParserTests public void PrintEntireHelp() { Parser.Default.ParseArguments(new[] { "help" }, AllOptionTypes().ToArray()); - foreach (var verb in new[] {"show", "init", "inspect-remote", "buildserver"}) + foreach (var verb in AllVerbs()) { Parser.Default.ParseArguments(new[] { "help", verb }, AllOptionTypes().ToArray()); } } + IEnumerable AllVerbs() + { + return new[] {"show", "init", "inspect-remote", "buildserver", "msbuild", "execute", "update-assembly-info"}; + } + IEnumerableAllOptionTypes() { yield return typeof(ShowOptions); diff --git a/src/GitVersionExe/Options/BuildServerOptions.cs b/src/GitVersionExe/Options/BuildServerOptions.cs index a9ccd3a6ae..b5feb16e1a 100644 --- a/src/GitVersionExe/Options/BuildServerOptions.cs +++ b/src/GitVersionExe/Options/BuildServerOptions.cs @@ -16,7 +16,7 @@ class BuildServerOptions : LoggingOptions public string BuildServerName { get; set; } - [Usage()] + [Usage(ApplicationAlias = "GitVersion")] public static IEnumerable Examples { get diff --git a/src/GitVersionExe/Options/ShowOptions.cs b/src/GitVersionExe/Options/ShowOptions.cs index 67e8d3d1f8..3eb6665a6a 100644 --- a/src/GitVersionExe/Options/ShowOptions.cs +++ b/src/GitVersionExe/Options/ShowOptions.cs @@ -1,6 +1,8 @@ namespace GitVersion.Options { + using System.Collections.Generic; using CommandLine; + using CommandLine.Text; [Verb("show", HelpText = "Inspect git repository and output deduced version information.")] @@ -11,8 +13,25 @@ class ShowOptions : LoggingOptions )] public string Path { get; set; } - // variables to include + [Option('o', "output", + HelpText = "The output format.", + Default = "Json" + )] + public string Output { get; set; } + + [Option('v', "variables")] + public IEnumerable Variables { get; set; } + - // output type (plain, json, ?java properties, ?xml) + [Usage(ApplicationAlias = "GitVersion")] + public static IEnumerable Examples + { + get + { + yield return new Example("Inspect the current directory, output version variables in Json format", new ShowOptions()); + yield return new Example("Inspect different directory", new ShowOptions { Path = @"c:\foo\bar\" }); + yield return new Example("Include only some variables", new ShowOptions { Variables = new[] {"SemVer", "Major", "Minor"} }); + } + } } } \ No newline at end of file From 4b6f9c5a628f19dc83c53a92b58acb31070c9836 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Sat, 22 Aug 2015 08:54:21 +0200 Subject: [PATCH 03/13] Add further documentation, rename some options for #428 --- .../ArgumentParserTests.cs | 21 ++++++++---- src/GitVersionExe/GitVersionExe.csproj | 8 ++--- src/GitVersionExe/Options/ExecuteOptions.cs | 9 ----- .../Options/InjectAssemblyInfo.cs | 30 ++++++++++++++++ ...Options.cs => InjectBuildServerOptions.cs} | 10 +++--- .../Options/InjectMsBuildOptions.cs | 24 +++++++++++++ src/GitVersionExe/Options/InjectProcess.cs | 34 +++++++++++++++++++ .../Options/InspectRemoteRepositoryOptions.cs | 4 +-- src/GitVersionExe/Options/LoggingOptions.cs | 2 +- src/GitVersionExe/Options/MsBuildOptions.cs | 9 ----- src/GitVersionExe/Options/ShowOptions.cs | 9 ++--- .../Options/UpdateAssemblyInfo.cs | 12 ------- src/GitVersionExe/Program.cs | 8 ++--- 13 files changed, 123 insertions(+), 57 deletions(-) delete mode 100644 src/GitVersionExe/Options/ExecuteOptions.cs create mode 100644 src/GitVersionExe/Options/InjectAssemblyInfo.cs rename src/GitVersionExe/Options/{BuildServerOptions.cs => InjectBuildServerOptions.cs} (77%) create mode 100644 src/GitVersionExe/Options/InjectMsBuildOptions.cs create mode 100644 src/GitVersionExe/Options/InjectProcess.cs delete mode 100644 src/GitVersionExe/Options/MsBuildOptions.cs delete mode 100644 src/GitVersionExe/Options/UpdateAssemblyInfo.cs diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 681c4cc3fc..ec49811593 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -17,14 +17,21 @@ public void PrintEntireHelp() Parser.Default.ParseArguments(new[] { "help" }, AllOptionTypes().ToArray()); foreach (var verb in AllVerbs()) { - Parser.Default.ParseArguments(new[] { "help", verb }, AllOptionTypes().ToArray()); + PrintVerbHelp(verb); } - + } + + [TestCaseSource("AllVerbs")] + public void PrintVerbHelp(string verb) + { + Parser.Default.ParseArguments(new[] {"help", verb}, AllOptionTypes().ToArray()); } IEnumerable AllVerbs() { - return new[] {"show", "init", "inspect-remote", "buildserver", "msbuild", "execute", "update-assembly-info"}; + return AllOptionTypes() + .Select(t => (VerbAttribute) Attribute.GetCustomAttribute(t, typeof(VerbAttribute))) + .Where(a => a != null).Select(a => a.Name); } IEnumerableAllOptionTypes() @@ -32,10 +39,10 @@ IEnumerable AllVerbs() yield return typeof(ShowOptions); yield return typeof(InitOptions); yield return typeof(InspectRemoteRepositoryOptions); - yield return typeof(BuildServerOptions); - yield return typeof(MsBuildOptions); - yield return typeof(ExecuteOptions); - yield return typeof(UpdateAssemblyInfo); + yield return typeof(InjectBuildServerOptions); + yield return typeof(InjectMsBuildOptions); + yield return typeof(InjectProcess); + yield return typeof(InjectAssemblyInfo); } [Test] diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 1db64c35fb..4966f72cc8 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -65,14 +65,14 @@ - + - - + + - + diff --git a/src/GitVersionExe/Options/ExecuteOptions.cs b/src/GitVersionExe/Options/ExecuteOptions.cs deleted file mode 100644 index 4386195108..0000000000 --- a/src/GitVersionExe/Options/ExecuteOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace GitVersion.Options -{ - using CommandLine; - - [Verb("execute")] - class ExecuteOptions : LoggingOptions - { - } -} diff --git a/src/GitVersionExe/Options/InjectAssemblyInfo.cs b/src/GitVersionExe/Options/InjectAssemblyInfo.cs new file mode 100644 index 0000000000..52d8ecb0c7 --- /dev/null +++ b/src/GitVersionExe/Options/InjectAssemblyInfo.cs @@ -0,0 +1,30 @@ +namespace GitVersion.Options +{ + using System.Collections.Generic; + using CommandLine; + using CommandLine.Text; + + [Verb("inject-assembly-info", + HelpText = "Search for all assembly information files in the git repo and update them using GitVersion variables.")] + class InjectAssemblyInfo : LoggingOptions + { + [Option('f', "filename", + HelpText = "Assembly information filename", Default = "AssemblyInfo.cs")] + public string AssemblyInformationFileName { get; set; } + + [Option('p', "path", + HelpText = "The path to inspect, defaults to current directory." + )] + public string Path { get; set; } + + [Usage(ApplicationAlias = "GitVersion")] + public static IEnumerable Examples + { + get + { + yield return new Example("Search all AssemblyInfo.cs and update with GitVersion variable information", new InjectAssemblyInfo()); + } + } + + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/BuildServerOptions.cs b/src/GitVersionExe/Options/InjectBuildServerOptions.cs similarity index 77% rename from src/GitVersionExe/Options/BuildServerOptions.cs rename to src/GitVersionExe/Options/InjectBuildServerOptions.cs index b5feb16e1a..6747d5b622 100644 --- a/src/GitVersionExe/Options/BuildServerOptions.cs +++ b/src/GitVersionExe/Options/InjectBuildServerOptions.cs @@ -4,15 +4,15 @@ using CommandLine; using CommandLine.Text; - [Verb("buildserver", + [Verb("inject-buildserver", HelpText = "Inject gitversion variables as environment variables in your build server job.")] - class BuildServerOptions : LoggingOptions + class InjectBuildServerOptions : LoggingOptions { [Option(HelpText = "Autodetect the build server, defaults to true.", Default = true)] public bool AutoDetect { get; set; } [Option(HelpText = "The name of the buildserver to use in case auto-detect is false. " + - "One of TeamCity, AppVeyor, ContinuaCi, MyGet, VsoBuild, Jenkis")] + "One of TeamCity, AppVeyor, ContinuaCi, MyGet, VsoBuild, Jenkins.")] public string BuildServerName { get; set; } @@ -21,10 +21,10 @@ public static IEnumerable Examples { get { - yield return new Example("Normal scenario, will detect build server automatically", new BuildServerOptions()); + yield return new Example("Normal scenario, will detect build server automatically", new InjectBuildServerOptions()); yield return new Example("Specific build server, will run the specified build server integration", UnParserSettings.WithGroupSwitchesOnly(), - new BuildServerOptions { AutoDetect = false, BuildServerName = "Jenkins" }); + new InjectBuildServerOptions { AutoDetect = false, BuildServerName = "Jenkins" }); } } } diff --git a/src/GitVersionExe/Options/InjectMsBuildOptions.cs b/src/GitVersionExe/Options/InjectMsBuildOptions.cs new file mode 100644 index 0000000000..21bf34b931 --- /dev/null +++ b/src/GitVersionExe/Options/InjectMsBuildOptions.cs @@ -0,0 +1,24 @@ +namespace GitVersion.Options +{ + using System.Collections.Generic; + using CommandLine; + using CommandLine.Text; + + [Verb("inject-msbuild", + HelpText = "Build an msbuild file, GitVersion variables will be injected as msbuild properties.")] + class InjectMsBuildOptions : LoggingOptions + { + [Option('f',"filename", HelpText = "MS build file to build.")] + public string BuildFileName { get; set; } + + [Usage(ApplicationAlias = "GitVersion")] + public static IEnumerable Examples + { + get + { + yield return new Example("Build msbuild file", new InjectMsBuildOptions { BuildFileName = "GitVersion.sln" }); + } + } + + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Options/InjectProcess.cs b/src/GitVersionExe/Options/InjectProcess.cs new file mode 100644 index 0000000000..82041c907e --- /dev/null +++ b/src/GitVersionExe/Options/InjectProcess.cs @@ -0,0 +1,34 @@ +namespace GitVersion.Options +{ + using System.Collections.Generic; + using CommandLine; + using CommandLine.Text; + + [Verb("inject-process", + HelpText = "Executes target executable injecting GitVersion variables as environmental variables.")] + class InjectProcess : LoggingOptions + { + [Option('e', "executable", HelpText = "Path to executable filename.", Required = true)] + public string ExecutableFileName { get; set; } + + [Option('a', "arguments")] + public string Arguments { get; set; } + + [Option('v', "variables", HelpText = "Variables to inject, defaults to all.")] + public IEnumerable Variables { get; set; } + + [Usage(ApplicationAlias = "GitVersion")] + public static IEnumerable Examples + { + get + { + yield return new Example("Inject all gitversion variables into MyApp", new InjectProcess { ExecutableFileName = "MyApp.exe" }); + yield return new Example("Inject only SemVer variable into MyApp", + new InjectProcess { ExecutableFileName = "MyApp.exe", Variables = new[] {"SemVer"}}); + yield return new Example("Start MyApp with --verbose and --short argument injecting all GitVersion variables", + new InjectProcess { ExecutableFileName = "MyApp.exe", Arguments = "--verbose --short" }); + } + } + + } +} diff --git a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs index 1d82962221..83fcb292f9 100644 --- a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs +++ b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs @@ -4,7 +4,7 @@ [Verb("inspect-remote", HelpText = "Inspect a remote repository.")] - class InspectRemoteRepositoryOptions : LoggingOptions + class InspectRemoteRepositoryOptions : ShowOptions { [Option("url", Required = true, HelpText = "Url to remote git repository.")] @@ -18,7 +18,7 @@ class InspectRemoteRepositoryOptions : LoggingOptions HelpText = "Username in case authentication is required.")] public string UserName { get; set; } - [Option('p', "password", + [Option("password", HelpText = "Password in case authentication is required.")] public string Password { get; set; } diff --git a/src/GitVersionExe/Options/LoggingOptions.cs b/src/GitVersionExe/Options/LoggingOptions.cs index 46adcc436b..92446d0bf5 100644 --- a/src/GitVersionExe/Options/LoggingOptions.cs +++ b/src/GitVersionExe/Options/LoggingOptions.cs @@ -5,7 +5,7 @@ class LoggingOptions { [Option( - HelpText = "Prints all messages to standard output.")] + HelpText = "Prints all system messages to standard output.")] public bool Verbose { get; set; } [Option( diff --git a/src/GitVersionExe/Options/MsBuildOptions.cs b/src/GitVersionExe/Options/MsBuildOptions.cs deleted file mode 100644 index e156e5e554..0000000000 --- a/src/GitVersionExe/Options/MsBuildOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace GitVersion.Options -{ - using CommandLine; - - [Verb("msbuild")] - class MsBuildOptions : LoggingOptions - { - } -} \ No newline at end of file diff --git a/src/GitVersionExe/Options/ShowOptions.cs b/src/GitVersionExe/Options/ShowOptions.cs index 3eb6665a6a..b7f158aa1a 100644 --- a/src/GitVersionExe/Options/ShowOptions.cs +++ b/src/GitVersionExe/Options/ShowOptions.cs @@ -13,8 +13,8 @@ class ShowOptions : LoggingOptions )] public string Path { get; set; } - [Option('o', "output", - HelpText = "The output format.", + [Option('f', "format", + HelpText = "The output format (Json, KeyValue or Values).", Default = "Json" )] public string Output { get; set; } @@ -22,7 +22,6 @@ class ShowOptions : LoggingOptions [Option('v', "variables")] public IEnumerable Variables { get; set; } - [Usage(ApplicationAlias = "GitVersion")] public static IEnumerable Examples { @@ -30,7 +29,9 @@ public static IEnumerable Examples { yield return new Example("Inspect the current directory, output version variables in Json format", new ShowOptions()); yield return new Example("Inspect different directory", new ShowOptions { Path = @"c:\foo\bar\" }); - yield return new Example("Include only some variables", new ShowOptions { Variables = new[] {"SemVer", "Major", "Minor"} }); + yield return new Example("Show only some variables", new ShowOptions { Variables = new[] {"SemVer", "Major", "Minor"} }); + yield return new Example("Output in key=value format, each pair on a new line", new ShowOptions { Output = "KeyValue" }); + yield return new Example("Show only one variable's value", UnParserSettings.WithGroupSwitchesOnly(), new ShowOptions { Output = "Values", Variables = new[] {"SemVer"} }); } } } diff --git a/src/GitVersionExe/Options/UpdateAssemblyInfo.cs b/src/GitVersionExe/Options/UpdateAssemblyInfo.cs deleted file mode 100644 index 7890ec31c4..0000000000 --- a/src/GitVersionExe/Options/UpdateAssemblyInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace GitVersion.Options -{ - using CommandLine; - - [Verb("update-assembly-info")] - class UpdateAssemblyInfo : LoggingOptions - { - [Option('f', "filename", - HelpText = "Assembly information filename, defaults to 'AssemblyInfo.cs'.")] - public string AssemblyInformationFileName { get; set; } - } -} \ No newline at end of file diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 20761a0192..3a0ffcef0c 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -37,10 +37,10 @@ static int VerifyArgumentsAndRun() return Parser.Default.ParseArguments(args) + InjectBuildServerOptions, + InjectMsBuildOptions, + InjectProcess, + InjectAssemblyInfo>(args) .MapResult( (ShowOptions opts) => Run(opts), (InitOptions opts) => Run(opts), From a47cb7c4bcf586cccdbe0cdcc9ce5c901ff0fe9b Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Sat, 22 Aug 2015 09:03:56 +0200 Subject: [PATCH 04/13] Using inheritance is not a good idea But using similar parameter names is. --- .../Options/InspectRemoteRepositoryOptions.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs index 83fcb292f9..06c751f1d8 100644 --- a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs +++ b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs @@ -1,10 +1,12 @@ namespace GitVersion.Options { + using System.Collections.Generic; using CommandLine; + using CommandLine.Text; [Verb("inspect-remote", HelpText = "Inspect a remote repository.")] - class InspectRemoteRepositoryOptions : ShowOptions + class InspectRemoteRepositoryOptions //: ShowOptions { [Option("url", Required = true, HelpText = "Url to remote git repository.")] @@ -28,5 +30,15 @@ class InspectRemoteRepositoryOptions : ShowOptions [Option(HelpText = "Target directory to clone to.", Default = "%tmp%")] public string DynamicRepositoryLocation { get; set; } + + [Usage(ApplicationAlias = "GitVersion")] + public static IEnumerable RemoteExamples + { + get + { + yield return new Example("Inspect GitVersion's remote repositsory ", + new InspectRemoteRepositoryOptions { Url = "https://github.com/GitTools/GitVersion.git" }); + } + } } } \ No newline at end of file From 66559c80171417c038083cf6a515c96c2e02c1af Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Sat, 22 Aug 2015 12:11:56 +0200 Subject: [PATCH 05/13] Rename show to inspect --- .../ArgumentParserTests.cs | 2 +- src/GitVersionExe/GitVersionExe.csproj | 2 +- .../{ShowOptions.cs => InspectOptions.cs} | 14 ++++++------ .../Options/InspectRemoteRepositoryOptions.cs | 22 ++++++++++++++----- src/GitVersionExe/Program.cs | 4 ++-- 5 files changed, 28 insertions(+), 16 deletions(-) rename src/GitVersionExe/Options/{ShowOptions.cs => InspectOptions.cs} (71%) diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index ec49811593..bd2f07243a 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -36,7 +36,7 @@ IEnumerable AllVerbs() IEnumerableAllOptionTypes() { - yield return typeof(ShowOptions); + yield return typeof(InspectOptions); yield return typeof(InitOptions); yield return typeof(InspectRemoteRepositoryOptions); yield return typeof(InjectBuildServerOptions); diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 4966f72cc8..f6191c064c 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -71,7 +71,7 @@ - + diff --git a/src/GitVersionExe/Options/ShowOptions.cs b/src/GitVersionExe/Options/InspectOptions.cs similarity index 71% rename from src/GitVersionExe/Options/ShowOptions.cs rename to src/GitVersionExe/Options/InspectOptions.cs index b7f158aa1a..110584011f 100644 --- a/src/GitVersionExe/Options/ShowOptions.cs +++ b/src/GitVersionExe/Options/InspectOptions.cs @@ -4,9 +4,9 @@ using CommandLine; using CommandLine.Text; - [Verb("show", + [Verb("inspect", HelpText = "Inspect git repository and output deduced version information.")] - class ShowOptions : LoggingOptions + class InspectOptions : LoggingOptions { [Option('p', "path", HelpText = "The path to inspect, defaults to current directory." @@ -27,11 +27,11 @@ public static IEnumerable Examples { get { - yield return new Example("Inspect the current directory, output version variables in Json format", new ShowOptions()); - yield return new Example("Inspect different directory", new ShowOptions { Path = @"c:\foo\bar\" }); - yield return new Example("Show only some variables", new ShowOptions { Variables = new[] {"SemVer", "Major", "Minor"} }); - yield return new Example("Output in key=value format, each pair on a new line", new ShowOptions { Output = "KeyValue" }); - yield return new Example("Show only one variable's value", UnParserSettings.WithGroupSwitchesOnly(), new ShowOptions { Output = "Values", Variables = new[] {"SemVer"} }); + yield return new Example("Inspect the current directory, output version variables in Json format", new InspectOptions()); + yield return new Example("Inspect different directory", new InspectOptions { Path = @"c:\foo\bar\" }); + yield return new Example("Show only some variables", new InspectOptions { Variables = new[] {"SemVer", "Major", "Minor"} }); + yield return new Example("Output in key=value format, each pair on a new line", new InspectOptions { Output = "KeyValue" }); + yield return new Example("Show only one variable's value", UnParserSettings.WithGroupSwitchesOnly(), new InspectOptions { Output = "Values", Variables = new[] {"SemVer"} }); } } } diff --git a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs index 06c751f1d8..1deb69758c 100644 --- a/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs +++ b/src/GitVersionExe/Options/InspectRemoteRepositoryOptions.cs @@ -4,15 +4,24 @@ using CommandLine; using CommandLine.Text; - [Verb("inspect-remote", + [Verb("inspect-remote", HelpText = "Inspect a remote repository.")] - class InspectRemoteRepositoryOptions //: ShowOptions + class InspectRemoteRepositoryOptions : LoggingOptions { + [Option('f', "format", + HelpText = "The output format (Json, KeyValue or Values).", + Default = "Json" + )] + public string Output { get; set; } + + [Option('v', "variables")] + public IEnumerable Variables { get; set; } + [Option("url", Required = true, HelpText = "Url to remote git repository.")] - string Url { get; set; } + public string Url { get; set; } - [Option('b',"branch", + [Option('b', "branch", HelpText = "Name of the branch on the remote repository.")] string Branch { get; set; } @@ -37,7 +46,10 @@ public static IEnumerable RemoteExamples get { yield return new Example("Inspect GitVersion's remote repositsory ", - new InspectRemoteRepositoryOptions { Url = "https://github.com/GitTools/GitVersion.git" }); + new InspectRemoteRepositoryOptions + { + Url = "https://github.com/GitTools/GitVersion.git" + }); } } } diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 3a0ffcef0c..0e1ea41455 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -34,7 +34,7 @@ static void Main() static int VerifyArgumentsAndRun() { var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); - return Parser.Default.ParseArguments(args) .MapResult( - (ShowOptions opts) => Run(opts), + (InspectOptions opts) => Run(opts), (InitOptions opts) => Run(opts), (InspectRemoteRepositoryOptions opts) => Run(opts), errs => 1); From 6db222730195cc14ae282d6a78a27188b154669d Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 17:45:28 +0200 Subject: [PATCH 06/13] Remove old ArgumentParser For #428. This is the first part of the rewrite to better see where we're going. I will implement this for three option verbs: * inspect * inject-buildserver * init --- .../ArgumentParserTests.cs | 238 +------------- src/GitVersionExe/ArgumentParser.cs | 308 ------------------ src/GitVersionExe/GitVersionExe.csproj | 2 +- src/GitVersionExe/Program.cs | 59 ++-- src/GitVersionExe/Runner.cs | 33 ++ 5 files changed, 87 insertions(+), 553 deletions(-) delete mode 100644 src/GitVersionExe/ArgumentParser.cs create mode 100644 src/GitVersionExe/Runner.cs diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index bd2f07243a..90abf38e50 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -46,237 +46,29 @@ IEnumerable AllVerbs() } [Test] - public void Empty_means_use_current_directory() + public void InputVariablesMustHaveCorrectDefaultValues() { - var arguments = ArgumentParser.ParseArguments(""); - arguments.TargetPath.ShouldBe(Environment.CurrentDirectory); - arguments.LogFilePath.ShouldBe(null); - arguments.IsHelp.ShouldBe(false); - } - - [Test] - public void Single_means_use_as_target_directory() - { - var arguments = ArgumentParser.ParseArguments("path"); - arguments.TargetPath.ShouldBe("path"); - arguments.LogFilePath.ShouldBe(null); - arguments.IsHelp.ShouldBe(false); - } - - [Test] - public void No_path_and_logfile_should_use_current_directory_TargetDirectory() - { - var arguments = ArgumentParser.ParseArguments("-l logFilePath"); - arguments.TargetPath.ShouldBe(Environment.CurrentDirectory); - arguments.LogFilePath.ShouldBe("logFilePath"); - arguments.IsHelp.ShouldBe(false); - } - - [Test] - public void h_means_IsHelp() - { - var arguments = ArgumentParser.ParseArguments("-h"); - Assert.IsNull(arguments.TargetPath); - Assert.IsNull(arguments.LogFilePath); - arguments.IsHelp.ShouldBe(true); - } - - [Test] - public void exec() - { - var arguments = ArgumentParser.ParseArguments("-exec rake"); - arguments.Exec.ShouldBe("rake"); - } - - [Test] - public void exec_with_args() - { - var arguments = ArgumentParser.ParseArguments(new List - { - "-exec", - "rake", - "-execargs", - "clean build" - }); - arguments.Exec.ShouldBe("rake"); - arguments.ExecArgs.ShouldBe("clean build"); - } - - [Test] - public void msbuild() - { - var arguments = ArgumentParser.ParseArguments("-proj msbuild.proj"); - arguments.Proj.ShouldBe("msbuild.proj"); - } + var iv = new InputVariables(); + + iv.TargetUrl.ShouldBe(null); - [Test] - public void msbuild_with_args() - { - var arguments = ArgumentParser.ParseArguments(new List - { - "-proj", - "msbuild.proj", - "-projargs", - "/p:Configuration=Debug /p:Platform=AnyCPU" - }); - arguments.Proj.ShouldBe("msbuild.proj"); - arguments.ProjArgs.ShouldBe("/p:Configuration=Debug /p:Platform=AnyCPU"); - } + iv.DynamicRepositoryLocation.ShouldBe(null); - [Test] - public void execwith_targetdirectory() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -exec rake"); - arguments.TargetPath.ShouldBe("targetDirectoryPath"); - arguments.Exec.ShouldBe("rake"); - } + iv.Authentication.ShouldNotBe(null); - [Test] - public void TargetDirectory_and_LogFilePath_can_be_parsed() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -l logFilePath"); - arguments.TargetPath.ShouldBe("targetDirectoryPath"); - arguments.LogFilePath.ShouldBe("logFilePath"); - arguments.IsHelp.ShouldBe(false); - } + var defaultAuthentication = new Authentication(); + iv.Authentication.Username.ShouldBeSameAs(defaultAuthentication.Username); + iv.Authentication.Password.ShouldBeSameAs(defaultAuthentication.Password); - [Test] - public void Username_and_Password_can_be_parsed() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -u [username] -p [password]"); - arguments.TargetPath.ShouldBe("targetDirectoryPath"); - arguments.Authentication.Username.ShouldBe("[username]"); - arguments.Authentication.Password.ShouldBe("[password]"); - arguments.IsHelp.ShouldBe(false); - } + iv.TargetUrl.ShouldBe(null); - [Test] - public void Unknown_output_should_throw() - { - var exception = Assert.Throws(() => ArgumentParser.ParseArguments("targetDirectoryPath -output invalid_value")); - exception.Message.ShouldBe("Value 'invalid_value' cannot be parsed as output type, please use 'json' or 'buildserver'"); - } + iv.TargetBranch.ShouldBe(null); - [Test] - public void Output_defaults_to_json() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath"); - arguments.Output.ShouldBe(OutputType.Json); - } + iv.NoFetch.ShouldBe(true); - [Test] - public void Output_json_can_be_parsed() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -output json"); - arguments.Output.ShouldBe(OutputType.Json); + iv.TargetPath.ShouldBe(Environment.CurrentDirectory); } - [Test] - public void Output_buildserver_can_be_parsed() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -output buildserver"); - arguments.Output.ShouldBe(OutputType.BuildServer); - } + // add tests for mapping input options to input variables - [Test] - public void MultipleArgsAndFlag() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -output buildserver -updateAssemblyInfo"); - arguments.Output.ShouldBe(OutputType.BuildServer); - } - - [Test] - public void Url_and_BranchName_can_be_parsed() - { - var arguments = ArgumentParser.ParseArguments("targetDirectoryPath -url http://github.com/Particular/GitVersion.git -b somebranch"); - arguments.TargetPath.ShouldBe("targetDirectoryPath"); - arguments.TargetUrl.ShouldBe("http://github.com/Particular/GitVersion.git"); - arguments.TargetBranch.ShouldBe("somebranch"); - arguments.IsHelp.ShouldBe(false); - } - - [Test] - public void Wrong_number_of_arguments_should_throw() - { - var exception = Assert.Throws(() => ArgumentParser.ParseArguments("targetDirectoryPath -l logFilePath extraArg")); - exception.Message.ShouldBe("Could not parse command line parameter 'extraArg'."); - } - - [Test] - public void Unknown_argument_should_throw() - { - var exception = Assert.Throws(() => ArgumentParser.ParseArguments("targetDirectoryPath -x logFilePath")); - exception.Message.ShouldBe("Could not parse command line parameter '-x'."); - } - - [TestCase("-updateAssemblyInfo true")] - [TestCase("-updateAssemblyInfo 1")] - [TestCase("-updateAssemblyInfo")] - [TestCase("-updateAssemblyInfo -proj foo.sln")] - public void update_assembly_info_true(string command) - { - var arguments = ArgumentParser.ParseArguments(command); - arguments.UpdateAssemblyInfo.ShouldBe(true); - } - - [TestCase("-updateAssemblyInfo false")] - [TestCase("-updateAssemblyInfo 0")] - public void update_assembly_info_false(string command) - { - var arguments = ArgumentParser.ParseArguments(command); - arguments.UpdateAssemblyInfo.ShouldBe(false); - } - - [Test] - public void update_assembly_info_with_filename() - { - var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo CommonAssemblyInfo.cs"); - arguments.UpdateAssemblyInfo.ShouldBe(true); - arguments.UpdateAssemblyInfoFileName.ShouldBe("CommonAssemblyInfo.cs"); - } - - [Test] - public void update_assembly_info_with_relative_filename() - { - var arguments = ArgumentParser.ParseArguments("-updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs"); - arguments.UpdateAssemblyInfo.ShouldBe(true); - arguments.UpdateAssemblyInfoFileName.ShouldBe("..\\..\\CommonAssemblyInfo.cs"); - } - - [Test] - public void dynamicRepoLocation() - { - var arguments = ArgumentParser.ParseArguments("-dynamicRepoLocation c:\\foo\\"); - arguments.DynamicRepositoryLocation.ShouldBe("c:\\foo\\"); - } - - [Test] - public void can_log_to_console() - { - var arguments = ArgumentParser.ParseArguments("-l console -proj foo.sln"); - arguments.LogFilePath.ShouldBe("console"); - } - - [Test] - public void nofetch_true_when_defined() - { - var arguments = ArgumentParser.ParseArguments("-nofetch"); - arguments.NoFetch = true; - } - - [Test] - public void other_arguments_can_be_parsed_before_nofetch() - { - var arguments = ArgumentParser.ParseArguments("targetpath -nofetch "); - arguments.TargetPath = "targetpath"; - arguments.NoFetch = true; - } - - [Test] - public void other_arguments_can_be_parsed_after_nofetch() - { - var arguments = ArgumentParser.ParseArguments("-nofetch -proj foo.sln"); - arguments.NoFetch = true; - arguments.Proj = "foo.sln"; - } -} \ No newline at end of file +} diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs deleted file mode 100644 index 620f543570..0000000000 --- a/src/GitVersionExe/ArgumentParser.cs +++ /dev/null @@ -1,308 +0,0 @@ -namespace GitVersion -{ - using System; - using System.Collections.Generic; - using System.Collections.Specialized; - using System.Linq; - using System.Text.RegularExpressions; - - - public class ArgumentParser - { - public static Arguments ParseArguments(string commandLineArguments) - { - return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList()); - } - - public static Arguments ParseArguments(List commandLineArguments) - { - if (commandLineArguments.Count == 0) - { - return new Arguments - { - TargetPath = Environment.CurrentDirectory - }; - } - - var firstArgument = commandLineArguments.First(); - if (IsHelp(firstArgument)) - { - return new Arguments - { - IsHelp = true - }; - } - if (IsInit(firstArgument)) - { - return new Arguments - { - TargetPath = Environment.CurrentDirectory, - Init = true - }; - } - - if (commandLineArguments.Count == 1 && !(commandLineArguments[0].StartsWith("-") || commandLineArguments[0].StartsWith("/"))) - { - return new Arguments - { - TargetPath = firstArgument - }; - } - - List namedArguments; - var arguments = new Arguments(); - if (firstArgument.StartsWith("-") || firstArgument.StartsWith("/")) - { - arguments.TargetPath = Environment.CurrentDirectory; - namedArguments = commandLineArguments; - } - else - { - arguments.TargetPath = firstArgument; - namedArguments = commandLineArguments.Skip(1).ToList(); - } - - var args = CollectSwitchesAndValuesFromArguments(namedArguments); - - foreach (var name in args.AllKeys) - { - var values = args.GetValues(name); - - string value = null; - - if (values != null) - { - //Currently, no arguments use more than one value, so having multiple values is an input error. - //In the future, this exception can be removed to support multiple values for a switch. - if (values.Length > 1) throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", values[1])); - - value = values.FirstOrDefault(); - } - - if (IsSwitch("l", name)) - { - arguments.LogFilePath = value; - continue; - } - - if (IsSwitch("targetpath", name)) - { - arguments.TargetPath = value; - continue; - } - - if (IsSwitch("dynamicRepoLocation", name)) - { - arguments.DynamicRepositoryLocation = value; - continue; - } - - if (IsSwitch("url", name)) - { - arguments.TargetUrl = value; - continue; - } - - if (IsSwitch("b", name)) - { - arguments.TargetBranch = value; - continue; - } - - if (IsSwitch("u", name)) - { - arguments.Authentication.Username = value; - continue; - } - - if (IsSwitch("p", name)) - { - arguments.Authentication.Password = value; - continue; - } - - if (IsSwitch("c", name)) - { - arguments.CommitId = value; - continue; - } - - if (IsSwitch("exec", name)) - { - arguments.Exec = value; - continue; - } - - if (IsSwitch("execargs", name)) - { - arguments.ExecArgs = value; - continue; - } - - if (IsSwitch("proj", name)) - { - arguments.Proj = value; - continue; - } - - if (IsSwitch("projargs", name)) - { - arguments.ProjArgs = value; - continue; - } - - if (IsSwitch("updateAssemblyInfo", name)) - { - if (new[] { "1", "true" }.Contains(value, StringComparer.OrdinalIgnoreCase)) - { - arguments.UpdateAssemblyInfo = true; - } - else if (new[] { "0", "false" }.Contains(value, StringComparer.OrdinalIgnoreCase)) - { - arguments.UpdateAssemblyInfo = false; - } - else if (!IsSwitchArgument(value)) - { - arguments.UpdateAssemblyInfo = true; - arguments.UpdateAssemblyInfoFileName = value; - } - else - { - arguments.UpdateAssemblyInfo = true; - } - continue; - } - - if (IsSwitch("assemblyversionformat", name)) - { - throw new WarningException("assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead"); - } - - if (IsSwitch("v", name) || IsSwitch("showvariable", name)) - { - string versionVariable = null; - - if (!string.IsNullOrWhiteSpace(value)) - { - versionVariable = VersionVariables.AvailableVariables.SingleOrDefault(av => av.Equals(value.Replace("'", ""), StringComparison.CurrentCultureIgnoreCase)); - } - - if (versionVariable == null) - { - var messageFormat = "{0} requires a valid version variable. Available variables are:\n{1}"; - var message = string.Format(messageFormat, name, String.Join(", ", VersionVariables.AvailableVariables.Select(x=>string.Concat("'", x, "'")))); - throw new WarningException(message); - } - - arguments.ShowVariable = versionVariable; - continue; - } - - if (IsSwitch("showConfig", name)) - { - if (new[] { "1", "true" }.Contains(value, StringComparer.OrdinalIgnoreCase)) - { - arguments.ShowConfig = true; - } - else if (new[] { "0", "false" }.Contains(value, StringComparer.OrdinalIgnoreCase)) - { - arguments.UpdateAssemblyInfo = false; - } - else - { - arguments.ShowConfig = true; - } - continue; - } - - if (IsSwitch("output", name)) - { - OutputType outputType; - if (!Enum.TryParse(value, true, out outputType)) - { - throw new WarningException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value)); - } - - arguments.Output = outputType; - continue; - } - - if (IsSwitch("nofetch", name)) - { - arguments.NoFetch = true; - continue; - } - - throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", name)); - } - - return arguments; - } - - static NameValueCollection CollectSwitchesAndValuesFromArguments(List namedArguments) - { - var args = new NameValueCollection(); - - string currentKey = null; - for (var index = 0; index < namedArguments.Count; index = index + 1) - { - var arg = namedArguments[index]; - //If this is a switch, create new name/value entry for it, with a null value. - if (IsSwitchArgument(arg)) - { - currentKey = arg; - args.Add(currentKey, null); - } - //If this is a value (not a switch) - else - { - //And if the current switch does not have a value yet, set it's value to this argument. - if (String.IsNullOrEmpty(args[currentKey])) - { - args[currentKey] = arg; - } - //Otherwise add the value under the same switch. - else - { - args.Add(currentKey, arg); - } - } - } - return args; - } - - static bool IsSwitchArgument(string value) - { - return value != null && (value.StartsWith("-") || value.StartsWith("/")) - && !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names. - } - - static bool IsSwitch(string switchName, string value) - { - if (value.StartsWith("-")) - { - value = value.Remove(0, 1); - } - - if (value.StartsWith("/")) - { - value = value.Remove(0, 1); - } - - return (string.Equals(switchName, value, StringComparison.OrdinalIgnoreCase)); - } - - static bool IsInit(string singleArgument) - { - return singleArgument.Equals("init", StringComparison.OrdinalIgnoreCase); - } - - static bool IsHelp(string singleArgument) - { - return (singleArgument == "?") || - IsSwitch("h", singleArgument) || - IsSwitch("help", singleArgument) || - IsSwitch("?", singleArgument); - } - } -} \ No newline at end of file diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index f6191c064c..62da61726e 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -61,7 +61,6 @@ - @@ -76,6 +75,7 @@ + diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 0e1ea41455..5f4fcbf3b3 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -17,15 +17,14 @@ static void Main() { var exitCode = VerifyArgumentsAndRun(); - if (Debugger.IsAttached) + if (exitCode != 0) { - Console.ReadKey(); + Console.Write(log.ToString()); } - if (exitCode != 0) + if (Debugger.IsAttached) { - // Dump log to console if we fail to complete successfully - Console.Write(log.ToString()); + Console.ReadKey(); } Environment.Exit(exitCode); @@ -33,26 +32,51 @@ static void Main() static int VerifyArgumentsAndRun() { - var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); - return Parser.Default.ParseArguments(args) - .MapResult( - (InspectOptions opts) => Run(opts), - (InitOptions opts) => Run(opts), - (InspectRemoteRepositoryOptions opts) => Run(opts), - errs => 1); + .WithParsed(InspectRunner.Run) + .WithParsed(InitRunner.Run) + //.WithParsed(Runner.Run) + .WithParsed(InjectBuildServerRunner.Run) + //.WithParsed(Runner.Run) + //.WithParsed(Runner.Run) + //.WithParsed(Runner.Run) + .WithNotParsed(HandleParseErrors); + + return 0; + } + catch (Exception e) + { + Console.WriteLine(e); + return 1; + } } - static int Run(object options) + static void HandleParseErrors(IEnumerable commandLineErrors) { - return 1; + var message = commandLineErrors.Aggregate("Error parsing arguments ...", + (current, err) => current + ("\nFailed to parse - " + err)); + throw new WarningException(message); } + static string[] GetArgumentsWithoutExeName() + { + return Environment.GetCommandLineArgs() + .Skip(1) + .ToArray(); + } + + + // Logging stuf + static void ConfigureLogging(Arguments arguments) { var writeActions = new List> @@ -96,12 +120,5 @@ static void WriteLogEntry(Arguments arguments, string s) var contents = string.Format("{0}\t\t{1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), s); File.AppendAllText(arguments.LogFilePath, contents); } - - static List GetArgumentsWithoutExeName() - { - return Environment.GetCommandLineArgs() - .Skip(1) - .ToList(); - } } } \ No newline at end of file diff --git a/src/GitVersionExe/Runner.cs b/src/GitVersionExe/Runner.cs new file mode 100644 index 0000000000..c8ce802a82 --- /dev/null +++ b/src/GitVersionExe/Runner.cs @@ -0,0 +1,33 @@ +using System; + +namespace GitVersion +{ + using GitVersion.Options; + + class InitRunner + { + public static void Run(InitOptions opts) + { + + throw new NotImplementedException(opts.GetType().Name); + } + } + + class InspectRunner + { + public static void Run(InspectOptions opts) + { + throw new NotImplementedException(opts.GetType().Name); + } + } + + class InjectBuildServerRunner + { + public static void Run(InjectBuildServerOptions opts) + { + throw new NotImplementedException(opts.GetType().Name); + } + } + + +} From 68cf44caef5c2b3b272e7d0bcca656f4f79beb8b Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 17:51:07 +0200 Subject: [PATCH 07/13] Scaffolding: extract the calculation of VersionVariables --- src/GitVersionExe/SpecifiedArgumentRunner.cs | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index 30324e4aae..031848bd54 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -5,10 +5,51 @@ namespace GitVersion using System.Linq; using GitVersion.Helpers; + public class InputVariables + { + public InputVariables() + { + Authentication = new Authentication(); + NoFetch = true; + } + + public string TargetUrl { get; set; } + public string DynamicRepositoryLocation { get; set; } + public Authentication Authentication { get; set; } + public string TargetBranch { get; set; } + public bool NoFetch { get; set; } + public string TargetPath { get; set; } + public string CommitId { get; set; } + } + class SpecifiedArgumentRunner { const string MsBuild = @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; + public static VersionVariables GetVariables(IFileSystem fileSystem, InputVariables inputVariables) + { + return GetVariables(fileSystem, + inputVariables.TargetUrl, + inputVariables.DynamicRepositoryLocation, + inputVariables.Authentication, + inputVariables.TargetBranch, + inputVariables.NoFetch, + inputVariables.TargetPath, + inputVariables.CommitId); + } + + private static VersionVariables GetVariables(IFileSystem fileSystem, + string targetUrl, + string dynamicRepositoryLocation, + Authentication authentication, + string targetBranch, + bool noFetch, + string targetPath, + string commitId) + { + return ExecuteCore.ExecuteGitVersion(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); + } + public static void Run(Arguments arguments, IFileSystem fileSystem) { var noFetch = arguments.NoFetch; @@ -19,7 +60,7 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; - var variables = ExecuteCore.ExecuteGitVersion(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); + var variables = GetVariables(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); if (arguments.Output == OutputType.BuildServer) { From 8be67b436b701d4262ca2e0edc8cc6867f965c19 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:09:00 +0200 Subject: [PATCH 08/13] Remove build server options that are not used --- src/GitVersionExe/Options/InjectBuildServerOptions.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/GitVersionExe/Options/InjectBuildServerOptions.cs b/src/GitVersionExe/Options/InjectBuildServerOptions.cs index 6747d5b622..cd1954cb01 100644 --- a/src/GitVersionExe/Options/InjectBuildServerOptions.cs +++ b/src/GitVersionExe/Options/InjectBuildServerOptions.cs @@ -8,23 +8,12 @@ HelpText = "Inject gitversion variables as environment variables in your build server job.")] class InjectBuildServerOptions : LoggingOptions { - [Option(HelpText = "Autodetect the build server, defaults to true.", Default = true)] - public bool AutoDetect { get; set; } - - [Option(HelpText = "The name of the buildserver to use in case auto-detect is false. " + - "One of TeamCity, AppVeyor, ContinuaCi, MyGet, VsoBuild, Jenkins.")] - public string BuildServerName { get; set; } - - [Usage(ApplicationAlias = "GitVersion")] public static IEnumerable Examples { get { yield return new Example("Normal scenario, will detect build server automatically", new InjectBuildServerOptions()); - yield return new Example("Specific build server, will run the specified build server integration", - UnParserSettings.WithGroupSwitchesOnly(), - new InjectBuildServerOptions { AutoDetect = false, BuildServerName = "Jenkins" }); } } } From 3a7f4628e73a430f344fd132f6f6dbf412fc84cf Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:09:34 +0200 Subject: [PATCH 09/13] Move inject-buildserver code, for #428 --- src/GitVersionExe/Runner.cs | 10 +++++++++- src/GitVersionExe/SpecifiedArgumentRunner.cs | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/GitVersionExe/Runner.cs b/src/GitVersionExe/Runner.cs index c8ce802a82..ac0618157d 100644 --- a/src/GitVersionExe/Runner.cs +++ b/src/GitVersionExe/Runner.cs @@ -2,6 +2,7 @@ namespace GitVersion { + using GitVersion.Helpers; using GitVersion.Options; class InitRunner @@ -25,7 +26,14 @@ class InjectBuildServerRunner { public static void Run(InjectBuildServerOptions opts) { - throw new NotImplementedException(opts.GetType().Name); + var inputVariables = new InputVariables(); // TODO: how to map to input variables + var fs = new FileSystem(); + var variables = SpecifiedArgumentRunner.GetVariables(fs, inputVariables); + + foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) + { + buildServer.WriteIntegration(Console.WriteLine, variables); + } } } diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index 031848bd54..60de196ac9 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -62,14 +62,6 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) var variables = GetVariables(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); - if (arguments.Output == OutputType.BuildServer) - { - foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) - { - buildServer.WriteIntegration(Console.WriteLine, variables); - } - } - if (arguments.Output == OutputType.Json) { switch (arguments.ShowVariable) From 7feb103151aed19eadc350ae4ecc6f04be5e6517 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:11:43 +0200 Subject: [PATCH 10/13] Cleanup only --- .../ArgumentParserTests.cs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index 90abf38e50..6edcc218a0 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -10,17 +10,6 @@ [TestFixture] public class ArgumentParserTests { - [Explicit] - [Test] - public void PrintEntireHelp() - { - Parser.Default.ParseArguments(new[] { "help" }, AllOptionTypes().ToArray()); - foreach (var verb in AllVerbs()) - { - PrintVerbHelp(verb); - } - } - [TestCaseSource("AllVerbs")] public void PrintVerbHelp(string verb) { @@ -34,7 +23,7 @@ IEnumerable AllVerbs() .Where(a => a != null).Select(a => a.Name); } - IEnumerableAllOptionTypes() + IEnumerable AllOptionTypes() { yield return typeof(InspectOptions); yield return typeof(InitOptions); @@ -49,8 +38,8 @@ IEnumerable AllVerbs() public void InputVariablesMustHaveCorrectDefaultValues() { var iv = new InputVariables(); - - iv.TargetUrl.ShouldBe(null); + + iv.TargetUrl.ShouldBe(null); iv.DynamicRepositoryLocation.ShouldBe(null); @@ -69,6 +58,15 @@ public void InputVariablesMustHaveCorrectDefaultValues() iv.TargetPath.ShouldBe(Environment.CurrentDirectory); } - // add tests for mapping input options to input variables + [Explicit] + [Test] + public void PrintEntireHelp() + { + Parser.Default.ParseArguments(new[] {"help"}, AllOptionTypes().ToArray()); + foreach (var verb in AllVerbs()) + { + PrintVerbHelp(verb); + } + } -} +} \ No newline at end of file From b5a4dc93c8ed9ee393f6f187dcb543717df0b721 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:23:02 +0200 Subject: [PATCH 11/13] Move code to InspectRunner, for #428 --- src/GitVersionExe/Runner.cs | 29 +++++++++++++++++++- src/GitVersionExe/SpecifiedArgumentRunner.cs | 19 ------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/GitVersionExe/Runner.cs b/src/GitVersionExe/Runner.cs index ac0618157d..6be3e7ff18 100644 --- a/src/GitVersionExe/Runner.cs +++ b/src/GitVersionExe/Runner.cs @@ -2,6 +2,7 @@ namespace GitVersion { + using System.Linq; using GitVersion.Helpers; using GitVersion.Options; @@ -18,7 +19,33 @@ class InspectRunner { public static void Run(InspectOptions opts) { - throw new NotImplementedException(opts.GetType().Name); + var inputVariables = new InputVariables() + { + TargetPath = opts.Path, + }; + + var fs = new FileSystem(); + var allVariables = SpecifiedArgumentRunner.GetVariables(fs, inputVariables); + + // TODO: allow more variables + var showVariable = opts.Variables.First(); + + switch (showVariable) + { + case null: + // TODO: allow more output formatters + Console.WriteLine(JsonOutputFormatter.ToJson(allVariables)); + break; + + default: + string part; + if (!allVariables.TryGetValue(showVariable, out part)) + { + throw new WarningException(string.Format("'{0}' variable does not exist", showVariable)); + } + Console.WriteLine(part); + break; + } } } diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index 60de196ac9..05d3d3eee1 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -62,25 +62,6 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) var variables = GetVariables(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId); - if (arguments.Output == OutputType.Json) - { - switch (arguments.ShowVariable) - { - case null: - Console.WriteLine(JsonOutputFormatter.ToJson(variables)); - break; - - default: - string part; - if (!variables.TryGetValue(arguments.ShowVariable, out part)) - { - throw new WarningException(string.Format("'{0}' variable does not exist", arguments.ShowVariable)); - } - Console.WriteLine(part); - break; - } - } - using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, targetPath, variables, fileSystem)) { var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); From 99f43c60d8201d00a2fa0d0702abea26de85f7a7 Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:26:52 +0200 Subject: [PATCH 12/13] Add init runner, for #428 Taken from original program.cs --- src/GitVersionExe/Runner.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitVersionExe/Runner.cs b/src/GitVersionExe/Runner.cs index 6be3e7ff18..d47830203c 100644 --- a/src/GitVersionExe/Runner.cs +++ b/src/GitVersionExe/Runner.cs @@ -10,8 +10,8 @@ class InitRunner { public static void Run(InitOptions opts) { - - throw new NotImplementedException(opts.GetType().Name); + var fs = new FileSystem(); + ConfigurationProvider.Init(opts.Path, fs, new ConsoleAdapter()); } } From 0bbe38cc6bcce5581d8a711f33350d6409371d8e Mon Sep 17 00:00:00 2001 From: Marijn van der Zee Date: Mon, 24 Aug 2015 18:28:30 +0200 Subject: [PATCH 13/13] Move to runners to own namespace, for #428 --- src/GitVersionExe/GitVersionExe.csproj | 5 ++- src/GitVersionExe/Program.cs | 1 + src/GitVersionExe/Runners/InitRunner.cs | 14 ++++++++ .../Runners/InjectBuildServerRunner.cs | 21 ++++++++++++ .../{Runner.cs => Runners/InspectRunner.cs} | 33 ++----------------- 5 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 src/GitVersionExe/Runners/InitRunner.cs create mode 100644 src/GitVersionExe/Runners/InjectBuildServerRunner.cs rename src/GitVersionExe/{Runner.cs => Runners/InspectRunner.cs} (59%) diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 62da61726e..a888b0ce43 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -64,6 +64,8 @@ + + @@ -75,7 +77,7 @@ - + @@ -113,6 +115,7 @@ GitVersionCore + diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 5f4fcbf3b3..7fb41d9e01 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -8,6 +8,7 @@ namespace GitVersion using System.Text; using CommandLine; using GitVersion.Options; + using GitVersion.Runners; class Program { diff --git a/src/GitVersionExe/Runners/InitRunner.cs b/src/GitVersionExe/Runners/InitRunner.cs new file mode 100644 index 0000000000..6e62517d18 --- /dev/null +++ b/src/GitVersionExe/Runners/InitRunner.cs @@ -0,0 +1,14 @@ +namespace GitVersion.Runners +{ + using GitVersion.Helpers; + using GitVersion.Options; + + class InitRunner + { + public static void Run(InitOptions opts) + { + var fs = new FileSystem(); + ConfigurationProvider.Init(opts.Path, fs, new ConsoleAdapter()); + } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Runners/InjectBuildServerRunner.cs b/src/GitVersionExe/Runners/InjectBuildServerRunner.cs new file mode 100644 index 0000000000..7c2fcaf7d0 --- /dev/null +++ b/src/GitVersionExe/Runners/InjectBuildServerRunner.cs @@ -0,0 +1,21 @@ +namespace GitVersion.Runners +{ + using System; + using GitVersion.Helpers; + using GitVersion.Options; + + class InjectBuildServerRunner + { + public static void Run(InjectBuildServerOptions opts) + { + var inputVariables = new InputVariables(); // TODO: how to map to input variables + var fs = new FileSystem(); + var variables = SpecifiedArgumentRunner.GetVariables(fs, inputVariables); + + foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) + { + buildServer.WriteIntegration(Console.WriteLine, variables); + } + } + } +} \ No newline at end of file diff --git a/src/GitVersionExe/Runner.cs b/src/GitVersionExe/Runners/InspectRunner.cs similarity index 59% rename from src/GitVersionExe/Runner.cs rename to src/GitVersionExe/Runners/InspectRunner.cs index d47830203c..c8a27a7ba9 100644 --- a/src/GitVersionExe/Runner.cs +++ b/src/GitVersionExe/Runners/InspectRunner.cs @@ -1,20 +1,10 @@ -using System; - -namespace GitVersion +namespace GitVersion.Runners { + using System; using System.Linq; using GitVersion.Helpers; using GitVersion.Options; - class InitRunner - { - public static void Run(InitOptions opts) - { - var fs = new FileSystem(); - ConfigurationProvider.Init(opts.Path, fs, new ConsoleAdapter()); - } - } - class InspectRunner { public static void Run(InspectOptions opts) @@ -48,21 +38,4 @@ public static void Run(InspectOptions opts) } } } - - class InjectBuildServerRunner - { - public static void Run(InjectBuildServerOptions opts) - { - var inputVariables = new InputVariables(); // TODO: how to map to input variables - var fs = new FileSystem(); - var variables = SpecifiedArgumentRunner.GetVariables(fs, inputVariables); - - foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) - { - buildServer.WriteIntegration(Console.WriteLine, variables); - } - } - } - - -} +} \ No newline at end of file