static void Main(string[] args) { ILoggerFactory loggerFactory = new LoggerFactory() .AddConsole() .AddDebug(); var logger = loggerFactory.CreateLogger <Program>(); var app = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(); app.Name = "dotnet UpdateVersionConsole.dll"; var csprojoption = app.Option("--CSProjPath", "Full path of the CS Project File", Microsoft.Extensions.CommandLineUtils.CommandOptionType.SingleValue); var buildnumber = app.Option("--BuildNumber", "Build number which needs to appended to project version", Microsoft.Extensions.CommandLineUtils.CommandOptionType.SingleValue); //give people help with --help app.HelpOption("-? | -h | --help"); app.OnExecute(() => { string csprojFilePath = ""; int intBuildNumber = 0; if (!csprojoption.HasValue()) { logger.LogError("Please specific the CSProj file path. Use --help for more info"); return(1); } else { csprojFilePath = csprojoption.Value(); var ext = Path.GetExtension(csprojFilePath); if (ext != ".csproj") { logger.LogError("Please specific file with .csproj extension. Use --help for more info"); return(11); } if (!File.Exists(csprojFilePath)) { logger.LogError("CSProj file doesn't exist. Please specify valid file. Use --help for more info"); return(12); } } if (!buildnumber.HasValue()) { logger.LogError("Please give build number which needs to be appended. Use --help for more info"); return(2); } else { if (!int.TryParse(buildnumber.Value(), out intBuildNumber)) { logger.LogError("Please give build number as whole number. Use --help for more info"); return(21); } } UpdateCSProjVersion.UpdateBuildNumber(csprojFilePath, intBuildNumber.ToString()); return(0); }); app.Execute(args); }
static int Main(string[] args) { if (System.Console.BufferWidth == System.Console.WindowWidth) { System.Console.SetBufferSize(System.Console.BufferWidth * 2, System.Console.BufferHeight); } // download everything local to the site var commandLineApplication = new Microsoft.Extensions.CommandLineUtils.CommandLineApplication(); var siteArgument = commandLineApplication.Argument("site", "The site to scrape"); var folderArgument = commandLineApplication.Argument("folder", "The folder to scrape to"); var updateOption = commandLineApplication.Option("-u|--update", "Whether to update or ignore existing files", Microsoft.Extensions.CommandLineUtils.CommandOptionType.NoValue); commandLineApplication.HelpOption("-h|--help"); commandLineApplication.OnExecute(() => { var site = siteArgument.Value; var local = folderArgument.Value; update = updateOption.HasValue(); Task task; using (var client = new System.Net.Http.HttpClient(new System.Net.Http.HttpClientHandler { AllowAutoRedirect = false, AutomaticDecompression = System.Net.DecompressionMethods.None })) { var cancellationTokenSource = new System.Threading.CancellationTokenSource(); var baseUri = new Uri(site); var basePath = GetFileName(local, baseUri); if (!update && System.IO.File.Exists(basePath)) { // just use the current var links = GetLinks(System.IO.File.ReadAllText(basePath), baseUri); task = ProcessUris(client, local, update ? links : links.OrderBy(_ => System.IO.File.Exists(GetFileName(local, _)), new ExistsComparer()), cancellationTokenSource.Token); } else { task = Process(client, local, baseUri, cancellationTokenSource.Token); } while (!(task.IsFaulted || task.IsCompleted || task.IsCanceled)) { System.Threading.Thread.Sleep(100); if (Console.KeyAvailable) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.Escape: cancellationTokenSource.Cancel(); break; case ConsoleKey.UpArrow: Delay++; break; case ConsoleKey.DownArrow: if (Delay > 0) { Delay--; } break; } } } if (task != null && task.IsFaulted) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("{0}ERROR! - {1}", currentIndent, task.Exception.ToString()); Console.ForegroundColor = DefaultConsoleColor; return(task.Exception.HResult); } } return(0); }); return(commandLineApplication.Execute(args)); }