Skip to content

Commit

Permalink
Add output type validation, for GitTools#428
Browse files Browse the repository at this point in the history
With validation
  • Loading branch information
serra committed Aug 15, 2015
1 parent fc45fda commit 42a8256
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public static OptionSet GetOptionSet(Arguments arguments)
"p|password=", "Password in case authentication is required",
v => arguments.Authentication.Password = v
},
{
"output=", "Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'",
v => arguments.SetOutPutType(v)
},
};
}

Expand Down Expand Up @@ -90,7 +94,6 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
arguments.TargetPath = additionalArguments[0];
}


return arguments;

/*
Expand Down Expand Up @@ -262,17 +265,17 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
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("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))
{
Expand Down
13 changes: 12 additions & 1 deletion src/GitVersionExe/Arguments.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace GitVersion
{
using System;

public class Arguments
{
public Arguments()
Expand All @@ -24,7 +26,15 @@ public Arguments()
public string ShowVariable;

public OutputType Output;


public void SetOutPutType(string value)
{
if (!Enum.TryParse(value, true, out Output))
{
throw new WarningException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value));
}
}

public string Proj;
public string ProjArgs;
public string Exec;
Expand All @@ -35,5 +45,6 @@ public Arguments()

public bool ShowConfig;
public bool NoFetch { get; set; }

}
}

0 comments on commit 42a8256

Please sign in to comment.