Skip to content

Commit cb0e60b

Browse files
committed
Add listing component parameters
1 parent f534e3b commit cb0e60b

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

src/TALXIS.CLI.Component/ComponentCliCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace TALXIS.CLI.Component;
66
Children = new[] {
77
typeof(AppComponentCommand),
88
typeof(ListTemplatesCliCommand),
9+
typeof(ListTemplateParametersCliCommand),
910
}
1011
)]
1112
public class ComponentCliCommand

src/TALXIS.CLI.Component/ComponentScaffolder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public async Task<List<ITemplateInfo>> ListTemplatesAsync(string? version = null
5252
return templates.FirstOrDefault(t => t.ShortNameList.Contains(shortName, StringComparer.OrdinalIgnoreCase));
5353
}
5454

55-
public async Task<IDictionary<string, ITemplateParameter>> ListParametersForTemplateAsync(string shortName, string? version = null)
55+
public async Task<IReadOnlyList<ITemplateParameter>> ListParametersForTemplateAsync(string shortName, string? version = null)
5656
{
5757
var template = await GetTemplateByShortNameAsync(shortName, version);
5858
if (template == null) throw new InvalidOperationException($"Template '{shortName}' not found.");
59-
// Use ParameterDefinitions instead of obsolete Parameters
60-
return template.ParameterDefinitions.ToDictionary(p => p.Name, p => p);
59+
// Use ParameterDefinitions property (non-obsolete in v9+)
60+
return template.ParameterDefinitions;
6161
}
6262

6363
public async Task ScaffoldAsync(string shortName, string outputPath, IDictionary<string, string> parameters, string? version = null, CancellationToken cancellationToken = default)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using DotMake.CommandLine;
2+
using System;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace TALXIS.CLI.Component;
7+
8+
/// <summary>
9+
/// CLI command to list parameters required for a specific component template.
10+
/// </summary>
11+
[CliCommand(
12+
Description = "Lists parameters for a specific component template."
13+
)]
14+
public class ListTemplateParametersCliCommand
15+
{
16+
[CliArgument(Description = "Short name of the template.")]
17+
public string ShortName { get; set; } = string.Empty;
18+
19+
public async Task<int> RunAsync()
20+
{
21+
try
22+
{
23+
using var scaffolder = new ComponentScaffolder();
24+
var parameters = await scaffolder.ListParametersForTemplateAsync(ShortName);
25+
if (parameters == null || parameters.Count == 0)
26+
{
27+
Console.WriteLine($"No parameters found for template '{ShortName}'.");
28+
return 0;
29+
}
30+
Console.WriteLine($"Parameters for template '{ShortName}':");
31+
foreach (var p in parameters)
32+
{
33+
Console.Write($"--{p.Name}");
34+
Console.Write($" ({p.DataType})");
35+
if (!string.IsNullOrEmpty(p.DefaultValue?.ToString()))
36+
Console.Write($" [default: {p.DefaultValue}]");
37+
// Check if parameter is required by string value
38+
if (p.Precedence != null && p.Precedence.ToString() == "Required")
39+
Console.Write(" <required>");
40+
if (p.Choices != null && p.Choices.Count > 0)
41+
{
42+
var list = string.Join(", ", p.Choices.Keys);
43+
Console.Write($" choices: {list}");
44+
}
45+
Console.WriteLine();
46+
if (!string.IsNullOrEmpty(p.Description))
47+
Console.WriteLine($" {p.Description}");
48+
}
49+
}
50+
catch (Exception ex)
51+
{
52+
Console.Error.WriteLine($"Error listing parameters: {ex.Message}");
53+
}
54+
return 0;
55+
}
56+
}

0 commit comments

Comments
 (0)