@@ -110,6 +110,11 @@ private static void RegisterServices(BaseSubOptions options)
110110 RegisterVcsProvider ( vcsOptions , serviceCollection ) ;
111111 }
112112
113+ if ( options is CreateSubOptions createOptions && ! string . IsNullOrEmpty ( createOptions . OutputPath ) )
114+ {
115+ configuration . Create . AllowUpdateToPublishedRelease = false ;
116+ }
117+
113118 serviceCollection = serviceCollection
114119 . AddTransient ( ( services ) => new TemplateFactory ( services . GetRequiredService < IFileSystem > ( ) , services . GetRequiredService < Config > ( ) , TemplateKind . Create ) ) ;
115120
@@ -197,21 +202,53 @@ private static Task<int> ExecuteCommand<TOptions>(TOptions options)
197202 private static void LogOptions ( BaseSubOptions options )
198203 => Log . Debug ( "{@Options}" , options ) ;
199204
205+ private static void RegisterKeyedVcsProvider < TVcsImplementation > ( object provider , IServiceCollection serviceCollection )
206+ where TVcsImplementation : class , IVcsProvider
207+ {
208+ static IVcsProvider ResolveService ( IServiceProvider service , object key ) => service . GetRequiredKeyedService < IVcsProvider > ( key ) ;
209+
210+ provider ??= "null" ;
211+
212+ Log . Debug ( "Registering {Type} with Service Key {Key}" , typeof ( IVcsProvider ) , provider ) ;
213+
214+ if ( typeof ( TVcsImplementation ) != typeof ( NullReleasesProvider ) )
215+ {
216+ serviceCollection . AddKeyedSingleton < IVcsProvider , TVcsImplementation > ( provider ) ;
217+ }
218+
219+ serviceCollection
220+ . AddKeyedTransient < IAssetsProvider > ( provider , ResolveService )
221+ . AddKeyedTransient < ICommitsProvider > ( provider , ResolveService )
222+ . AddKeyedTransient < IIssuesProvider > ( provider , ResolveService )
223+ . AddKeyedTransient < IMilestonesProvider > ( provider , ResolveService )
224+ . AddKeyedTransient < IReleasesProvider > ( provider , ResolveService ) ;
225+ }
226+
200227 private static void RegisterVcsProvider ( BaseVcsOptions vcsOptions , IServiceCollection serviceCollection )
201228 {
202229 Log . Information ( "Using {Provider} as VCS Provider" , vcsOptions . Provider ) ;
203- if ( vcsOptions . Provider == VcsProvider . GitLab )
230+
231+ serviceCollection . AddKeyedSingleton < IVcsProvider > ( "null" , ( service , _ ) => new NullReleasesProvider ( vcsOptions . Provider . ToString ( ) , service . GetRequiredService < ILogger > ( ) ) ) ;
232+ RegisterKeyedVcsProvider < NullReleasesProvider > ( null , serviceCollection ) ;
233+ RegisterKeyedVcsProvider < GitHubProvider > ( VcsProvider . GitHub , serviceCollection ) ;
234+
235+ serviceCollection
236+ . AddSingleton < IGitLabClient > ( ( _ ) => new GitLabClient ( "https://gitlab.com" , vcsOptions . Token ) ) ;
237+
238+ serviceCollection
239+ . AddSingleton < IGitHubClient > ( ( _ ) => new GitHubClient ( new ProductHeaderValue ( "GitReleaseManager" ) ) { Credentials = new Credentials ( vcsOptions . Token ) } ) ;
240+
241+ serviceCollection . AddTransient ( ( service ) => service . GetKeyedService < IVcsProvider > ( vcsOptions . Provider ) ?? service . GetRequiredKeyedService < IVcsProvider > ( "null" ) ) ;
242+
243+ if ( vcsOptions is CreateSubOptions createOptions && ! string . IsNullOrEmpty ( createOptions . OutputPath ) )
204244 {
205- serviceCollection
206- . AddSingleton < IGitLabClient > ( ( _ ) => new GitLabClient ( "https://gitlab.com" , vcsOptions . Token ) )
207- . AddSingleton < IVcsProvider , GitLabProvider > ( ) ;
245+ serviceCollection . AddSingleton < IReleasesProvider > ( ( service ) => new LocalProvider (
246+ service . GetRequiredService < IFileSystem > ( ) ,
247+ createOptions . OutputPath ) ) ;
208248 }
209249 else
210250 {
211- // default to Github
212- serviceCollection
213- . AddSingleton < IGitHubClient > ( ( _ ) => new GitHubClient ( new ProductHeaderValue ( "GitReleaseManager" ) ) { Credentials = new Credentials ( vcsOptions . Token ) } )
214- . AddSingleton < IVcsProvider , GitHubProvider > ( ) ;
251+ serviceCollection . AddTransient ( ( service ) => service . GetKeyedService < IReleasesProvider > ( vcsOptions . Provider ) ?? service . GetRequiredKeyedService < IReleasesProvider > ( "null" ) ) ;
215252 }
216253 }
217254 }
0 commit comments