Skip to content

Commit

Permalink
Fixed code analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Dec 9, 2023
1 parent 0590ec1 commit c6a564e
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/Credfeto.ChangeLog.Cmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,22 @@ private static async Task OutputUnreleasedContentAsync(Options options, Cancella

private static Task CreateNewReleaseAsync(Options options, in CancellationToken cancellationToken)
{
string releaseVersion = options.CreateRelease!;
string releaseVersion = GetCreateRelease(options);
string changeLog = FindChangeLog(options);
Console.WriteLine($"Using Changelog {changeLog}");
Console.WriteLine($"Release Version: {releaseVersion}");

return ChangeLogUpdater.CreateReleaseAsync(changeLogFileName: changeLog, version: releaseVersion, pending: options.Pending, cancellationToken: cancellationToken);
}

private static string GetCreateRelease(Options options)
{
return options.CreateRelease ?? throw new InvalidOptionsException(nameof(options.CreateRelease) + " is null");
}

private static async Task CheckInsertPositionAsync(Options options, CancellationToken cancellationToken)
{
string originBranchName = options.CheckInsert!;
string originBranchName = GetCheckInsert(options);
string changeLog = FindChangeLog(options);
Console.WriteLine($"Using Changelog {changeLog}");
Console.WriteLine($"Branch: {originBranchName}");
Expand All @@ -119,10 +124,15 @@ private static async Task CheckInsertPositionAsync(Options options, Cancellation
throw new ChangeLogInvalidFailedException("Changelog modified in released section");
}

private static string GetCheckInsert(Options options)
{
return options.CheckInsert ?? throw new InvalidOptionsException(nameof(options.CheckInsert) + " is null");
}

private static Task AddEntryToUnreleasedChangelogAsync(Options options, in CancellationToken cancellationToken)
{
string changeType = options.Add!;
string message = options.Message!;
string changeType = GetAdd(options);
string message = GetMessage(options);
string changeLog = FindChangeLog(options);
Console.WriteLine($"Using Changelog {changeLog}");
Console.WriteLine($"Change Type: {changeType}");
Expand All @@ -131,10 +141,15 @@ private static Task AddEntryToUnreleasedChangelogAsync(Options options, in Cance
return ChangeLogUpdater.AddEntryAsync(changeLogFileName: changeLog, type: changeType, message: message, cancellationToken: cancellationToken);
}

private static string GetAdd(Options options)
{
return options.Add ?? throw new InvalidOptionsException(nameof(options.Add) + " is null");
}

private static Task RemoveEntryFromUnreleasedChangelogAsync(Options options, in CancellationToken cancellationToken)
{
string changeType = options.Remove!;
string message = options.Message!;
string changeType = GetChangeType(options);
string message = GetMessage(options);
string changeLog = FindChangeLog(options);
Console.WriteLine($"Using Changelog {changeLog}");
Console.WriteLine($"Change Type: {changeType}");
Expand All @@ -143,10 +158,20 @@ private static Task RemoveEntryFromUnreleasedChangelogAsync(Options options, in
return ChangeLogUpdater.RemoveEntryAsync(changeLogFileName: changeLog, type: changeType, message: message, cancellationToken: cancellationToken);
}

private static string GetChangeType(Options options)
{
return options.Remove ?? throw new InvalidOptionsException(nameof(options.Remove) + " is null");
}

private static string GetMessage(Options options)
{
return options.Message ?? throw new InvalidOptionsException(nameof(options.Message) + " is null");
}

private static async Task ExtractChangeLogTextForVersionAsync(Options options, CancellationToken cancellationToken)
{
string outputFileName = options.Extract!;
string version = options.Version!;
string outputFileName = GetExtract(options);
string version = GetVersion(options);
string changeLog = FindChangeLog(options);
Console.WriteLine($"Using Changelog {changeLog}");
Console.WriteLine($"Version {version}");
Expand All @@ -156,6 +181,16 @@ private static async Task ExtractChangeLogTextForVersionAsync(Options options, C
await File.WriteAllTextAsync(path: outputFileName, contents: text, encoding: Encoding.UTF8, cancellationToken: cancellationToken);
}

private static string GetVersion(Options options)
{
return options.Version ?? throw new InvalidOptionsException(nameof(options.Version) + " is null");
}

private static string GetExtract(Options options)
{
return options.Extract ?? throw new InvalidOptionsException(nameof(options.Extract) + " is null");
}

private static void NotParsed(IEnumerable<Error> errors)
{
Console.WriteLine("Errors:");
Expand Down

0 comments on commit c6a564e

Please sign in to comment.