Skip to content

Commit

Permalink
Add descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanteDeRuwe committed Nov 19, 2024
1 parent 9843d55 commit 4f7213b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
12 changes: 8 additions & 4 deletions src/Dotty.CLI/Commands/ConvertCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ public void Register(ICoconaAppBuilder app)
{
app.AddSubCommand("convert", group =>
{
group.AddCommand("units", ConvertUnits);
group.AddCommand("tobase64", ([Argument] string input) => Panel(Convert.ToBase64String(Encoding.UTF8.GetBytes(input))));
group.AddCommand("frombase64", ([Argument] string input) => Panel(Encoding.UTF8.GetString(Convert.FromBase64String(input))));
});
group.AddCommand("units", ConvertUnits)
.WithDescription("Converts a value from one unit of measurement to another");
group.AddCommand("tobase64", ([Argument] string input) => Panel(Convert.ToBase64String(Encoding.UTF8.GetBytes(input))))
.WithDescription("Converts a string to a base64 encoded string");
group.AddCommand("frombase64", ([Argument] string input) => Panel(Encoding.UTF8.GetString(Convert.FromBase64String(input))))
.WithDescription("Converts a base64 encoded string to a regular string");
})
.WithDescription("Contains commands to convert values");
}


Expand Down
34 changes: 19 additions & 15 deletions src/Dotty.CLI/Commands/GenerateCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ public class GenerateCommands : ICommandDefinition
public void Register(ICoconaAppBuilder app)
{
app.AddSubCommand("generate", group =>
{
group.AddSubCommand("random", subgroup =>
{
subgroup.AddCommand("guid", () => Panel(Guid.NewGuid().ToString()));

subgroup.AddCommand("number", ([Option('m')] int min = 0, [Option('M')] int max = 100)
=> Panel(Random.Shared.Next(min, max).ToString()));
group.AddSubCommand("random", subgroup =>
{
subgroup.AddCommand("guid", () => Panel(Guid.NewGuid().ToString()))
.WithDescription("Generates a random GUID");

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}}'`
""");
});
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");

group.AddCommand("timestamp", (string format = "o") => Panel(DateTimeOffset.UtcNow.ToString(format)));
});
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}}'`
""");
});

group.AddCommand("timestamp", (string format = "o") => Panel(DateTimeOffset.UtcNow.ToString(format)))
.WithDescription("Generates a timestamp for the current datetime with an optional format string");
})
.WithDescription("Contains commands to generate certain data");
}
}
28 changes: 17 additions & 11 deletions src/Dotty.CLI/Commands/IntroduceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ public void Register(ICoconaAppBuilder app)
{
app.AddSubCommand("introduce", group =>
{
group.AddCommand("talk", () => Panel("Welcome to this talk on crafting modern CLI tools using .NET"));
group.AddCommand("speaker", IntroduceSpeaker);
group.AddCommand("talk", () => Panel("Welcome to this talk on crafting modern CLI tools using .NET"))
.WithDescription("Introduces the talk");

group.AddCommand("speaker", IntroduceSpeaker)
.WithDescription("Introduces the speaker");

group.AddCommand("yourself", () =>
{
Panel("""
Hi, I'm Dotty, a CLI tool written in C# with dotnet.
I'm an assistant here to help you with various tasks!
PS: My name is a play on words: Dotnet + Clippy. Remember Clippy?
""");
});
});
{
Panel("""
Hi, I'm Dotty, a CLI tool written in C# with dotnet.
I'm an assistant here to help you with various tasks!
PS: My name is a play on words: Dotnet + Clippy. Remember Clippy?
""");
})
.WithDescription("Introduces Dotty");
})
.WithDescription("Contains commands to introduce various elements");
}

private static void IntroduceSpeaker([Option('n')] string? name = null)
Expand Down
3 changes: 2 additions & 1 deletion src/Dotty.CLI/Commands/PresentCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void Register(ICoconaAppBuilder app)
UseShellExecute = true
});
});
});
})
.WithDescription("Opens the presentation slides for the talk");
}
}
3 changes: 2 additions & 1 deletion src/Dotty.CLI/Commands/SimpleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class SimpleCommands : ICommandDefinition
{
public void Register(ICoconaAppBuilder app)
{
app.AddCommand("greet", ([Argument] string subject) => Panel($"Hello, {subject}!"));
app.AddCommand("greet", ([Argument] string subject) => Panel($"Hello, {subject}!"))
.WithDescription("Greets any subject");

app.AddCommand(([FromService] ICoconaApplicationMetadataProvider metadataProvider, [FromService] ICoconaHelpMessageBuilder helpProvider) =>
{
Expand Down
3 changes: 2 additions & 1 deletion src/Dotty.CLI/Commands/WeatherCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class WeatherCommands : ICommandDefinition
{
public void Register(ICoconaAppBuilder app)
{
app.AddCommand("weather", ExecuteWeatherCommand);
app.AddCommand("weather", ExecuteWeatherCommand)
.WithDescription("Gets the weather for a specific city");
}

private static async Task ExecuteWeatherCommand([FromService] IWeatherService weatherService, [Argument] string city)
Expand Down

0 comments on commit 4f7213b

Please sign in to comment.