From 2a0c8dace12cbb8c04e93f881b6cd26a0603a815 Mon Sep 17 00:00:00 2001 From: Dante De Ruwe Date: Tue, 19 Nov 2024 20:47:07 +0100 Subject: [PATCH] Fix names on generate random number command --- src/Dotty.CLI/Commands/GenerateCommands.cs | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Dotty.CLI/Commands/GenerateCommands.cs b/src/Dotty.CLI/Commands/GenerateCommands.cs index 3c11187..1bc0435 100644 --- a/src/Dotty.CLI/Commands/GenerateCommands.cs +++ b/src/Dotty.CLI/Commands/GenerateCommands.cs @@ -9,22 +9,32 @@ public void Register(ICoconaAppBuilder app) app.AddSubCommand("generate", group => { group.AddSubCommand("random", subgroup => - { - subgroup.AddCommand("guid", () => Panel(Guid.NewGuid().ToString())) - .WithDescription("Generates a random GUID"); + { + subgroup.AddCommand("guid", () => Panel(Guid.NewGuid().ToString())) + .WithDescription("Generates a random GUID"); - subgroup.AddCommand("number", ([Option('m')] int min = 0, [Option('M')] int max = 100) - => Panel(Random.Shared.Next(min, max).ToString())) - .WithDescription("Generates a random number within a range"); + subgroup.AddCommand("number", ([Option('f')] int from = 0, [Option('t')] int to = 100) => + { + if (from >= to) + { + Console.WriteLine("Error: The 'from' value cannot be greater than the 'to' value"); + return 1; + } - subgroup - .AddCommand("fromtemplate", ([Argument] string template) => Panel(new Faker().Parse(template))) - .WithDescription(""" - Can generate random data from a template using the Bogus library. - For example, `generate random fromtemplate '{{name.firstName(Male)}} {{name.lastName}}'` - """); - }) - .WithDescription("Contains commands to generate certain random data"); + var number = Random.Shared.Next(from, to); + Panel($"Generated number: {number}"); + return 0; + }) + .WithDescription("Generates a random number within a range"); + + subgroup + .AddCommand("fromtemplate", ([Argument] string template) => Panel(new Faker().Parse(template))) + .WithDescription(""" + Can generate random data from a template using the Bogus library. + For example, `generate random fromtemplate '{{name.firstName(Male)}} {{name.lastName}}'` + """); + }) + .WithDescription("Contains commands to generate certain random data"); group.AddCommand("timestamp", (string format = "o") => Panel(DateTimeOffset.UtcNow.ToString(format))) .WithDescription("Generates a timestamp for the current datetime with an optional format string");