Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into release/3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeGinnivan committed Jun 25, 2015
2 parents ed9878c + a1991f0 commit bec5eb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GitVersionCore/OutputVariables/VersionVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class VersionVariables : IEnumerable<KeyValuePair<string, string>>
public string NuGetVersionV2 { get { return LegacySemVerPadded.ToLower(); } }
public string NuGetVersion { get { return NuGetVersionV2; } }

public IEnumerable<string> AvailableVariables
public static IEnumerable<string> AvailableVariables
{
get { return typeof(VersionVariables).GetProperties().Select(p => p.Name).OrderBy(a => a); }
}
Expand Down
27 changes: 16 additions & 11 deletions GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ namespace GitVersion
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;


public class ArgumentParser
{
static ArgumentParser()
{
var fields = typeof(VariableProvider).GetFields(BindingFlags.Public | BindingFlags.Static);
VersionParts = fields.Select(x => x.Name.ToLower()).ToArray();
}

public static Arguments ParseArguments(string commandLineArguments)
{
return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList());
Expand Down Expand Up @@ -185,9 +178,23 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
throw new WarningException("assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead");
}

if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
if (IsSwitch("v", name) || IsSwitch("showvariable", name))
{
arguments.ShowVariable = value.ToLower();
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;
}

Expand Down Expand Up @@ -297,7 +304,5 @@ static bool IsHelp(string singleArgument)
IsSwitch("help", singleArgument) ||
IsSwitch("?", singleArgument);
}

static string[] VersionParts;
}
}
13 changes: 13 additions & 0 deletions GitVersionExe/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ static int VerifyArgumentsAndRun()
{
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));
Expand Down

0 comments on commit bec5eb5

Please sign in to comment.