Skip to content

Commit

Permalink
generate Config
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 15, 2024
1 parent 1996c08 commit 2a4c556
Show file tree
Hide file tree
Showing 9 changed files with 947 additions and 560 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ app.Add("foo baz", async (string foo = "test", CancellationToken cancellationTok
The Source Generator generates four fields and holds them with specific types.

```csharp
partial struct ConsoleAppBuilder
partial class ConsoleAppBuilder
{
Action command0 = default!;
Action<int, int> command1 = default!;
Expand Down
107 changes: 92 additions & 15 deletions sandbox/GeneratorSandbox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
using ConsoleAppFramework;
#nullable enable

using ConsoleAppFramework;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Reflection;
using ZLogger;

[assembly: ConsoleAppFrameworkGeneratorOptions(DisableNamingConversion = true)]


args = ["HelloWorld", "--help"];
var app = ConsoleApp.Create();
//app.Add<MyCommands>();
app.Add<Tacommands>();
app.Run(args);

var app = ConsoleApp.Create()
;

app.ConfigureDefaultConfiguration();

app.ConfigureServices(services =>
{

});

// .ConfigureLogging(
// .ConfigureDefaultConfiguration()
// ;

app.Add("", () => { });

app.Run(args);



Expand Down Expand Up @@ -71,22 +91,79 @@ internal static partial class ConsoleApp



//internal partial struct ConsoleAppBuilder
//internal partial class ConsoleAppBuilder
//{
// /// <summary>
// /// Add all [RegisterCommands] types as ConsoleApp command.
// /// </summary>
// public void RegisterAll()
// bool requireConfiguration;
// IConfiguration? configuration;
// Action<IConfiguration, IServiceCollection>? configureServices;
// Action<IConfiguration, ILoggingBuilder>? configureLogging;

// /// <summary>Create configuration with SetBasePath(Directory.GetCurrentDirectory()) and AddJsonFile("appsettings.json").</summary>
// public void ConfigureDefaultConfiguration(Action<IConfigurationBuilder> configure)
// {
// var config = new ConfigurationBuilder();
// config.SetBasePath(System.IO.Directory.GetCurrentDirectory());
// config.AddJsonFile("appsettings.json", optional: true);
// configure(config);
// configuration = config.Build();
// }

// /// <summary>
// /// Add all [RegisterCommands] types as ConsoleApp command.
// /// </summary>
// public void RegisterAll(string commandPath)
// public void ConfigureEmptyConfiguration(Action<IConfigurationBuilder> configure)
// {
// var config = new ConfigurationBuilder();
// configure(config);
// configuration = config.Build();
// }

// public void ConfigureServices(Action<IServiceCollection> configure)
// {
// this.configureServices = (_, services) => configure(services);
// }

// public void ConfigureServices(Action<IConfiguration, IServiceCollection> configure)
// {
// this.requireConfiguration = true;
// this.configureServices = configure;
// }

// public void ConfigureLogging(Action<ILoggingBuilder> configure)
// {
// this.configureLogging = (_, builder) => configure(builder);
// }

// public void ConfigureLogging(Action<IConfiguration, ILoggingBuilder> configure)
// {
// this.requireConfiguration = true;
// this.configureLogging = configure;
// }

// public void BuildAndSetServiceProvider()
// {
// if (configureServices == null && configureLogging == null) return;

// if (configureServices != null)
// {
// var services = new ServiceCollection();
// configureServices?.Invoke(configuration!, services);

// if (configureLogging != null)
// {
// var config = configuration;
// if (requireConfiguration && config == null)
// {
// config = new ConfigurationRoot(Array.Empty<IConfigurationProvider>());
// }

// var configure = configureLogging;
// services.AddLogging(logging =>
// {
// configure!(config!, logging);
// });
// }

// ConsoleApp.ServiceProvider = services.BuildServiceProvider();
// }
// }
//}
}

Expand Down
Loading

0 comments on commit 2a4c556

Please sign in to comment.