-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (51 loc) · 1.84 KB
/
Program.cs
File metadata and controls
58 lines (51 loc) · 1.84 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
51
52
53
54
55
56
57
58
// See https://aka.ms/new-console-template for more information
using System.Reflection;
internal class Program
{
static void Main(string[] args)
{
var test = int.TryParse(string.Join(' ', args), out var _);
if (!test && !string.IsNullOrWhiteSpace(string.Join(' ', args)) && string.Join(' ', args).ToLower() == "help")
{
var versionString = Assembly.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion
.ToString();
Console.WriteLine($"CLI Guid Generator v{versionString}");
Console.WriteLine("-------------");
Console.WriteLine("\nUsage:");
Console.WriteLine(
" cli-generate-guid <number of guids> - Generates a specified number of GUIDs. default is 1.");
return;
}
GenerateGuids(string.Join(' ', args));
}
private static void GenerateGuids(string args)
{
// Default to 1 if empty string
if (string.IsNullOrWhiteSpace(args))
{
args = "1";
}
// Check if the input string is a valid number
if (int.TryParse(args, out int count))
{
// Validate the count is positive
if (count <= 0)
{
Console.WriteLine("Error: Please enter a positive number of GUIDs to generate.");
return;
}
// Generate the specified number of GUIDs
for (int i = 0; i < count; i++)
{
Console.WriteLine(Guid.NewGuid().ToString());
}
}
else
{
// If not a valid number, show error message
Console.WriteLine("Error: You must provide a valid number of GUIDs to generate.");
}
}
}