@@ -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