static async Task <int> Main(string[] args) { var rootApp = new CommandLineApplication() { Name = "screenshot1" }; rootApp.Command("screenshot", app => { var urlArgs = app.Argument("urlArgument", "the url"); var formatOpt = app.Option("--format", "option for the output format", CommandOptionType.SingleOrNoValue); var nameOpt = app.Option("--output", "define the output file name", CommandOptionType.SingleOrNoValue); object format = null; app.OnExecuteAsync(async cancellationToken => { Console.WriteLine("executing..."); if (formatOpt.HasValue()) { format = SS.detectFormatByOpt(formatOpt); } else if (nameOpt.HasValue()) { format = SS.detectFormatByName(nameOpt); } else { format = SS.getDefaultFormat(); } Console.WriteLine("format : {0}", format); string name = SS.GetName(nameOpt); await SS.TakeSS(urlArgs.Value, format, name); }); }); return(rootApp.Execute(args)); }
static async Task <int> Main(string[] args) { var rootApp = new CommandLineApplication() { Name = "screenshot2" }; rootApp.Command("screenshot-list", app => { var filePath = app.Argument("urlArgument", "the url"); var formatOpt = app.Option("--format", "option for the output format", CommandOptionType.SingleOrNoValue); object format = null; app.OnExecuteAsync(async cancellationToken => { List <string> links = new List <string>(File.ReadAllLines(filePath.Value)); Console.WriteLine("executing..."); if (formatOpt.HasValue()) { format = SS.detectFormatByOpt(formatOpt); } else { format = SS.getDefaultFormat(); } Console.WriteLine("format : {0}", format); foreach (var l in links) { string name = SS.GetName(l); Console.WriteLine(name); await SS.TakeSS(l, format, name); } }); }); return(rootApp.Execute(args)); }