AutoSpectre.SourceGeneration
                             
                            
                                0.11.0-preview-01
                            
                        
                    
        
        
                                This is a prerelease version of AutoSpectre.SourceGeneration.
                            
    
    
        
        
                                There is a newer version of this package available.
                                
See the version list below for details.
                    See the version list below for details.
dotnet add package AutoSpectre.SourceGeneration --version 0.11.0-preview-01
NuGet\Install-Package AutoSpectre.SourceGeneration -Version 0.11.0-preview-01
        
        
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
                    
    
    <PackageReference Include="AutoSpectre.SourceGeneration" Version="0.11.0-preview-01" />
        
        
For projects that support PackageReference, copy this XML node into the project file to reference the package.
                    
    
    <PackageVersion Include="AutoSpectre.SourceGeneration" Version="0.11.0-preview-01" />
<PackageReference Include="AutoSpectre.SourceGeneration" />
        
        
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
                    
    
    paket add AutoSpectre.SourceGeneration --version 0.11.0-preview-01
        
        
 The NuGet Team does not provide support for this client. Please contact its maintainers for support.
                    
    
    #r "nuget: AutoSpectre.SourceGeneration, 0.11.0-preview-01"
        
        
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
                    
    
    #:package AutoSpectre.SourceGeneration@0.11.0-preview-01
        
        
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
                    
    
    #addin nuget:?package=AutoSpectre.SourceGeneration&version=0.11.0-preview-01&prerelease
#tool nuget:?package=AutoSpectre.SourceGeneration&version=0.11.0-preview-01&prerelease
        
        
 The NuGet Team does not provide support for this client. Please contact its maintainers for support.
                    
    
    AutoSpectre Source Generation
This allows you to decorate a class with the AutoSpectreForm attribute and decorate properties on that class with:
- TextPromptAttribute
- SelectPromptAttribute
and void or Task methods with
- TaskStepAttribute
and behind the scenes a Form (SpectreFactory) will be generated to request input using Spectre.Console
Example
Code
[AutoSpectreForm]
public class Example
{
    [TextPrompt(Title = "Add item")] public int[] IntItems { get; set; } = Array.Empty<int>();
    [TextPrompt(Title = "Enter first name", DefaultValueStyle = "bold")]
    public string? FirstName { get; set; } = "John Doe"; // Default value in prompt
    [TextPrompt(PromptStyle = "green bold")] 
    public bool LeftHanded { get; set; }
    [TextPrompt(Title = "Choose your [red]value[/]" )]
    public SomeEnum Other { get; set; }
    
