@@ -28,108 +28,28 @@ public static class Program
28
28
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Reliability" , "CA2000:Dispose objects before losing scope" , Justification = "Not required" ) ]
29
29
private static int Main ( string [ ] args )
30
30
{
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 ) ;
125
43
}
126
44
127
45
private static async Task < int > CreateReleaseAsync ( CreateSubOptions subOptions , IFileSystem fileSystem )
128
46
{
129
47
try
130
48
{
49
+ ConfigureLogging ( subOptions . LogFilePath ) ;
50
+
131
51
var github = subOptions . CreateGitHubClient ( ) ;
132
- var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
52
+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory ?? Environment . CurrentDirectory , fileSystem ) ;
133
53
134
54
if ( ! string . IsNullOrEmpty ( subOptions . Milestone ) )
135
55
{
@@ -154,6 +74,8 @@ private static async Task<int> AddAssetsAsync(AddAssetSubOptions subOptions)
154
74
{
155
75
try
156
76
{
77
+ ConfigureLogging ( subOptions . LogFilePath ) ;
78
+
157
79
var github = subOptions . CreateGitHubClient ( ) ;
158
80
159
81
await AddAssets ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName , subOptions . AssetPaths ) ;
@@ -172,6 +94,8 @@ private static async Task<int> CloseMilestoneAsync(CloseSubOptions subOptions)
172
94
{
173
95
try
174
96
{
97
+ ConfigureLogging ( subOptions . LogFilePath ) ;
98
+
175
99
var github = subOptions . CreateGitHubClient ( ) ;
176
100
177
101
await CloseMilestone ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . Milestone ) ;
@@ -190,6 +114,8 @@ private static async Task<int> PublishReleaseAsync(PublishSubOptions subOptions)
190
114
{
191
115
try
192
116
{
117
+ ConfigureLogging ( subOptions . LogFilePath ) ;
118
+
193
119
var github = subOptions . CreateGitHubClient ( ) ;
194
120
195
121
await PublishRelease ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName ) ;
@@ -208,8 +134,10 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
208
134
{
209
135
try
210
136
{
137
+ ConfigureLogging ( subOptions . LogFilePath ) ;
138
+
211
139
var github = subOptions . CreateGitHubClient ( ) ;
212
- var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory , fileSystem ) ;
140
+ var configuration = ConfigurationProvider . Provide ( subOptions . TargetDirectory ?? Environment . CurrentDirectory , fileSystem ) ;
213
141
214
142
var releasesMarkdown = await ExportReleases ( github , subOptions . RepositoryOwner , subOptions . RepositoryName , subOptions . TagName , configuration ) ;
215
143
@@ -228,6 +156,22 @@ private static async Task<int> ExportReleasesAsync(ExportSubOptions subOptions,
228
156
}
229
157
}
230
158
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
+
231
175
private static async Task CreateReleaseFromMilestone ( GitHubClient github , string owner , string repository , string milestone , string targetCommitish , IList < string > assets , bool prerelease , Config configuration )
232
176
{
233
177
var releaseNotesBuilder = new ReleaseNotesBuilder ( new DefaultGitHubClient ( github , owner , repository ) , owner , repository , milestone , configuration ) ;
0 commit comments