Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Fixed service collection not being created on non-vcs commands #292

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/GitReleaseManager.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static async Task<int> Main(string[] args)
.WithParsed<BaseSubOptions>(LogConfiguration.ConfigureLogging)
.WithParsed<BaseSubOptions>(CreateFiglet)
.WithParsed<BaseSubOptions>(LogOptions)
.WithParsed<BaseVcsOptions>(RegisterServices)
.WithParsed<BaseSubOptions>(RegisterServices)
.MapResult(
(CreateSubOptions opts) => ExecuteCommand(opts),
(DiscardSubOptions opts) => ExecuteCommand(opts),
Expand Down Expand Up @@ -75,20 +75,13 @@ private static async Task<int> Main(string[] args)
}
}

private static void RegisterServices(BaseVcsOptions options)
private static void RegisterServices(BaseSubOptions options)
{
var fileSystem = new FileSystem();
var logger = Log.ForContext<VcsService>();
var mapper = AutoMapperConfiguration.Configure();
var configuration = ConfigurationProvider.Provide(options.TargetDirectory ?? Environment.CurrentDirectory, fileSystem);

if (string.IsNullOrWhiteSpace(options.Token))
{
throw new Exception("The token option is not defined");
}

var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(options.Token) };

var serviceCollection = new ServiceCollection()
.AddSingleton(logger)
.AddSingleton(mapper)
Expand All @@ -104,13 +97,24 @@ private static void RegisterServices(BaseVcsOptions options)
.AddSingleton<ICommand<OpenSubOptions>, OpenCommand>()
.AddSingleton<ICommand<PublishSubOptions>, PublishCommand>()
.AddSingleton<ICommand<ShowConfigSubOptions>, ShowConfigCommand>()
.AddSingleton<IFileSystem, FileSystem>()
.AddSingleton<IFileSystem>(fileSystem)
.AddSingleton<IReleaseNotesExporter, ReleaseNotesExporter>()
.AddSingleton<IReleaseNotesBuilder, ReleaseNotesBuilder>()
.AddSingleton<IGitHubClient>(gitHubClient)
.AddSingleton<IVcsProvider, GitHubProvider>()
.AddSingleton<IVcsService, VcsService>();

if (options is BaseVcsOptions vcsOptions)
{
if (string.IsNullOrWhiteSpace(vcsOptions.Token))
{
throw new Exception("The token option is not defined");
}

var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) };
serviceCollection = serviceCollection
.AddSingleton<IGitHubClient>(gitHubClient);
}

_serviceProvider = serviceCollection.BuildServiceProvider();
}

Expand Down