    [TextPrompt(Secret = true, Mask = '*')]
    public string? Password { get; set; }
    [TextPrompt] public OtherAutoSpectreFormClass ChildForm { get; set; } = new();
    [TextPrompt]
    public IReadOnlyList<OtherAutoSpectreFormClass> Investors { get; set; } = new List<OtherAutoSpectreFormClass>();
    [TaskStep(UseStatus = true, StatusText = "This will take a while", SpinnerType = SpinnerKnownTypes.Christmas, SpinnerStyle = "green on yellow")]
    public void DoSomething(IAnsiConsole console)
    {
        console.Write(new FigletText("A figlet text is needed"));
    }
    [SelectPrompt(WrapAround = true, PageSize = 3,
        MoreChoicesText = "Press down to see more choices", HighlightStyle = "purple")]
    //[SelectPrompt(Source = nameof(ItemSource))]
    public string Item { get; set; } = string.Empty;
    public List<string> ItemSource { get; } = new() { "Alpha", "Bravo", "Charlie" };
    [SelectPrompt(InstructionsText = "Check the special items you want to select")]
    //[SelectPrompt(Converter = nameof(SpecialProjectionConverter))]
    public List<int> SpecialProjection { get; set; } = new();
    public string SpecialProjectionConverter(int source) => $"Number {source}";
    public List<int> SpecialProjectionSource { get; set; } = new() { 1, 2, 3, 4 };
    [TextPrompt]
    // [TextPrompt(Validator = nameof(EnterYearValidator))]
    public int EnterYear { get; set; }
    public string? EnterYearValidator(int year)
    {
        return year <= DateTime.Now.Year ? null : "Year cannot be larger than current year";
    }
    [TextPrompt] public HashSet<string> Names { get; set; } = new(StringComparer.OrdinalIgnoreCase);
    public string? NamesValidator(List<string> items, string newItem)
    {
        if (newItem == "Foobar")
            return "Cannot be Foobar";
        if (items.Contains(newItem))
            return $"{newItem} has already been added";
        return null;
    }
    [TextPrompt] public bool AddExistingName { get; set; }
    [TextPrompt(Condition = nameof(AddExistingName))]
    public string? ExistingName { get; set; }
    [TextPrompt(Condition = nameof(AddExistingName), NegateCondition = true)]
    public string? NewName { get; set; }
}
Output
/// <summary>
/// Helps create and fill <see cref = "Example"/> with values
/// </summary>
public interface IExampleSpectreFactory
{
    Example Get(Example destination = null);
}
/// <summary>
/// Helps create and fill <see cref = "Example"/> with values
/// </summary>
public class ExampleSpectreFactory : IExampleSpectreFactory
{
    public Example Get(Example destination = null)
    {
        IOtherAutoSpectreFormClassSpectreFactory OtherAutoSpectreFormClassSpectreFactory = new OtherAutoSpectreFormClassSpectreFactory();
        destination ??= new ConsoleApp1.Example();
        // Prompt for values for destination.IntItems
        {
            List<int> items = new List<int>();
            bool continuePrompting = true;
            do
            {
                var item = AnsiConsole.Prompt(new TextPrompt<int>("Add item"));
                items.Add(item);
                continuePrompting = AnsiConsole.Confirm("Add more items?");
            }
            while (continuePrompting);
            int[] result = items.ToArray();
            destination.IntItems = result;
        }
        destination.FirstName = AnsiConsole.Prompt(new TextPrompt<string?>("Enter first name").AllowEmpty().DefaultValue("John Doe").DefaultValueStyle("bold"));
        destination.LeftHanded = AnsiConsole.Confirm("Enter [green]LeftHanded[/]");
        destination.Other = AnsiConsole.Prompt(new SelectionPrompt<SomeEnum>().Title("Choose your [red]value[/]").PageSize(10).AddChoices(Enum.GetValues<SomeEnum>()));
        destination.Password = AnsiConsole.Prompt(new TextPrompt<string?>("Enter [green]Password[/]").AllowEmpty().Secret('*'));
        {
            AnsiConsole.MarkupLine("Enter [green]ChildForm[/]");
            var item = OtherAutoSpectreFormClassSpectreFactory.Get();
            destination.ChildForm = item;
        }
        // Prompt for values for destination.Investors
        {
            List<OtherAutoSpectreFormClass> items = new List<OtherAutoSpectreFormClass>();
            bool continuePrompting = true;
            do
            {
                {
                    AnsiConsole.MarkupLine("Enter [green]Investors[/]");
                    var newItem = OtherAutoSpectreFormClassSpectreFactory.Get();
                    items.Add(newItem);
                }
                continuePrompting = AnsiConsole.Confirm("Add more items?");
            }
            while (continuePrompting);
            System.Collections.Generic.IReadOnlyList<ConsoleApp1.OtherAutoSpectreFormClass> result = items;
            destination.Investors = result;
        }
        AnsiConsole.MarkupLine("Calling method [green]DoSomething[/]");
        AnsiConsole.Status().SpinnerStyle("green on yellow").Spinner(Spinner.Known.Christmas).Start("This will take a while", ctx =>
        {
            destination.DoSomething(AnsiConsole.Console);
        });
        destination.Item = AnsiConsole.Prompt(new SelectionPrompt<string>().Title("Enter [green]Item[/]").PageSize(3).WrapAround(true).MoreChoicesText("Press down to see more choices").HighlightStyle("purple").AddChoices(destination.ItemSource.ToArray()));
        destination.SpecialProjection = AnsiConsole.Prompt(new MultiSelectionPrompt<int>().Title("Enter [green]SpecialProjection[/]").UseConverter(destination.SpecialProjectionConverter).PageSize(10).InstructionsText("Check the special items you want to select").AddChoices(destination.SpecialProjectionSource.ToArray()));
        destination.EnterYear = AnsiConsole.Prompt(new TextPrompt<int>("Enter [green]EnterYear[/]").Validate(ctx =>
        {
            var result = destination.EnterYearValidator(ctx);
            return result == null ? ValidationResult.Success() : ValidationResult.Error(result);
        }));
        // Prompt for values for destination.Names
        {
            List<string> items = new List<string>();
            bool continuePrompting = true;
            do
            {
                bool valid = false;
                while (!valid)
                {
                    var item = AnsiConsole.Prompt(new TextPrompt<string>("Enter [green]Names[/]"));
                    var validationResult = destination.NamesValidator(items, item);
                    if (validationResult is { } error)
                    {
                        AnsiConsole.MarkupLine($"[red]{error}[/]");
                        valid = false;
                    }
                    else
                    {
                        valid = true;
                        items.Add(item);
                    }
                }
                continuePrompting = AnsiConsole.Confirm("Add more items?");
            }
            while (continuePrompting);
            System.Collections.Generic.HashSet<string> result = new System.Collections.Generic.HashSet<string>(items);
            destination.Names = result;
        }
        destination.AddExistingName = AnsiConsole.Confirm("Enter [green]AddExistingName[/]");
        if (destination.AddExistingName == true)
        {
            destination.ExistingName = AnsiConsole.Prompt(new TextPrompt<string?>("Enter [green]ExistingName[/]").AllowEmpty());
        }
        if (destination.AddExistingName == false)
        {
            destination.NewName = AnsiConsole.Prompt(new TextPrompt<string?>("Enter [green]NewName[/]").AllowEmpty());
        }
        return destination;
    }
}
Credits
                            There are no supported framework assets in this package.
                            
                    Learn more about Target Frameworks and .NET Standard.
