Skip to content

Commit 5402114

Browse files
committed
(GH-59) Updated to latest CommandLineParser
1 parent a87b843 commit 5402114

11 files changed

+63
-119
lines changed

Source/GitReleaseManager.Cli/GitReleaseManager.Cli.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<RestorePackages>true</RestorePackages>
1818
<BuildToolsFxCopVersion>1.0.1</BuildToolsFxCopVersion>
1919
<TargetFrameworkProfile />
20+
<IsWebBootstrapper>false</IsWebBootstrapper>
2021
<PublishUrl>publish\</PublishUrl>
2122
<Install>true</Install>
2223
<InstallFrom>Disk</InstallFrom>
@@ -29,7 +30,6 @@
2930
<MapFileExtensions>true</MapFileExtensions>
3031
<ApplicationRevision>0</ApplicationRevision>
3132
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
32-
<IsWebBootstrapper>false</IsWebBootstrapper>
3333
<UseApplicationTrust>false</UseApplicationTrust>
3434
<BootstrapperEnabled>true</BootstrapperEnabled>
3535
</PropertyGroup>
@@ -59,8 +59,9 @@
5959
<CodeAnalysisTreatWarningsAsErrors>True</CodeAnalysisTreatWarningsAsErrors>
6060
</PropertyGroup>
6161
<ItemGroup>
62-
<Reference Include="CommandLine">
63-
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
62+
<Reference Include="CommandLine, Version=2.0.275.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
63+
<HintPath>..\packages\CommandLineParser.2.0.275-beta\lib\net45\CommandLine.dll</HintPath>
64+
<Private>True</Private>
6465
</Reference>
6566
<Reference Include="Octokit, Version=0.17.0.0, Culture=neutral, processorArchitecture=MSIL">
6667
<HintPath>..\packages\Octokit.0.17.0\lib\net45\Octokit.dll</HintPath>

