|
| 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