- 
                                                    .NETStandard 2.0- AutoSpectre (>= 0.11.0-preview01)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.9.2)
- Spectre.Console (>= 0.49.1)
 
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | 
|---|---|---|
| 0.11.0 | 222 | 5/21/2025 | 
| 0.11.0-preview-01 | 187 | 5/21/2025 | 
| 0.10.0 | 249 | 4/7/2025 | 
| 0.10.0-preview-01.1 | 156 | 4/6/2025 | 
| 0.9.1 | 222 | 4/3/2025 | 
| 0.9.1-preview-03 | 203 | 4/3/2025 | 
| 0.9.1-preview-02 | 183 | 4/3/2025 | 
| 0.9.1-preview-01 | 210 | 4/2/2025 | 
| 0.9.0 | 229 | 7/2/2024 | 
| 0.9.0-preview-0.6 | 85 | 7/1/2024 | 
| 0.8.2 | 207 | 6/25/2024 | 
| 0.8.2-preview-01 | 148 | 6/23/2024 | 
| 0.8.1 | 235 | 2/5/2024 | 
| 0.8.0 | 290 | 11/30/2023 | 
| 0.8.0-preview.0.1 | 132 | 11/4/2023 | 
| 0.7.0 | 378 | 10/3/2023 | 
| 0.7.0-preview.0.8 | 125 | 10/2/2023 | 
| 0.7.0-preview.0.7 | 108 | 10/2/2023 | 
| 0.7.0-preview.0.6 | 118 | 10/1/2023 | 
| 0.7.0-preview.0.5 | 134 | 9/26/2023 | 
| 0.7.0-preview.0.4.2 | 126 | 9/20/2023 | 
| 0.7.0-preview.0.3 | 90 | 9/18/2023 | 
| 0.7.0-preview.0.2 | 115 | 9/15/2023 | 
| 0.7.0-preview.0.1 | 149 | 9/14/2023 | 
| 0.6.0 | 387 | 9/12/2023 | 
| 0.6.0-preview.0.4 | 153 | 9/10/2023 | 
| 0.6.0-preview.0.1 | 146 | 9/3/2023 | 
| 0.5.3 | 384 | 8/28/2023 | 
| 0.5.2 | 390 | 8/27/2023 | 
| 0.5.1 | 389 | 8/25/2023 | 
| 0.5.0 | 419 | 8/23/2023 | 
| 0.4.0 | 439 | 8/15/2023 | 
| 0.3.8 | 427 | 8/6/2023 | 
| 0.3.7.2 | 312 | 7/29/2023 | 
| 0.3.6.1 | 307 | 7/25/2023 | 
| 0.3.5 | 253 | 7/24/2023 | 
| 0.3.4 | 295 | 7/23/2023 | 
| 0.3.3 | 247 | 7/23/2023 | 
| 0.3.2 | 470 | 1/22/2023 | 
| 0.3.1 | 447 | 1/16/2023 | 
| 0.3.0 | 476 | 1/6/2023 | 
| 0.2.0.2 | 474 | 12/14/2022 | 
| 0.2.0.1 | 417 | 12/14/2022 | 
| 0.1.6 | 486 | 12/2/2022 | 
| 0.1.5 | 478 | 11/30/2022 | 
Rewrite of prompt class. Introduced general interface