-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuidGenCommand.cs
More file actions
50 lines (43 loc) · 1.49 KB
/
GuidGenCommand.cs
File metadata and controls
50 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace Neolution.DotNet.Console.Demo.Commands.GuidGen
{
using System;
using System.Globalization;
using Microsoft.Extensions.Logging;
using Neolution.DotNet.Console.Abstractions;
/// <summary>
/// Prints a randomly generated GUID in the console window
/// </summary>
/// <seealso cref="IDotNetConsoleCommand{TOptions}" />
public class GuidGenCommand : IDotNetConsoleCommand<GuidGenOptions>
{
/// <summary>
/// The logger
/// </summary>
private readonly ILogger<GuidGenCommand> logger;
/// <summary>
/// Initializes a new instance of the <see cref="GuidGenCommand"/> class.
/// </summary>
/// <param name="logger">The logger.</param>
public GuidGenCommand(ILogger<GuidGenCommand> logger)
{
this.logger = logger;
}
/// <inheritdoc />
public Task RunAsync(GuidGenOptions options, CancellationToken cancellationToken)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
var format = options.Format ?? "B";
var result = Guid.NewGuid().ToString(format, CultureInfo.InvariantCulture);
if (options.Upper)
{
result = result.ToUpperInvariant();
}
Console.WriteLine(result);
this.logger.LogTrace("Wrote result to console");
return Task.CompletedTask;
}
}
}