1- using ConsoleAppFramework ;
1+
2+ using ConsoleAppFramework ;
23using Microsoft . EntityFrameworkCore ;
34using Microsoft . Extensions . DependencyInjection ;
45using Microsoft . Extensions . Logging ;
78using ZLogger ;
89
910
10- // ConsoleApp.Run(args, (string name) => Console.WriteLine($"Hello {name}"));
11+ ConsoleApp . Run ( args , ( string name ) => Console . WriteLine ( $ "Hello { name } ") ) ;
1112
1213//args = new[] { "--message", "tako" };
1314
7677
7778// ----
7879
79- [ Command ( "db" ) ]
80- public class DatabaseApp : ConsoleAppBase , IAsyncDisposable
81- {
82- readonly ILogger < DatabaseApp > logger ;
83- readonly MyDbContext dbContext ;
84- readonly IOptions < MyConfig > config ;
85-
86- // you can get DI parameters.
87- public DatabaseApp ( ILogger < DatabaseApp > logger , IOptions < MyConfig > config , MyDbContext dbContext )
88- {
89- this . logger = logger ;
90- this . dbContext = dbContext ;
91- this . config = config ;
92- }
93-
94- [ Command ( "select" ) ]
95- public async Task QueryAsync ( int id )
96- {
97- // select * from...
98- }
99-
100- // also allow defaultValue.
101- [ Command ( "insert" ) ]
102- public async Task InsertAsync ( string value , int id = 0 )
103- {
104- // insert into...
105- }
106-
107- // support cleanup(IDisposable/IAsyncDisposable)
108- public async ValueTask DisposeAsync ( )
109- {
110- await dbContext . DisposeAsync ( ) ;
111- }
112- }
113-
114- public class MyConfig
115- {
116- public string FooValue { get ; set ; } = default ! ;
117- public string BarValue { get ; set ; } = default ! ;
118- }
119-
120-
121- // System.CommandLine
122- // Create a root command with some options
123- //using System.CommandLine;
124-
125- //var rootCommand = new RootCommand
80+ //[Command("db")]
81+ //public class DatabaseApp : ConsoleAppBase, IAsyncDisposable
12682//{
127- // new Option<int>(
128- // "--int-option",
129- // getDefaultValue: () => 42,
130- // description: "An option whose argument is parsed as an int"),
131- // new Option<bool>(
132- // "--bool-option",
133- // "An option whose argument is parsed as a bool"),
134- // new Option<FileInfo>(
135- // "--file-option",
136- // "An option whose argument is parsed as a FileInfo")
137- //};
138-
139- //rootCommand.Description = "My sample app";
140-
141- //rootCommand.SetHandler<int, bool, FileInfo>((intOption, boolOption, fileOption) =>
142- //{
143- // Console.WriteLine($"The value for --int-option is: {intOption}");
144- // Console.WriteLine($"The value for --bool-option is: {boolOption}");
145- // Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}");
146- //});
83+ // readonly ILogger<DatabaseApp> logger;
84+ // readonly MyDbContext dbContext;
85+ // readonly IOptions<MyConfig> config;
14786
148- //await rootCommand.InvokeAsync(args);
87+ // // you can get DI parameters.
88+ // public DatabaseApp(ILogger<DatabaseApp> logger, IOptions<MyConfig> config, MyDbContext dbContext)
89+ // {
90+ // this.logger = logger;
91+ // this.dbContext = dbContext;
92+ // this.config = config;
93+ // }
14994
95+ // [Command("select")]
96+ // public async Task QueryAsync(int id)
97+ // {
98+ // // select * from...
99+ // }
150100
101+ // // also allow defaultValue.
102+ // [Command("insert")]
103+ // public async Task InsertAsync(string value, int id = 0)
104+ // {
105+ // // insert into...
106+ // }
151107
152- //args = new[] { "check-timeout" };
108+ // // support cleanup(IDisposable/IAsyncDisposable)
109+ // public async ValueTask DisposeAsync()
110+ // {
111+ // await dbContext.DisposeAsync();
112+ // }
113+ //}
153114
154- //var builder = ConsoleApp.CreateBuilder(args);
155- //builder.ConfigureHostOptions(options =>
115+ //public class MyConfig
156116//{
157- // global::System.Console.WriteLine(options.ShutdownTimeout) ;
158- // options.ShutdownTimeout = TimeSpan.FromSeconds(10) ;
159- //});
117+ // public string FooValue { get; set; } = default! ;
118+ // public string BarValue { get; set; } = default! ;
119+ //}
160120
161121
162- //var app = builder.Build();
122+ //// System.CommandLine
123+ //// Create a root command with some options
124+ ////using System.CommandLine;
163125
126+ ////var rootCommand = new RootCommand
127+ ////{
128+ //// new Option<int>(
129+ //// "--int-option",
130+ //// getDefaultValue: () => 42,
131+ //// description: "An option whose argument is parsed as an int"),
132+ //// new Option<bool>(
133+ //// "--bool-option",
134+ //// "An option whose argument is parsed as a bool"),
135+ //// new Option<FileInfo>(
136+ //// "--file-option",
137+ //// "An option whose argument is parsed as a FileInfo")
138+ ////};
139+
140+ ////rootCommand.Description = "My sample app";
141+
142+ ////rootCommand.SetHandler<int, bool, FileInfo>((intOption, boolOption, fileOption) =>
143+ ////{
144+ //// Console.WriteLine($"The value for --int-option is: {intOption}");
145+ //// Console.WriteLine($"The value for --bool-option is: {boolOption}");
146+ //// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}");
147+ ////});
164148
165- //app.AddCommands<DisposeMan>( );
149+ ////await rootCommand.InvokeAsync(args );
166150
167- //app.Run();
168151
169- // System.CommandLine v2, requires many boilerplate code.
170- //using System.CommandLine;
171152
172- //var option = new Option<string>("name");
173- //var rootCommand = new RootCommand
174- //{
175- // option
176- //};
153+ ////args = new[] { "check-timeout" };
177154
178- //rootCommand.SetHandler((string name) =>
179- //{
180- // Console.WriteLine($"Hello {name}");
181- //}, option);
155+ ////var builder = ConsoleApp.CreateBuilder(args);
156+ ////builder.ConfigureHostOptions(options =>
157+ ////{
158+ //// global::System.Console.WriteLine(options.ShutdownTimeout);
159+ //// options.ShutdownTimeout = TimeSpan.FromSeconds(10);
160+ ////});
182161
183- //rootCommand.Invoke(args);
184162
163+ ////var app = builder.Build();
185164
186165
166+ ////app.AddCommands<DisposeMan>();
187167
188- //return ;
168+ ////app.Run() ;
189169
190- public class DisposeMan : ConsoleAppBase , IDisposable
191- {
192- public void Tako ( )
193- {
194- Console . WriteLine ( "Tako" ) ;
195- }
170+ //// System.CommandLine v2, requires many boilerplate code.
171+ ////using System.CommandLine;
196172
197- public async Task CheckTimeout ( )
198- {
199- await Task . Delay ( TimeSpan . FromSeconds ( 30 ) ) ;
200- }
173+ ////var option = new Option<string>("name");
174+ ////var rootCommand = new RootCommand
175+ ////{
176+ //// option
177+ ////};
201178
202- public void Dispose ( )
203- {
204- Console . WriteLine ( "foo!" ) ;
205- }
206- }
179+ ////rootCommand.SetHandler((string name) =>
180+ ////{
181+ //// Console.WriteLine($"Hello {name}");
182+ ////}, option);
207183
184+ ////rootCommand.Invoke(args);
208185
209- //rootCommand.Handler = CommandHandler.Create<int, bool, FileInfo>((intOption, boolOption, fileOption) =>
210- //{
211- // Console.WriteLine($"The value for --int-option is: {intOption}");
212- // Console.WriteLine($"The value for --bool-option is: {boolOption}");
213- // Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}");
214- //});
215186
216- //// Parse the incoming args and invoke the handler
217- //return rootCommand.InvokeAsync(args).Result;
218187
219188
189+ ////return;
220190
221- //using ConsoleAppFramework;
222- //using Microsoft.Extensions.Hosting;
223- //using Microsoft.Extensions.Logging;
191+ //public class DisposeMan : ConsoleAppBase, IDisposable
192+ //{
193+ // public void Tako()
194+ // {
195+ // Console.WriteLine("Tako");
196+ // }
224197
225- //args = new[] { "iroiro-case", "tako", "--help" };
226- ////args = new[] { "console-foo", "hello-anonymous", "--help" };
227- ////args = new[] { "console-foo", "hello-anonymous", "--hyper-name", "takoyaki" };
198+ // public async Task CheckTimeout()
199+ // {
200+ // await Task.Delay(TimeSpan.FromSeconds(30));
201+ // }
202+
203+ // public void Dispose()
204+ // {
205+ // Console.WriteLine("foo!");
206+ // }
207+ //}
228208
229- //var app = ConsoleApp.Create(args);
230209
231- ////app.AddCommand("foo", (ConsoleAppContext context, [Option(0)] int x, ILogger<string> oreLogger, [Option(1)] int y ) =>
210+ ////rootCommand.Handler = CommandHandler.Create<int, bool, FileInfo>((intOption, boolOption, fileOption ) =>
232211////{
233- //// global::System.Console.WriteLine(context.Timestamp);
234- //// global::System.Console.WriteLine(x + ":" + y);
212+ //// Console.WriteLine($"The value for --int-option is: {intOption}");
213+ //// Console.WriteLine($"The value for --bool-option is: {boolOption}");
214+ //// Console.WriteLine($"The value for --file-option is: {fileOption?.FullName ?? "null"}");
235215////});
236- //app.AddRoutedCommands();
237- //app.AddDefaultCommand((string foo) => { });
238216
239- ////app.AddCommands<ConsoleFoo>();
217+ ////// Parse the incoming args and invoke the handler
218+ ////return rootCommand.InvokeAsync(args).Result;
240219
241- //app.Run();
242220
243- //static class Foo
244- //{
245- // public static void Barrier(int x, int y)
246- // {
247- // Console.WriteLine($"OK:{x + y}");
248- // }
249- //}
250221
251- //public class ConsoleFoo : ConsoleAppBase
252- //{
253- // // [DefaultCommand]
254- // public void HelloAnonymous(string hyperName)
255- // {
256- // Console.WriteLine("OK:" + hyperName);
257- // }
222+ ////using ConsoleAppFramework;
223+ ////using Microsoft.Extensions.Hosting;
224+ ////using Microsoft.Extensions.Logging;
258225
259- // public void Hello2([Option("n ", "name of send user.")] string name, [Option("r", "repeat count.")] int repeat = 3)
260- // {
261- // }
226+ ////args = new[] { "iroiro-case ", "tako", "--help" };
227+ //////args = new[] { "console-foo", "hello-anonymous", "--help" };
228+ //////args = new[] { "console-foo", "hello-anonymous", "--hyper-name", "takoyaki" };
262229
230+ ////var app = ConsoleApp.Create(args);
263231
264- //}
232+ //////app.AddCommand("foo", (ConsoleAppContext context, [Option(0)] int x, ILogger<string> oreLogger, [Option(1)] int y) =>
233+ //////{
234+ ////// global::System.Console.WriteLine(context.Timestamp);
235+ ////// global::System.Console.WriteLine(x + ":" + y);
236+ //////});
237+ ////app.AddRoutedCommands();
238+ ////app.AddDefaultCommand((string foo) => { });
265239
266- //public class IroiroCase : ConsoleAppBase
267- //{
268- // [Command(new[] { "tako", "Yaki", "nanobee", "hatchi" })]
269- // 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)
270- // {
271- // }
240+ //////app.AddCommands<ConsoleFoo>();
272241
242+ ////app.Run();
273243
274- // public void Hot()
275- // {
276- // }
277- //}
244+ ////static class Foo
245+ ////{
246+ //// public static void Barrier(int x, int y)
247+ //// {
248+ //// Console.WriteLine($"OK:{x + y}");
249+ //// }
250+ ////}
251+
252+ ////public class ConsoleFoo : ConsoleAppBase
253+ ////{
254+ //// // [DefaultCommand]
255+ //// public void HelloAnonymous(string hyperName)
256+ //// {
257+ //// Console.WriteLine("OK:" + hyperName);
258+ //// }
259+
260+ //// public void Hello2([Option("n", "name of send user.")] string name, [Option("r", "repeat count.")] int repeat = 3)
261+ //// {
262+ //// }
263+
264+
265+ ////}
266+
267+ ////public class IroiroCase : ConsoleAppBase
268+ ////{
269+ //// [Command(new[] { "tako", "Yaki", "nanobee", "hatchi" })]
270+ //// 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)
271+ //// {
272+ //// }
273+
274+
275+ //// public void Hot()
276+ //// {
277+ //// }
278+ ////}
0 commit comments