-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOptions.cs
More file actions
63 lines (54 loc) · 1.95 KB
/
Copy pathOptions.cs
File metadata and controls
63 lines (54 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace dotnet.gitversion
{
internal class Options
{
private static readonly IDictionary<string, string> _commandMapping =
new Dictionary<string, string> {
{ "-j", "projectjson" },
{ "-c", "csproj" },
{ "-h", "help" },
{ "-?", "help" },
};
public string ProjectJson { get; set; }
public string CsProj { get; set; }
public bool Help { get; set; }
public static string GetHelpMessage()
{
var builder = new StringBuilder("USAGE: dotnet gitversion <options>");
builder.AppendLine(" If no options are specified, then it will look for the project.json or *.csproj in current directory.");
builder.AppendLine();
builder.AppendLine("OPTIONS:");
foreach (var kvp in _commandMapping)
{
if (string.Equals(kvp.Value, "help", StringComparison.OrdinalIgnoreCase))
{
builder.AppendLine($"{kvp.Key}|--{kvp.Value}");
}
else
{
builder.AppendLine($"{kvp.Key}|--{kvp.Value} PathToFile");
}
}
return builder.ToString();
}
public bool NoFilesSpecified
{
get { return string.IsNullOrEmpty(CsProj) && string.IsNullOrEmpty(ProjectJson); }
}
public static Options Parse(string[] args)
{
var builder = new ConfigurationBuilder()
.AddCommandLine(args, _commandMapping);
var configure = new ConfigureFromConfigurationOptions<Options>(builder.Build());
var options = new Options();
configure.Action(options);
return options;
}
}
}