Source/GitReleaseManager.Cli/Options/AddAssetSubOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace GitReleaseManager.Cli.Options
88
{
99
using System.Collections.Generic;
10-
1110
using CommandLine;
1211

12+
[Verb("addasset", HelpText = "Adds an asset to an existing release.")]
1313
public class AddAssetSubOptions : BaseGitHubSubOptions
1414
{
15-
[OptionList('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = true)]
15+
[Option('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = true)]
1616
public IList<string> AssetPaths { get; set; }
1717

1818
[Option('t', "tagName", HelpText = "The name of the release (Typically this is the generated SemVer Version Number).", Required = true)]

Source/GitReleaseManager.Cli/Options/CloseSubOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace GitReleaseManager.Cli.Options
88
{
99
using CommandLine;
1010

11+
[Verb("close", HelpText = "Closes the milestone.")]
1112
public class CloseSubOptions : BaseGitHubSubOptions
1213
{
1314
[Option('m', "milestone", HelpText = "The milestone to use.", Required = true)]

Source/GitReleaseManager.Cli/Options/CreateSubOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace GitReleaseManager.Cli.Options
88
{
99
using System.Collections.Generic;
10-
1110
using CommandLine;
1211

12+
[Verb("create", HelpText = "Creates a draft release notes from a milestone.")]
1313
public class CreateSubOptions : BaseGitHubSubOptions
1414
{
15-
[OptionList('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = false)]
15+
[Option('a', "assets", Separator = ',', HelpText = "Paths to the files to include in the release.", Required = false)]
1616
public IList<string> AssetPaths { get; set; }
1717

1818
[Option('c', "targetcommitish", HelpText = "The commit to tag. Can be a branch or SHA. Defaults to repository's default branch.", Required = false)]

Source/GitReleaseManager.Cli/Options/ExportSubOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace GitReleaseManager.Cli.Options
88
{
99
using CommandLine;
1010

11+
[Verb("export", HelpText = "Exports all the Release Notes in markdown format.")]
1112
public class ExportSubOptions : BaseGitHubSubOptions
1213
{
1314
[Option('f', "fileOutputPath", HelpText = "Path to the file export releases.", Required = true)]

Source/GitReleaseManager.Cli/Options/InitSubOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace GitReleaseManager.Cli.Options
88
{
9+
using CommandLine;
10+
11+
[Verb("init", HelpText = "Creates a sample Yaml Configuration file in root directory")]
912
public class InitSubOptions : BaseSubOptions
1013
{
1114
}

Source/GitReleaseManager.Cli/Options/MainOptions.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,26 @@
66

77
namespace GitReleaseManager.Cli.Options
88
{
9-
using CommandLine;
10-
using CommandLine.Text;
11-
129
public class MainOptions
1310
{
14-
[VerbOption("create", HelpText = "Creates a draft release notes from a milestone.")]
1511
public CreateSubOptions CreateVerb { get; set; }
1612

17-
[VerbOption("addasset", HelpText = "Adds an asset to an existing release.")]
1813
public AddAssetSubOptions AddAssetVerb { get; set; }
1914

20-
[VerbOption("close", HelpText = "Closes the milestone.")]
2115
public CloseSubOptions CloseVerb { get; set; }
2216

23-
[VerbOption("publish", HelpText = "Publishes the release notes and closes the milestone.")]
2417
public PublishSubOptions PublishVerb { get; set; }
2518

26-
[VerbOption("export", HelpText = "Exports all the Release Notes in markdown format.")]
2719
public ExportSubOptions ExportVerb { get; set; }
2820

29-
[VerbOption("init", HelpText = "Creates a sample Yaml Configuration file in root directory")]
3021
public InitSubOptions InitVerb { get; set; }
3122

32-
[VerbOption("showconfig", HelpText = "Shows the current configuration")]
3323
public ShowConfigSubOptions ShowConfigVerb { get; set; }
3424

35-
[HelpVerbOption]
36-
public string DoHelpForVerb(string verbName)
37-
{
38-
return HelpText.AutoBuild(this, verbName);
39-
}
25+
////[HelpVerbOption]
26+
////public string DoHelpForVerb(string verbName)
27+
////{
28+
//// return HelpText.AutoBuild(this, verbName);
29+
////}
4030
}
4131
}

Source/GitReleaseManager.Cli/Options/PublishSubOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace GitReleaseManager.Cli.Options
88
{
99
using CommandLine;
1010

11+
[Verb("publish", HelpText = "Publishes the release notes and closes the milestone.")]
1112
public class PublishSubOptions : BaseGitHubSubOptions
1213
{
1314
[Option('t', "tagName", HelpText = "The name of the release (Typically this is the generated SemVer Version Number).", Required = true)]

Source/GitReleaseManager.Cli/Options/ShowConfigSubOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace GitReleaseManager.Cli.Options
88
{
9+
using CommandLine;
10+
11+
[Verb("showconfig", HelpText = "Shows the current configuration")]
912
public class ShowConfigSubOptions : BaseSubOptions
1013
{
1114
}

Source/GitReleaseManager.Cli/Program.cs

Lines changed: 40 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -28,108 +28,28 @@ public static class Program
2828
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Not required")]
2929
private static int Main(string[] args)
3030
{
31-
var options = new MainOptions();
32-
33-
var result = 1;
34-
35-
if (!Parser.Default.ParseArgumentsStrict(
36-
args,
37-
options,
38-
(verb, subOptions) =>
39-
{
40-
result = 1;
41-
42-
var baseSubOptions = subOptions as BaseSubOptions;
43-
if (baseSubOptions != null)
44-
{
45-
if (string.IsNullOrEmpty(baseSubOptions.TargetDirectory))
46-
{
47-
baseSubOptions.TargetDirectory = Environment.CurrentDirectory;
48-
}
49-
50-
ConfigureLogging(baseSubOptions.LogFilePath);
51-
}
52-
53-
var fileSystem = new FileSystem();
54-
55-
if (verb == "create")
56-
{
57-
var createSubOptions = baseSubOptions as CreateSubOptions;
58-
if (createSubOptions != null)
59-
{
60-
result = CreateReleaseAsync(createSubOptions, fileSystem).Result;
61-
}
62-
}
63-
64-
if (verb == "addasset")
65-
{
66-
var addAssetSubOptions = baseSubOptions as AddAssetSubOptions;
67-
if (addAssetSubOptions != null)
68-
{
69-
result = AddAssetsAsync(addAssetSubOptions).Result;
70-
}
71-
}
72-
73-
if (verb == "close")
74-
{
75-
var closeSubOptions = baseSubOptions as CloseSubOptions;
76-
if (closeSubOptions != null)
77-
{
78-
result = CloseMilestoneAsync(closeSubOptions).Result;
79-
}
80-
}
81-
82-
if (verb == "publish")
83-
{
84-
var publishSubOptions = baseSubOptions as PublishSubOptions;
85-
if (publishSubOptions != null)
86-
{
87-
result = PublishReleaseAsync(publishSubOptions).Result;
88-
}
89-
}
90-
91-
if (verb == "export")
92-
{
93-
var exportSubOptions = baseSubOptions as ExportSubOptions;
94-
if (exportSubOptions != null)
95-
{
96-
result = ExportReleasesAsync(exportSubOptions, fileSystem).Result;
97-
}
98-
}
99-
100-
if (verb == "init")
101-
{
102-
var initSubOptions = baseSubOptions as InitSubOptions;
103-
if (initSubOptions != null)
104-
{
105-
ConfigurationProvider.WriteSample(initSubOptions.TargetDirectory, fileSystem);
106-
result = 0;
107-
}
108-
}
109-
110-
if (verb == "showconfig")
111-
{
112-
var showConfigSubOptions = baseSubOptions as ShowConfigSubOptions;
113-
if (showConfigSubOptions != null)
114-
{
115-
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(showConfigSubOptions.TargetDirectory, fileSystem));
116-
result = 0;
117-
}
118-
}
119-
}))
120-
{
121-
return 1;
122-
}
123-
124-
return result;
31+
var fileSystem = new FileSystem();
32+
33+
return Parser.Default.ParseArguments<CreateSubOptions, AddAssetSubOptions, CloseSubOptions, PublishSubOptions, ExportSubOptions, InitSubOptions, ShowConfigSubOptions>(args)
34+
.MapResult(
35+
(CreateSubOptions opts) => CreateReleaseAsync(opts, fileSystem).Result,
36+
(AddAssetSubOptions opts) => AddAssetsAsync(opts).Result,
37+
(CloseSubOptions opts) => CloseMilestoneAsync(opts).Result,
38+
(PublishSubOptions opts) => PublishReleaseAsync(opts).Result,
39+
(ExportSubOptions opts) => ExportReleasesAsync(opts, fileSystem).Result,
40+
(InitSubOptions opts) => CreateSampleConfigFile(opts, fileSystem).Result,
41+
(ShowConfigSubOptions opts) => ShowConfig(opts, fileSystem).Result,
42+
errs => 1);
12543
}
12644

12745
private static async Task<int> CreateReleaseAsync(CreateSubOptions subOptions, IFileSystem fileSystem)
12846
{
12947
try
13048
{
49+
ConfigureLogging(subOptions.LogFilePath);
50+
13151
var github = subOptions.CreateGitHubClient();
132-
var configuration = ConfigurationProvider.Provide(subOptions.TargetDirectory, fileSystem);
52+
var configuration = ConfigurationProvider.Provide(subOptions.TargetDirectory ?? Environment.CurrentDirectory, fileSystem);
13353

13454
if (!string.IsNullOrEmpty(subOptions.Milestone))
13555
{
@@ -154,6 +74,8 @@ private static async Task<int> AddAssetsAsync(AddAssetSubOptions subOptions)
15474
{
15575
try
15676
{
77+
ConfigureLogging(subOptions.LogFilePath);
78+
15779
var github = subOptions.CreateGitHubClient();
15880

15981
await AddAssets(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.TagName, subOptions.AssetPaths);
@@ -172,6 +94,8 @@ private static async Task<int> CloseMilestoneAsync(CloseSubOptions subOptions)
17294
{
17395
try
17496
{
97+
ConfigureLogging(subOptions.LogFilePath);
98+
17599
var github = subOptions.CreateGitHubClient();
176100

177101
await CloseMilestone(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.Milestone);
@@ -190,6 +114,8 @@ private static async Task<int> PublishReleaseAsync(PublishSubOptions subOptions)
190114
{
191115
try
192116
{
117+
ConfigureLogging(subOptions.LogFilePath);
118+
193119
var github = subOptions.CreateGitHubClient();
194120

195121
await PublishRelease(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.TagName);
@@ -208,8 +134,10 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
208134
{
209135
try
210136
{
137+
ConfigureLogging(subOptions.LogFilePath);
138+
211139
var github = subOptions.CreateGitHubClient();
212-
var configuration = ConfigurationProvider.Provide(subOptions.TargetDirectory, fileSystem);
140+
var configuration = ConfigurationProvider.Provide(subOptions.TargetDirectory ?? Environment.CurrentDirectory, fileSystem);
213141

214142
var releasesMarkdown = await ExportReleases(github, subOptions.RepositoryOwner, subOptions.RepositoryName, subOptions.TagName, configuration);
215143

@@ -228,6 +156,22 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
228156
}
229157
}
230158

159+
private static async Task<int> CreateSampleConfigFile(InitSubOptions subOptions, IFileSystem fileSystem)
160+
{
161+
ConfigureLogging(subOptions.LogFilePath);
162+
163+
ConfigurationProvider.WriteSample(subOptions.TargetDirectory ?? Environment.CurrentDirectory, fileSystem);
164+
return 0;
165+
}
166+
167+
private static async Task<int> ShowConfig(ShowConfigSubOptions subOptions, IFileSystem fileSystem)
168+
{
169+
ConfigureLogging(subOptions.LogFilePath);
170+
171+
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(subOptions.TargetDirectory ?? Environment.CurrentDirectory, fileSystem));
172+
return 0;
173+
}
174+
231175
private static async Task CreateReleaseFromMilestone(GitHubClient github, string owner, string repository, string milestone, string targetCommitish, IList<string> assets, bool prerelease, Config configuration)
232176
{
233177
var releaseNotesBuilder = new ReleaseNotesBuilder(new DefaultGitHubClient(github, owner, repository), owner, repository, milestone, configuration);

0 commit comments

Comments
 (0)