diff --git a/sandbox/Net6Console/Program.cs b/sandbox/Net6Console/Program.cs index 6a7109d..56a718c 100644 --- a/sandbox/Net6Console/Program.cs +++ b/sandbox/Net6Console/Program.cs @@ -1,4 +1,5 @@ -using ConsoleAppFramework; + +using ConsoleAppFramework; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -7,7 +8,7 @@ using ZLogger; -//ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}")); +ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}")); //args = new[] { "--message", "tako" }; @@ -76,202 +77,202 @@ // ---- -[Command("db")] -public class DatabaseApp : ConsoleAppBase, IAsyncDisposable -{ - readonly ILogger logger; - readonly MyDbContext dbContext; - readonly IOptions config; - - // you can get DI parameters. - public DatabaseApp(ILogger logger, IOptions config, MyDbContext dbContext) - { - this.logger = logger; - this.dbContext = dbContext; - this.config = config; - } - - [Command("select")] - public async Task QueryAsync(int id) - { - // select * from... - } - - // also allow defaultValue. - [Command("insert")] - public async Task InsertAsync(string value, int id = 0) - { - // insert into... - } - - // support cleanup(IDisposable/IAsyncDisposable) - public async ValueTask DisposeAsync() - { - await dbContext.DisposeAsync(); - } -} - -public class MyConfig -{ - public string FooValue { get; set; } = default!; - public string BarValue { get; set; } = default!; -} - - -// System.CommandLine -// Create a root command with some options -//using System.CommandLine; - -//var rootCommand = new RootCommand +//[Command("db")] +//public class DatabaseApp : ConsoleAppBase, IAsyncDisposable //{ -// new Option( -// "--int-option", -// getDefaultValue: () => 42, -// description: "An option whose argument is parsed as an int"), -// new Option( -// "--bool-option", -// "An option whose argument is parsed as a bool"), -// new Option( -// "--file-option", -// "An option whose argument is parsed as a FileInfo") -//}; - -//rootCommand.Description = "My sample app"; - -//rootCommand.SetHandler((intOption, boolOption, fileOption) => -//{ -// Console.WriteLine($"The value for --int-option is: {intOption}"); -// Console.WriteLine($"The value for --bool-option is: {boolOption}"); -// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}"); -//}); +// readonly ILogger logger; +// readonly MyDbContext dbContext; +// readonly IOptions config; -//await rootCommand.InvokeAsync(args); +// // you can get DI parameters. +// public DatabaseApp(ILogger logger, IOptions config, MyDbContext dbContext) +// { +// this.logger = logger; +// this.dbContext = dbContext; +// this.config = config; +// } +// [Command("select")] +// public async Task QueryAsync(int id) +// { +// // select * from... +// } +// // also allow defaultValue. +// [Command("insert")] +// public async Task InsertAsync(string value, int id = 0) +// { +// // insert into... +// } -//args = new[] { "check-timeout" }; +// // support cleanup(IDisposable/IAsyncDisposable) +// public async ValueTask DisposeAsync() +// { +// await dbContext.DisposeAsync(); +// } +//} -//var builder = ConsoleApp.CreateBuilder(args); -//builder.ConfigureHostOptions(options => +//public class MyConfig //{ -// global::System.Console.WriteLine(options.ShutdownTimeout); -// options.ShutdownTimeout = TimeSpan.FromSeconds(10); -//}); +// public string FooValue { get; set; } = default!; +// public string BarValue { get; set; } = default!; +//} -//var app = builder.Build(); +//// System.CommandLine +//// Create a root command with some options +////using System.CommandLine; +////var rootCommand = new RootCommand +////{ +//// new Option( +//// "--int-option", +//// getDefaultValue: () => 42, +//// description: "An option whose argument is parsed as an int"), +//// new Option( +//// "--bool-option", +//// "An option whose argument is parsed as a bool"), +//// new Option( +//// "--file-option", +//// "An option whose argument is parsed as a FileInfo") +////}; + +////rootCommand.Description = "My sample app"; + +////rootCommand.SetHandler((intOption, boolOption, fileOption) => +////{ +//// Console.WriteLine($"The value for --int-option is: {intOption}"); +//// Console.WriteLine($"The value for --bool-option is: {boolOption}"); +//// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}"); +////}); -//app.AddCommands(); +////await rootCommand.InvokeAsync(args); -//app.Run(); -// System.CommandLine v2, requires many boilerplate code. -//using System.CommandLine; -//var option = new Option("name"); -//var rootCommand = new RootCommand -//{ -// option -//}; +////args = new[] { "check-timeout" }; -//rootCommand.SetHandler((string name) => -//{ -// Console.WriteLine($"Hello {name}"); -//}, option); +////var builder = ConsoleApp.CreateBuilder(args); +////builder.ConfigureHostOptions(options => +////{ +//// global::System.Console.WriteLine(options.ShutdownTimeout); +//// options.ShutdownTimeout = TimeSpan.FromSeconds(10); +////}); -//rootCommand.Invoke(args); +////var app = builder.Build(); +////app.AddCommands(); -//return; +////app.Run(); -public class DisposeMan : ConsoleAppBase, IDisposable -{ - public void Tako() - { - Console.WriteLine("Tako"); - } +//// System.CommandLine v2, requires many boilerplate code. +////using System.CommandLine; - public async Task CheckTimeout() - { - await Task.Delay(TimeSpan.FromSeconds(30)); - } +////var option = new Option("name"); +////var rootCommand = new RootCommand +////{ +//// option +////}; - public void Dispose() - { - Console.WriteLine("foo!"); - } -} +////rootCommand.SetHandler((string name) => +////{ +//// Console.WriteLine($"Hello {name}"); +////}, option); +////rootCommand.Invoke(args); -//rootCommand.Handler = CommandHandler.Create((intOption, boolOption, fileOption) => -//{ -// Console.WriteLine($"The value for --int-option is: {intOption}"); -// Console.WriteLine($"The value for --bool-option is: {boolOption}"); -// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}"); -//}); -//// Parse the incoming args and invoke the handler -//return rootCommand.InvokeAsync(args).Result; +////return; -//using ConsoleAppFramework; -//using Microsoft.Extensions.Hosting; -//using Microsoft.Extensions.Logging; +//public class DisposeMan : ConsoleAppBase, IDisposable +//{ +// public void Tako() +// { +// Console.WriteLine("Tako"); +// } -//args = new[] { "iroiro-case", "tako", "--help" }; -////args = new[] { "console-foo", "hello-anonymous", "--help" }; -////args = new[] { "console-foo", "hello-anonymous", "--hyper-name", "takoyaki" }; +// public async Task CheckTimeout() +// { +// await Task.Delay(TimeSpan.FromSeconds(30)); +// } + +// public void Dispose() +// { +// Console.WriteLine("foo!"); +// } +//} -//var app = ConsoleApp.Create(args); -////app.AddCommand("foo", (ConsoleAppContext context, [Option(0)] int x, ILogger oreLogger, [Option(1)] int y) => +////rootCommand.Handler = CommandHandler.Create((intOption, boolOption, fileOption) => ////{ -//// global::System.Console.WriteLine(context.Timestamp); -//// global::System.Console.WriteLine(x + ":" + y); +//// Console.WriteLine($"The value for --int-option is: {intOption}"); +//// Console.WriteLine($"The value for --bool-option is: {boolOption}"); +//// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}"); ////}); -//app.AddRoutedCommands(); -//app.AddDefaultCommand((string foo) => { }); -////app.AddCommands(); +////// Parse the incoming args and invoke the handler +////return rootCommand.InvokeAsync(args).Result; -//app.Run(); -//static class Foo -//{ -// public static void Barrier(int x, int y) -// { -// Console.WriteLine($"OK:{x + y}"); -// } -//} -//public class ConsoleFoo : ConsoleAppBase -//{ -// // [DefaultCommand] -// public void HelloAnonymous(string hyperName) -// { -// Console.WriteLine("OK:" + hyperName); -// } +////using ConsoleAppFramework; +////using Microsoft.Extensions.Hosting; +////using Microsoft.Extensions.Logging; -// public void Hello2([Option("n", "name of send user.")] string name, [Option("r", "repeat count.")] int repeat = 3) -// { -// } +////args = new[] { "iroiro-case", "tako", "--help" }; +//////args = new[] { "console-foo", "hello-anonymous", "--help" }; +//////args = new[] { "console-foo", "hello-anonymous", "--hyper-name", "takoyaki" }; +////var app = ConsoleApp.Create(args); -//} +//////app.AddCommand("foo", (ConsoleAppContext context, [Option(0)] int x, ILogger oreLogger, [Option(1)] int y) => +//////{ +////// global::System.Console.WriteLine(context.Timestamp); +////// global::System.Console.WriteLine(x + ":" + y); +//////}); +////app.AddRoutedCommands(); +////app.AddDefaultCommand((string foo) => { }); -//public class IroiroCase : ConsoleAppBase -//{ -// [Command(new[] { "tako", "Yaki", "nanobee", "hatchi" })] -// public void Tes(int I, int i, int ID, int XML, int Xml, int Id, int IdCheck, int IDCheck, int IdCheckZ, int IdCheckXML, int IdCheckXml) -// { -// } +//////app.AddCommands(); +////app.Run(); -// public void Hot() -// { -// } -//} \ No newline at end of file +////static class Foo +////{ +//// public static void Barrier(int x, int y) +//// { +//// Console.WriteLine($"OK:{x + y}"); +//// } +////} + +////public class ConsoleFoo : ConsoleAppBase +////{ +//// // [DefaultCommand] +//// public void HelloAnonymous(string hyperName) +//// { +//// Console.WriteLine("OK:" + hyperName); +//// } + +//// public void Hello2([Option("n", "name of send user.")] string name, [Option("r", "repeat count.")] int repeat = 3) +//// { +//// } + + +////} + +////public class IroiroCase : ConsoleAppBase +////{ +//// [Command(new[] { "tako", "Yaki", "nanobee", "hatchi" })] +//// public void Tes(int I, int i, int ID, int XML, int Xml, int Id, int IdCheck, int IDCheck, int IdCheckZ, int IdCheckXML, int IdCheckXml) +//// { +//// } + + +//// public void Hot() +//// { +//// } +////} \ No newline at end of file