|
| 1 | +using CodeQLToolkit.Features.Pack.Commands.Targets; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.CommandLine; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | + |
| 9 | +namespace CodeQLToolkit.Features.Pack.Commands |
| 10 | +{ |
| 11 | + public class PackCommandFeature : FeatureBase, IToolkitCommandFeature |
| 12 | + { |
| 13 | + public void Register(Command parentCommand) |
| 14 | + { |
| 15 | + Log<PackCommandFeature>.G().LogInformation("Registering command submodule."); |
| 16 | + |
| 17 | + var runCommand = new Command("run", "Functions pertaining to running pack-related commands."); |
| 18 | + parentCommand.Add(runCommand); |
| 19 | + |
| 20 | + // a command that installs query packs |
| 21 | + var sayHello = new Command("hello-jeongsoo", "Says hello!"); |
| 22 | + var howManyTimesHello = new Option<int>("--times", "how many times to say it") { IsRequired = true }; |
| 23 | + sayHello.Add(howManyTimesHello); |
| 24 | + |
| 25 | + var sayGoodbye = new Command("goodbye-jeongsoo", "Says goodbye!"); |
| 26 | + |
| 27 | + var howManyTimes = new Option<int>("--times", "how many times to say it") { IsRequired = true }; |
| 28 | + sayGoodbye.Add(howManyTimes); |
| 29 | + |
| 30 | + |
| 31 | + runCommand.Add(sayHello); |
| 32 | + runCommand.Add(sayGoodbye); |
| 33 | + |
| 34 | + sayHello.SetHandler((basePath, times) => { |
| 35 | + |
| 36 | + new HelloJeongsooCommandTarget() { |
| 37 | + Base = basePath, |
| 38 | + Times = times |
| 39 | + |
| 40 | + }.Run(); |
| 41 | + |
| 42 | + }, Globals.BasePathOption, howManyTimesHello); |
| 43 | + |
| 44 | + sayGoodbye.SetHandler((basePath, times) => { |
| 45 | + |
| 46 | + Console.WriteLine($"Saying goodbye {times} number of times"); |
| 47 | + |
| 48 | + for (int i = 0; i < times; i++) |
| 49 | + { |
| 50 | + Console.WriteLine("Goodbye!"); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + }, Globals.BasePathOption, howManyTimes); |
| 55 | + |
| 56 | + } |
| 57 | + |
| 58 | + public int Run() |
| 59 | + { |
| 60 | + throw new NotImplementedException(); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments